diff --git a/capabilities.go b/capabilities.go index e4386a45..491bd7a7 100644 --- a/capabilities.go +++ b/capabilities.go @@ -78,8 +78,8 @@ type CapabilitiesVersion struct { } type CapabilitiesResponse struct { - Version CapabilitiesVersion `json:"version"` - Capabilities map[string]map[string]interface{} `json:"capabilities"` + Version CapabilitiesVersion `json:"version"` + Capabilities map[string]*json.RawMessage `json:"capabilities"` } func (c *Capabilities) getCapabilities(key string) (map[string]interface{}, bool) { @@ -174,12 +174,18 @@ func (c *Capabilities) loadCapabilities(ctx context.Context, u *url.URL) (map[st return nil, err } - capa, found := response.Capabilities[AppNameSpreed] - if !found { + capaObj, found := response.Capabilities[AppNameSpreed] + if !found || capaObj == nil { log.Printf("No capabilities received for app spreed from %s: %+v", capUrl.String(), response) return nil, nil } + var capa map[string]interface{} + if err := json.Unmarshal(*capaObj, &capa); err != nil { + log.Printf("Unsupported capabilities received for app spreed from %s: %+v", capUrl.String(), response) + return nil, nil + } + log.Printf("Received capabilities %+v from %s", capa, capUrl.String()) c.setCapabilities(key, capa) return capa, nil diff --git a/capabilities_test.go b/capabilities_test.go index 1bc1fb69..19eb0879 100644 --- a/capabilities_test.go +++ b/capabilities_test.go @@ -69,15 +69,18 @@ func NewCapabilitiesForTest(t *testing.T) (*url.URL, *Capabilities) { config := map[string]interface{}{ "signaling": signaling, } + spreedCapa, _ := json.Marshal(map[string]interface{}{ + "features": features, + "config": config, + }) + emptyArray := []byte("[]") response := &CapabilitiesResponse{ Version: CapabilitiesVersion{ Major: 20, }, - Capabilities: map[string]map[string]interface{}{ - "spreed": { - "features": features, - "config": config, - }, + Capabilities: map[string]*json.RawMessage{ + "anotherApp": (*json.RawMessage)(&emptyArray), + "spreed": (*json.RawMessage)(&spreedCapa), }, } diff --git a/hub_test.go b/hub_test.go index 24e47f79..c45ebe98 100644 --- a/hub_test.go +++ b/hub_test.go @@ -420,15 +420,16 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) { if strings.Contains(t.Name(), "MultiRoom") { signaling[ConfigKeySessionPingLimit] = 2 } + spreedCapa, _ := json.Marshal(map[string]interface{}{ + "features": features, + "config": config, + }) response := &CapabilitiesResponse{ Version: CapabilitiesVersion{ Major: 20, }, - Capabilities: map[string]map[string]interface{}{ - "spreed": { - "features": features, - "config": config, - }, + Capabilities: map[string]*json.RawMessage{ + "spreed": (*json.RawMessage)(&spreedCapa), }, }