Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-55975] Fix regression when presenting session leaves call without previously… #577

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions e2e/tests/media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,54 @@ test.describe('screen sharing', () => {
await devPage.leaveCall();
await userPage.leaveCall();
});

test('presenter leaving and joining back', async ({page}) => {
const userPage = await startCall(userStorages[1]);

const devPage = new PlaywrightDevPage(page);
await devPage.joinCall();

// presenter starts sharing
await page.locator('#calls-widget-toggle-menu-button').click();
await page.locator('#calls-widget-menu-screenshare').click();

// verify that on both sides the screen sharing player is rendered
await expect(page.locator('#screen-player')).toBeVisible();
await expect(userPage.page.locator('#screen-player')).toBeVisible();

await devPage.wait(1000);

// verify that on the receiving side the screen track is correctly set
let screenStreamID = await userPage.page.evaluate(() => {
return window.callsClient.getRemoteScreenStream()?.getVideoTracks()[0]?.id;
});
expect(screenStreamID).toContain('screen_');

// presenter leaves call
await devPage.leaveCall();

// here we switch roles, previous presenter will now be receiving
await devPage.joinCall();

// the other participant shares screen
await userPage.page.locator('#calls-widget-toggle-menu-button').click();
await userPage.page.locator('#calls-widget-menu-screenshare').click();

// verify that on both sides the screen sharing player is rendered
await expect(userPage.page.locator('#screen-player')).toBeVisible();
await expect(devPage.page.locator('#screen-player')).toBeVisible();

await userPage.wait(1000);

// verify that on the receiving side the screen track is correctly set
screenStreamID = await devPage.page.evaluate(() => {
return window.callsClient.getRemoteScreenStream()?.getVideoTracks()[0]?.id;
});
expect(screenStreamID).toContain('screen_');

await devPage.leaveCall();
await userPage.leaveCall();
});
});

test.describe('sending voice', () => {
Expand Down
6 changes: 3 additions & 3 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ func (p *Plugin) removeUserSession(state *channelState, userID, connID, channelI

state = state.Clone()

if state.Call.ScreenSharingID == userID {
state.Call.ScreenSharingID = ""
if state.Call.ScreenSharingSessionID == connID {
state.Call.ScreenSharingSessionID = ""
state.Call.ScreenStreamID = ""
if state.Call.ScreenStartAt > 0 {
state.Call.Stats.ScreenDuration += secondsSinceTimestamp(state.Call.ScreenStartAt)
Expand Down Expand Up @@ -311,7 +311,7 @@ func (p *Plugin) removeSession(us *session) error {
}, &model.WebsocketBroadcast{ChannelId: us.channelID, ReliableClusterSend: true})

// If the removed user was sharing we should send out a screen off event.
if prevState.Call.ScreenSharingID != "" && (currState.Call == nil || currState.Call.ScreenSharingID == "") {
if prevState.Call.ScreenSharingSessionID != "" && (currState.Call == nil || currState.Call.ScreenSharingSessionID == "") {
p.LogDebug("removed session was sharing, sending screen off event", "userID", us.userID, "connID", us.connID)
p.publishWebSocketEvent(wsEventUserScreenOff, map[string]interface{}{}, &model.WebsocketBroadcast{ChannelId: us.channelID, ReliableClusterSend: true})
}
Expand Down
36 changes: 18 additions & 18 deletions server/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ type callStats struct {
}

type callState struct {
ID string `json:"id"`
StartAt int64 `json:"create_at"`
EndAt int64 `json:"end_at"`
Sessions map[string]*userState `json:"sessions,omitempty"`
OwnerID string `json:"owner_id"`
ThreadID string `json:"thread_id"`
PostID string `json:"post_id"`
ScreenSharingID string `json:"screen_sharing_id"`
ScreenStreamID string `json:"screen_stream_id"`
ScreenStartAt int64 `json:"screen_start_at"`
Stats callStats `json:"stats"`
RTCDHost string `json:"rtcd_host"`
HostID string `json:"host_id"`
Recording *jobState `json:"recording,omitempty"`
Transcription *jobState `json:"transcription,omitempty"`
DismissedNotification map[string]bool `json:"dismissed_notification,omitempty"`
ID string `json:"id"`
StartAt int64 `json:"create_at"`
EndAt int64 `json:"end_at"`
Sessions map[string]*userState `json:"sessions,omitempty"`
OwnerID string `json:"owner_id"`
ThreadID string `json:"thread_id"`
PostID string `json:"post_id"`
ScreenSharingSessionID string `json:"screen_sharing_session_id"`
ScreenStreamID string `json:"screen_stream_id"`
ScreenStartAt int64 `json:"screen_start_at"`
Stats callStats `json:"stats"`
RTCDHost string `json:"rtcd_host"`
HostID string `json:"host_id"`
Recording *jobState `json:"recording,omitempty"`
Transcription *jobState `json:"transcription,omitempty"`
DismissedNotification map[string]bool `json:"dismissed_notification,omitempty"`
}

type channelState struct {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (cs *callState) getClientState(botID, userID string) *CallStateClient {
}

var screenSharingUserID string
if s := cs.Sessions[cs.ScreenSharingID]; s != nil {
if s := cs.Sessions[cs.ScreenSharingSessionID]; s != nil {
screenSharingUserID = s.UserID
}

Expand All @@ -255,7 +255,7 @@ func (cs *callState) getClientState(botID, userID string) *CallStateClient {
// DEPRECATED since v0.21
ScreenSharingID: screenSharingUserID,

ScreenSharingSessionID: cs.ScreenSharingID,
ScreenSharingSessionID: cs.ScreenSharingSessionID,
OwnerID: cs.OwnerID,
HostID: cs.HostID,
Recording: cs.Recording.getClientState(),
Expand Down
10 changes: 5 additions & 5 deletions server/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func TestCallStateGetClientState(t *testing.T) {
RaisedHand: 1100,
},
},
ThreadID: "threadID",
ScreenSharingID: "sessionA",
OwnerID: "ownerID",
HostID: "hostID",
ThreadID: "threadID",
ScreenSharingSessionID: "sessionA",
OwnerID: "ownerID",
HostID: "hostID",
}
ccs := CallStateClient{
ID: cs.ID,
Expand All @@ -88,7 +88,7 @@ func TestCallStateGetClientState(t *testing.T) {
},
ThreadID: cs.ThreadID,
ScreenSharingID: "userA",
ScreenSharingSessionID: cs.ScreenSharingID,
ScreenSharingSessionID: cs.ScreenSharingSessionID,
OwnerID: cs.OwnerID,
HostID: cs.HostID,
}
Expand Down
12 changes: 6 additions & 6 deletions server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ func (p *Plugin) handleClientMessageTypeScreen(us *session, msg clientMessage, h
}

if msg.Type == clientMessageTypeScreenOn {
if state.Call.ScreenSharingID != "" {
return fmt.Errorf("cannot start screen sharing, someone else is sharing already: connID=%s", state.Call.ScreenSharingID)
if state.Call.ScreenSharingSessionID != "" {
return fmt.Errorf("cannot start screen sharing, someone else is sharing already: connID=%s", state.Call.ScreenSharingSessionID)
}
state.Call.ScreenSharingID = us.originalConnID
state.Call.ScreenSharingSessionID = us.originalConnID
state.Call.ScreenStreamID = data["screenStreamID"]
state.Call.ScreenStartAt = time.Now().Unix()
} else {
if state.Call.ScreenSharingID != us.originalConnID {
return fmt.Errorf("cannot stop screen sharing, someone else is sharing already: connID=%s", state.Call.ScreenSharingID)
if state.Call.ScreenSharingSessionID != us.originalConnID {
return fmt.Errorf("cannot stop screen sharing, someone else is sharing already: connID=%s", state.Call.ScreenSharingSessionID)
}
state.Call.ScreenSharingID = ""
state.Call.ScreenSharingSessionID = ""
state.Call.ScreenStreamID = ""
if state.Call.ScreenStartAt > 0 {
state.Call.Stats.ScreenDuration += secondsSinceTimestamp(state.Call.ScreenStartAt)
Expand Down