Skip to content

Commit

Permalink
Merge pull request #419 from mcottontensor/fix_reconnect_flow
Browse files Browse the repository at this point in the history
Rewriting a bunch of reconnect and disconnect handling.
  • Loading branch information
mcottontensor committed Nov 2, 2023
1 parent d0e3bc4 commit ad2b4f5
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 204 deletions.
6 changes: 4 additions & 2 deletions Frontend/library/src/PixelStreaming/PixelStreaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ describe('PixelStreaming', () => {
type: MessageRecvTypes.STREAMER_LIST,
ids: streamerIdList
}),
autoSelectedStreamerId: streamerId
autoSelectedStreamerId: streamerId,
wantedStreamerId: null
}));
expect(webSocketSpyFunctions.sendSpy).toHaveBeenCalledWith(
expect.stringMatching(/"type":"subscribe".*MOCK_PIXEL_STREAMING/)
Expand All @@ -298,7 +299,8 @@ describe('PixelStreaming', () => {
type: MessageRecvTypes.STREAMER_LIST,
ids: extendedStreamerIdList
}),
autoSelectedStreamerId: null
autoSelectedStreamerId: null,
wantedStreamerId: null
}));
expect(webSocketSpyFunctions.sendSpy).not.toHaveBeenCalledWith(
expect.stringMatching(/"type":"subscribe"/)
Expand Down
34 changes: 11 additions & 23 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class PixelStreaming {

private _videoElementParent: HTMLElement;

_showActionOrErrorOnDisconnect = true;
private allowConsoleCommands = false;

private onScreenKeyboardHelper: OnScreenKeyboard;
Expand Down Expand Up @@ -353,7 +352,7 @@ export class PixelStreaming {
*/
public reconnect() {
this._eventEmitter.dispatchEvent(new StreamReconnectEvent());
this._webRtcController.restartStreamAutomatically();
this._webRtcController.tryReconnect("Reconnecting...");
}

/**
Expand Down Expand Up @@ -440,7 +439,6 @@ export class PixelStreaming {
*/
_onWebRtcAutoConnect() {
this._eventEmitter.dispatchEvent(new WebRtcAutoConnectEvent());
this._showActionOrErrorOnDisconnect = true;
}

/**
Expand All @@ -460,30 +458,16 @@ export class PixelStreaming {
/**
* Event fired when the video is disconnected - emits given eventString or an override
* message from webRtcController if one has been set
* @param eventString - the event text that will be emitted
*/
_onDisconnect(eventString: string) {
// if we have overridden the default disconnection message, assign the new value here
if (
this._webRtcController.getDisconnectMessageOverride() != '' &&
this._webRtcController.getDisconnectMessageOverride() !==
undefined &&
this._webRtcController.getDisconnectMessageOverride() != null
) {
eventString = this._webRtcController.getDisconnectMessageOverride();
this._webRtcController.setDisconnectMessageOverride('');
}

* @param eventString - a string describing why the connection closed
* @param allowClickToReconnect - true if we want to allow the user to retry the connection with a click
*/
_onDisconnect(eventString: string, allowClickToReconnect: boolean) {
this._eventEmitter.dispatchEvent(
new WebRtcDisconnectedEvent({
eventString,
showActionOrErrorOnDisconnect:
this._showActionOrErrorOnDisconnect
eventString: eventString,
allowClickToReconnect: allowClickToReconnect
})
);
if (this._showActionOrErrorOnDisconnect == false) {
this._showActionOrErrorOnDisconnect = true;
}
}

/**
Expand Down Expand Up @@ -856,4 +840,8 @@ export class PixelStreaming {
public get toStreamerHandlers() {
return this._webRtcController.streamMessageController.toStreamerHandlers;
}

public isReconnecting() {
return this._webRtcController.isReconnecting;
}
}
6 changes: 4 additions & 2 deletions Frontend/library/src/Util/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class WebRtcDisconnectedEvent extends Event {
/** Message describing the disconnect reason */
eventString: string;
/** true if the user is able to reconnect, false if disconnected because of unrecoverable reasons like not able to connect to the signaling server */
showActionOrErrorOnDisconnect: boolean;
allowClickToReconnect: boolean;
};
constructor(data: WebRtcDisconnectedEvent['data']) {
super('webRtcDisconnected');
Expand Down Expand Up @@ -347,7 +347,9 @@ export class StreamerListMessageEvent extends Event {
/** Streamer list message containing an array of streamer ids */
messageStreamerList: MessageStreamerList;
/** Auto-selected streamer from the list, or null if unable to auto-select and user should be prompted to select */
autoSelectedStreamerId: string | null;
autoSelectedStreamerId: string;
/** Wanted streamer id from various configurations. */
wantedStreamerId: string;
};
constructor(data: StreamerListMessageEvent['data']) {
super('streamerListMessage');
Expand Down

0 comments on commit ad2b4f5

Please sign in to comment.