Merge pull request #2064 from jmelancondev/webrtc/ice-server-urls-list
webrtc: Fix ice_servers parsing for a list of URLs
This commit is contained in:
@@ -107,4 +107,12 @@ func TestUnmarshalICEServers(t *testing.T) {
|
|||||||
servers, err := UnmarshalICEServers([]byte(s))
|
servers, err := UnmarshalICEServers([]byte(s))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Len(t, servers, 2)
|
require.Len(t, servers, 2)
|
||||||
|
require.Equal(t, []string{"xxx"}, servers[0].URLs)
|
||||||
|
|
||||||
|
s = `[{"urls":"xxx"},{"urls":["yyy","zzz"]}]`
|
||||||
|
servers, err = UnmarshalICEServers([]byte(s))
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Len(t, servers, 2)
|
||||||
|
require.Equal(t, []string{"xxx"}, servers[0].URLs)
|
||||||
|
require.Equal(t, []string{"yyy", "zzz"}, servers[1].URLs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -331,8 +331,12 @@ func UnmarshalICEServers(b []byte) ([]webrtc.ICEServer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch v := src[i].URLs.(type) {
|
switch v := src[i].URLs.(type) {
|
||||||
case []string:
|
case []any:
|
||||||
srv.URLs = v
|
for _, u := range v {
|
||||||
|
if s, ok := u.(string); ok {
|
||||||
|
srv.URLs = append(srv.URLs, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
case string:
|
case string:
|
||||||
srv.URLs = []string{v}
|
srv.URLs = []string{v}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user