Skip to content

Commit

Permalink
Merge pull request #287 from strukturag/arbitrary-capabilities
Browse files Browse the repository at this point in the history
Support arbitrary capabilities values.
  • Loading branch information
fancycode authored Jul 4, 2022
2 parents ddb7ece + ec62503 commit 32a2f82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
14 changes: 10 additions & 4 deletions capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand Down
11 changes: 6 additions & 5 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand Down

0 comments on commit 32a2f82

Please sign in to comment.