Skip to content
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
9 changes: 0 additions & 9 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { Config, PixelStreaming, SPSApplication, TextParameters, PixelStreamingA
export const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
PixelStreamingApplicationStyles.applyStyleSheet();

// websocket url env
declare var WEBSOCKET_URL: string;

// Extend the MessageRecv to allow the engine version to exist as part of our config message from the signalling server
class MessageExtendedConfig extends MessageRecv {
peerConnectionOptions: RTCConfiguration;
Expand All @@ -28,12 +25,6 @@ document.body.onload = function () {
// 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
const config = new Config({ useUrlParams: true, initialSettings: { OfferToReceive: true, TimeoutIfIdle: true, AutoConnect: false, MaxReconnectAttempts: 0 } });

// make usage of WEBSOCKET_URL if it is not empty
let webSocketAddress = WEBSOCKET_URL;
if (webSocketAddress != "") {
config.setTextSetting(TextParameters.SignallingServerUrl, webSocketAddress);
}

// Create stream and spsApplication instances that implement the Epic Games Pixel Streaming Frontend PixelStreaming and Application types
const stream = new ScalablePixelStreaming(config);

Expand Down
15 changes: 12 additions & 3 deletions library/src/SPSApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { LoadingOverlay } from './LoadingOverlay';
import { SPSSignalling } from './SignallingExtension';
import { MessageStats } from './Messages';

// For local testing. Declare a websocket URL that can be imported via a .env file that will override
// the signalling server URL builder.
declare var WEBSOCKET_URL: string;


export class SPSApplication extends Application {
private loadingOverlay: LoadingOverlay;
Expand Down Expand Up @@ -53,13 +57,18 @@ export class SPSApplication extends Application {
}

enforceSpecialSignallingServerUrl() {
// SPS needs a special /ws added to the signalling server url so K8s can distinguish it
// SPS needs to build a specific signalling server url based on the application name so K8s can distinguish it
this.stream.setSignallingUrlBuilder(() => {

// if we have overriden the signalling server URL with a .env file use it here
if (WEBSOCKET_URL) {
return WEBSOCKET_URL as string;
}

// get the current signalling url
let signallingUrl = this.stream.config.getTextSettingValue(TextParameters.SignallingServerUrl);

// add our 'ws' token to the end dependant on whether the URL ends with a '/' or not
// build the signalling URL based on the existing window location, the result should be 'domain.com/signalling/app-name'
signallingUrl = signallingUrl.endsWith("/") ? signallingUrl + "signalling" + window.location.pathname : signallingUrl + "/signalling" + window.location.pathname;

return signallingUrl
Expand All @@ -85,4 +94,4 @@ export class SPSApplication extends Application {
const data = new MessageStats(stats);
this.stream.webSocketController.webSocket.send(data.payload());
}
}
}