1- import { Config , PixelStreaming , SPSApplication , TextParameters , PixelStreamingApplicationStyle } from "@tensorworks/libspsfrontend" ;
1+ import { Config , PixelStreaming , SPSApplication , TextParameters , PixelStreamingApplicationStyle , MessageRecv , Flags } from "@tensorworks/libspsfrontend" ;
22
33// Apply default styling from Epic Games Pixel Streaming Frontend
44export const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle ( ) ;
@@ -7,24 +7,46 @@ PixelStreamingApplicationStyles.applyStyleSheet();
77// websocket url env
88declare var WEBSOCKET_URL : string ;
99
10+ // Extend the MessageRecv to allow the engine version to exist as part of our config message from the signalling server
11+ class MessageExtendedConfig extends MessageRecv {
12+ peerConnectionOptions : RTCConfiguration ;
13+ engineVersion : string ;
14+ platform : string ;
15+ frontendToSendOffer : boolean ;
16+ } ;
17+
18+ // Extend PixelStreaming to use our custom extended config that includes the engine version
19+ class ScalablePixelStreaming extends PixelStreaming {
20+ // Create a new method that retains original functionality
21+ public handleOnConfig ( messageExtendedConfig : MessageExtendedConfig ) {
22+ this . _webRtcController . handleOnConfigMessage ( messageExtendedConfig ) ;
23+ }
24+ } ;
25+
1026document . body . onload = function ( ) {
1127
12- // Create a config object.
13- // Note: This config is extremely important, SPS only supports the browser sending the offer.
14- const config = new Config ( { useUrlParams : true , initialSettings : { OfferToReceive : true , TimeoutIfIdle : true } } ) ;
28+ // Create a config object. We default to sending the WebRTC offer from the browser as true, TimeoutIfIdle to true, AutoConnect to false and MaxReconnectAttempts to 0
29+ const config = new Config ( { useUrlParams : true , initialSettings : { OfferToReceive : true , TimeoutIfIdle : true , AutoConnect : false , MaxReconnectAttempts : 0 } } ) ;
1530
1631 // make usage of WEBSOCKET_URL if it is not empty
1732 let webSocketAddress = WEBSOCKET_URL ;
18- if ( webSocketAddress != "" ) {
19- config . setTextSetting ( TextParameters . SignallingServerUrl , webSocketAddress )
33+ if ( webSocketAddress != "" ) {
34+ config . setTextSetting ( TextParameters . SignallingServerUrl , webSocketAddress ) ;
2035 }
2136
2237 // Create stream and spsApplication instances that implement the Epic Games Pixel Streaming Frontend PixelStreaming and Application types
23- const stream = new PixelStreaming ( config ) ;
38+ const stream = new ScalablePixelStreaming ( config ) ;
39+
40+ // Override the onConfig so we can determine if we need to send the WebRTC offer based on what is sent from the signalling server
41+ stream . webSocketController . onConfig = ( messageExtendedConfig : MessageExtendedConfig ) => {
42+ stream . config . setFlagEnabled ( Flags . BrowserSendOffer , messageExtendedConfig . frontendToSendOffer ) ;
43+ stream . handleOnConfig ( messageExtendedConfig ) ;
44+ }
45+
46+ // Create and append our application
2447 const spsApplication = new SPSApplication ( {
2548 stream,
2649 onColorModeChanged : ( isLightMode ) => PixelStreamingApplicationStyles . setColorMode ( isLightMode ) /* Light/Dark mode support. */
2750 } ) ;
28-
2951 document . body . appendChild ( spsApplication . rootElement ) ;
3052}
0 commit comments