|
7 | 7 | ITransport, |
8 | 8 | Messages, |
9 | 9 | MessageHelpers, |
10 | | - BaseMessage |
| 10 | + BaseMessage, |
| 11 | + KeepaliveMonitor |
11 | 12 | } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5'; |
12 | 13 | import { StreamController } from '../VideoPlayer/StreamController'; |
13 | 14 | import { FreezeFrameController } from '../FreezeFrame/FreezeFrameController'; |
@@ -104,6 +105,7 @@ export class WebRtcPlayerController { |
104 | 105 | subscribedStream: string; |
105 | 106 | signallingUrlBuilder: () => string; |
106 | 107 | autoJoinTimer: ReturnType<typeof setTimeout> = undefined; |
| 108 | + keepalive: KeepaliveMonitor; |
107 | 109 |
|
108 | 110 | /** |
109 | 111 | * |
@@ -171,6 +173,9 @@ export class WebRtcPlayerController { |
171 | 173 | this.protocol.addListener(Messages.config.typeName, (msg: BaseMessage) => |
172 | 174 | this.handleOnConfigMessage(msg as Messages.config) |
173 | 175 | ); |
| 176 | + this.protocol.addListener(Messages.ping.typeName, (msg: BaseMessage) => |
| 177 | + this.handlePingMessage(msg as Messages.ping) |
| 178 | + ); |
174 | 179 | this.protocol.addListener(Messages.streamerList.typeName, (msg: BaseMessage) => |
175 | 180 | this.handleStreamerListMessage(msg as Messages.streamerList) |
176 | 181 | ); |
@@ -846,7 +851,7 @@ export class WebRtcPlayerController { |
846 | 851 | // if the connection is open, first close it and force a reconnect. |
847 | 852 | if (this.protocol.isConnected()) { |
848 | 853 | if (!this.forceReconnect) { |
849 | | - message = `${message} Reconnecting.`; |
| 854 | + this.disconnectMessage = `${message} Reconnecting.`; |
850 | 855 | } |
851 | 856 | this.closeSignalingServer(message, true); |
852 | 857 | } else { |
@@ -1023,6 +1028,15 @@ export class WebRtcPlayerController { |
1023 | 1028 | this.disconnectMessage = null; |
1024 | 1029 | const signallingUrl = this.signallingUrlBuilder(); |
1025 | 1030 | this.protocol.connect(signallingUrl); |
| 1031 | + const keepaliveDelay = this.config.getNumericSettingValue(NumericParameters.KeepaliveDelay); |
| 1032 | + if (keepaliveDelay > 0) { |
| 1033 | + this.keepalive = new KeepaliveMonitor(this.protocol, keepaliveDelay); |
| 1034 | + this.keepalive.onTimeout = () => { |
| 1035 | + // if the ping fails just disconnect |
| 1036 | + Logger.Error(`Protocol timeout`); |
| 1037 | + this.protocol.disconnect(); |
| 1038 | + }; |
| 1039 | + } |
1026 | 1040 | } |
1027 | 1041 |
|
1028 | 1042 | /** |
@@ -1138,6 +1152,10 @@ export class WebRtcPlayerController { |
1138 | 1152 | this.startSession(messageConfig.peerConnectionOptions); |
1139 | 1153 | } |
1140 | 1154 |
|
| 1155 | + handlePingMessage(pingMessage: Messages.ping) { |
| 1156 | + this.protocol.sendMessage(MessageHelpers.createMessage(Messages.pong, { time: pingMessage.time })); |
| 1157 | + } |
| 1158 | + |
1141 | 1159 | /** |
1142 | 1160 | * Handles when the signalling server gives us the list of streamer ids. |
1143 | 1161 | */ |
|
0 commit comments