Add WebRTC sources for Amazon Kinesis and Wyze
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
@@ -100,3 +101,10 @@ a=recvonly
|
||||
err = sender.ReplaceTrack(track)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestUnmarshalICEServers(t *testing.T) {
|
||||
s := `[{"credential":"xxx","urls":"xxx","username":"xxx"},{"credential":null,"urls":"xxx","username":null}]`
|
||||
servers, err := UnmarshalICEServers([]byte(s))
|
||||
require.Nil(t, err)
|
||||
require.Len(t, servers, 2)
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/rtp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Conn struct {
|
||||
@@ -130,7 +131,7 @@ func NewConn(pc *webrtc.PeerConnection) *Conn {
|
||||
}
|
||||
|
||||
func (c *Conn) Close() error {
|
||||
c.closed.Done()
|
||||
c.closed.Done(nil)
|
||||
return c.pc.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
@@ -293,3 +294,35 @@ func CandidateManualHostTCPPassive(address string, port int) string {
|
||||
foundation, priority, address, port,
|
||||
)
|
||||
}
|
||||
|
||||
func UnmarshalICEServers(b []byte) ([]webrtc.ICEServer, error) {
|
||||
type ICEServer struct {
|
||||
URLs any `json:"urls"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Credential string `json:"credential,omitempty"`
|
||||
}
|
||||
|
||||
var src []ICEServer
|
||||
if err := json.Unmarshal(b, &src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var dst []webrtc.ICEServer
|
||||
for i := range src {
|
||||
srv := webrtc.ICEServer{
|
||||
Username: src[i].Username,
|
||||
Credential: src[i].Credential,
|
||||
}
|
||||
|
||||
switch v := src[i].URLs.(type) {
|
||||
case []string:
|
||||
srv.URLs = v
|
||||
case string:
|
||||
srv.URLs = []string{v}
|
||||
}
|
||||
|
||||
dst = append(dst, srv)
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user