Skip to content

Commit

Permalink
Merge pull request #879 from strukturag/join-features
Browse files Browse the repository at this point in the history
Include client features in "join" events.
  • Loading branch information
fancycode authored Dec 12, 2024
2 parents 18c3bb5 + fda934d commit 76af5af
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 41 deletions.
6 changes: 6 additions & 0 deletions api_signaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ const (
ServerFeatureDialout = "dialout"
ServerFeatureFederation = "federation"
ServerFeatureRecipientCall = "recipient-call"
ServerFeatureJoinFeatures = "join-features"

// Features to send to internal clients only.
ServerFeatureInternalVirtualSessions = "virtual-sessions"
Expand All @@ -551,6 +552,7 @@ var (
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
ServerFeatureJoinFeatures,
}
DefaultFeaturesInternal = []string{
ServerFeatureInternalVirtualSessions,
Expand All @@ -562,6 +564,7 @@ var (
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
ServerFeatureJoinFeatures,
}
DefaultWelcomeFeatures = []string{
ServerFeatureAudioVideoPermissions,
Expand All @@ -574,6 +577,7 @@ var (
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
ServerFeatureJoinFeatures,
}
)

Expand Down Expand Up @@ -1068,6 +1072,7 @@ func (m *EventServerMessage) String() string {
type EventServerMessageSessionEntry struct {
SessionId string `json:"sessionid"`
UserId string `json:"userid"`
Features []string `json:"features,omitempty"`
User json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
Federated bool `json:"federated,omitempty"`
Expand All @@ -1077,6 +1082,7 @@ func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry
return &EventServerMessageSessionEntry{
SessionId: e.SessionId,
UserId: e.UserId,
Features: e.Features,
User: e.User,
RoomSessionId: e.RoomSessionId,
Federated: e.Federated,
Expand Down
115 changes: 76 additions & 39 deletions api_signaling_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion docs/standalone-signaling-api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,19 @@ Room event session object:
"userid": "the-user-id-for-known-users",
"user": {
...additional data of the user as received from the auth backend...
}
},
"roomsessionid": "the-nextcloud-talk-session-id",
"features": [
...optional list of feature ids from the clients "hello" request...
]
}

If a session is federated, an additional entry `"federated": true` will be
available.

The feature ids are present in the `join` events if the server supports the
`join-features` feature.


Message format (Server -> Client, user(s) left):

Expand Down
2 changes: 2 additions & 0 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (r *Room) notifySessionJoined(sessionId string) {
User: s.UserData(),
}
if s, ok := s.(*ClientSession); ok {
entry.Features = s.GetFeatures()
entry.RoomSessionId = s.RoomSessionId()
entry.Federated = s.ClientType() == HelloClientTypeFederation
}
Expand Down Expand Up @@ -551,6 +552,7 @@ func (r *Room) PublishSessionJoined(session Session, sessionData *RoomSessionDat
},
}
if session, ok := session.(*ClientSession); ok {
message.Event.Join[0].Features = session.GetFeatures()
message.Event.Join[0].RoomSessionId = session.RoomSessionId()
message.Event.Join[0].Federated = session.ClientType() == HelloClientTypeFederation
}
Expand Down
39 changes: 39 additions & 0 deletions room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,45 @@ loop:
assert.NoError(err)
}

func TestRoom_RoomJoinFeatures(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
require := require.New(t)
assert := assert.New(t)
hub, _, router, server := CreateHubForTest(t)

config, err := getTestConfig(server)
require.NoError(err)
b, err := NewBackendServer(config, hub, "no-version")
require.NoError(err)
require.NoError(b.Start(router))

client := NewTestClient(t, server, hub)
defer client.CloseWithBye()

features := []string{"one", "two", "three"}
require.NoError(client.SendHelloClientWithFeatures(testDefaultUserId, features))

ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

hello, err := client.RunUntilHello(ctx)
require.NoError(err)

// Join room by id.
roomId := "test-room"
roomMsg, err := client.JoinRoom(ctx, roomId)
require.NoError(err)
require.Equal(roomId, roomMsg.Room.RoomId)

if message, err := client.RunUntilMessage(ctx); assert.NoError(err) {
if assert.NoError(client.checkMessageJoinedSession(message, hello.Hello.SessionId, testDefaultUserId)) {
assert.Equal(roomId+"-"+hello.Hello.SessionId, message.Event.Join[0].RoomSessionId)
assert.Equal(features, message.Event.Join[0].Features)
}
}
}

func TestRoom_RoomSessionData(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
Expand Down
6 changes: 5 additions & 1 deletion testclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,14 @@ func (c *TestClient) SendHelloResume(resumeId string) error {
}

func (c *TestClient) SendHelloClient(userid string) error {
return c.SendHelloClientWithFeatures(userid, nil)
}

func (c *TestClient) SendHelloClientWithFeatures(userid string, features []string) error {
params := TestBackendClientAuthParams{
UserId: userid,
}
return c.SendHelloParams(c.server.URL, HelloVersionV1, "client", nil, params)
return c.SendHelloParams(c.server.URL, HelloVersionV1, "client", features, params)
}

func (c *TestClient) SendHelloInternal() error {
Expand Down

0 comments on commit 76af5af

Please sign in to comment.