From 71d7062505bd0b97edea48d1025d86b37c2a8da9 Mon Sep 17 00:00:00 2001 From: Daniel Holden Date: Wed, 10 Jul 2024 13:16:57 +1000 Subject: [PATCH] override the stream disconnect event and fire off our own webrtc disconnect that always allows a reconnect. also fix some grammar issues --- examples/typescript/src/index.ts | 20 +++++++++++++++++++- library/src/index.ts | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/examples/typescript/src/index.ts b/examples/typescript/src/index.ts index cd8507fc..93497d64 100644 --- a/examples/typescript/src/index.ts +++ b/examples/typescript/src/index.ts @@ -1,4 +1,4 @@ -import { Config, PixelStreaming, SPSApplication, TextParameters, PixelStreamingApplicationStyle, MessageRecv, Flags } from "@tensorworks/libspsfrontend"; +import { Config, PixelStreaming, SPSApplication, TextParameters, PixelStreamingApplicationStyle, MessageRecv, Flags, WebRtcDisconnectedEvent } from "@tensorworks/libspsfrontend"; // Apply default styling from Epic Games Pixel Streaming Frontend export const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle(); @@ -34,6 +34,24 @@ document.body.onload = function () { stream.handleOnConfig(messageExtendedConfig); } + // override the _onDisconnect function to intercept webrtc disconnect events + // and modify how the event is fired by always showing a click to reconnect overlay. + // we also add a full stop to the AFK message. + stream._onDisconnect = function (eventString: string) { + + // check if the eventString coming in is the inactivity string and add a full stop + if (eventString == "You have been disconnected due to inactivity") { + eventString += "." + } + + this._eventEmitter.dispatchEvent( + new WebRtcDisconnectedEvent({ + eventString: eventString, + allowClickToReconnect: true + }) + ); + } + // Create and append our application const spsApplication = new SPSApplication({ stream, diff --git a/library/src/index.ts b/library/src/index.ts index 995d9dca..557a0fb4 100644 --- a/library/src/index.ts +++ b/library/src/index.ts @@ -5,7 +5,7 @@ export { MessageSendTypes, MessageStats } from "./Messages"; export { MessageAuthRequest, InstanceState, MessageInstanceState, MessageAuthResponseOutcomeType, MessageAuthResponse, MessageRequestInstance, SPSSignalling } from "./SignallingExtension"; // Epic Games Pixel Streaming Frontend exports -export { WebRtcPlayerController } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.4'; +export { WebRtcPlayerController, WebRtcDisconnectedEvent } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.4'; export { WebXRController } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.4'; export { Config, ControlSchemeType, Flags, NumericParameters, TextParameters, OptionParameters, FlagsIds, NumericParametersIds, TextParametersIds, OptionParametersIds, AllSettings } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.4'; export { SettingBase } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.4';