Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #124 from lukehb/expose_ws_xr_controllers
Browse files Browse the repository at this point in the history
Exposed websocketController and webXRController to public API
  • Loading branch information
lukehb committed Feb 25, 2023
2 parents bfce874 + 56a64b3 commit d232421
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 83 deletions.
4 changes: 2 additions & 2 deletions Frontend/implementations/EpicGames/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ document.body.onload = function() {
const config = new Config({ useUrlParams: true });

// Create a Native DOM delegate instance that implements the Delegate interface class
const pixelStreaming = new PixelStreaming(config);
const application = new Application({ pixelStreaming });
const stream = new PixelStreaming(config);
const application = new Application({ stream });
// document.getElementById("centrebox").appendChild(application.rootElement);
document.body.appendChild(application.rootElement);
}
4 changes: 2 additions & 2 deletions Frontend/implementations/EpicGames/src/stresstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export class StressTester {
config.setFlagEnabled(Flags.StartVideoMuted, true);

// Create a Native DOM delegate instance that implements the Delegate interface class
const pixelStreaming = new PixelStreaming(config);
const application = new Application({ pixelStreaming });
const stream = new PixelStreaming(config);
const application = new Application({ stream });
streamFrame.appendChild(application.rootElement);
return streamFrame;
}
Expand Down
87 changes: 51 additions & 36 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export interface PixelStreamingOverrides {
* this will likely be the core of your Pixel Streaming experience in terms of functionality.
*/
export class PixelStreaming {
private webRtcController: WebRtcPlayerController;
private webXrController: WebXRController;
private _webRtcController: WebRtcPlayerController;
private _webXrController: WebXRController;
/**
* Configuration object. You can read or modify config through this object. Whenever
* the configuration is changed, the library will emit a `settingsChanged` event.
Expand Down Expand Up @@ -94,14 +94,14 @@ export class PixelStreaming {
x: number,
y: number
) =>
this.webRtcController.requestUnquantizedAndDenormalizeUnsigned(
this._webRtcController.requestUnquantizedAndDenormalizeUnsigned(
x,
y
);
this._activateOnScreenKeyboard = (command: MessageOnScreenKeyboard) =>
this.onScreenKeyboardHelper.showOnScreenKeyboard(command);

this.webXrController = new WebXRController(this.webRtcController);
this._webXrController = new WebXRController(this._webRtcController);
}

/**
Expand All @@ -126,24 +126,24 @@ export class PixelStreaming {
// and we aren't currently quality controller, send the request
if (
wantsQualityController === true &&
!this.webRtcController.isQualityController
!this._webRtcController.isQualityController
) {
this.webRtcController.sendRequestQualityControlOwnership();
this._webRtcController.sendRequestQualityControlOwnership();
}
}
);

this.config._addOnSettingChangedListener(
Flags.AFKDetection,
(isAFKEnabled: boolean) => {
this.webRtcController.setAfkEnabled(isAFKEnabled);
this._webRtcController.setAfkEnabled(isAFKEnabled);
}
);

this.config._addOnSettingChangedListener(
Flags.MatchViewportResolution,
() => {
this.webRtcController.videoPlayer.updateVideoStreamSize();
this._webRtcController.videoPlayer.updateVideoStreamSize();
}
);

Expand All @@ -156,7 +156,7 @@ export class PixelStreaming {
isHoveringMouse ? 'Hovering' : 'Locked'
} Mouse`
);
this.webRtcController.activateRegisterMouse();
this._webRtcController.activateRegisterMouse();
}
);

Expand All @@ -169,7 +169,7 @@ export class PixelStreaming {
'-------- Sending MinQP --------',
7
);
this.webRtcController.sendEncoderMinQP(newValue);
this._webRtcController.sendEncoderMinQP(newValue);
Logger.Log(
Logger.GetStackTrace(),
'-------------------------------------------',
Expand All @@ -186,7 +186,7 @@ export class PixelStreaming {
'-------- Sending encoder settings --------',
7
);
this.webRtcController.sendEncoderMaxQP(newValue);
this._webRtcController.sendEncoderMaxQP(newValue);
Logger.Log(
Logger.GetStackTrace(),
'-------------------------------------------',
Expand All @@ -204,7 +204,7 @@ export class PixelStreaming {
'-------- Sending web rtc settings --------',
7
);
this.webRtcController.sendWebRTCMinBitrate(newValue * 1000 /* kbps to bps */);
this._webRtcController.sendWebRTCMinBitrate(newValue * 1000 /* kbps to bps */);
Logger.Log(
Logger.GetStackTrace(),
'-------------------------------------------',
Expand All @@ -221,7 +221,7 @@ export class PixelStreaming {
'-------- Sending web rtc settings --------',
7
);
this.webRtcController.sendWebRTCMaxBitrate(newValue * 1000 /* kbps to bps */);
this._webRtcController.sendWebRTCMaxBitrate(newValue * 1000 /* kbps to bps */);
Logger.Log(
Logger.GetStackTrace(),
'-------------------------------------------',
Expand All @@ -238,7 +238,7 @@ export class PixelStreaming {
'-------- Sending web rtc settings --------',
7
);
this.webRtcController.sendWebRTCFps(newValue);
this._webRtcController.sendWebRTCFps(newValue);
Logger.Log(
Logger.GetStackTrace(),
'-------------------------------------------',
Expand All @@ -250,8 +250,8 @@ export class PixelStreaming {
this.config._addOnOptionSettingChangedListener(
OptionParameters.PreferredCodec,
(newValue: string) => {
if (this.webRtcController) {
this.webRtcController.setPreferredCodec(newValue);
if (this._webRtcController) {
this._webRtcController.setPreferredCodec(newValue);
}
}
);
Expand Down Expand Up @@ -283,13 +283,13 @@ export class PixelStreaming {
private setWebRtcPlayerController(
webRtcPlayerController: WebRtcPlayerController
) {
this.webRtcController = webRtcPlayerController;
this._webRtcController = webRtcPlayerController;

this.webRtcController.setPreferredCodec(
this._webRtcController.setPreferredCodec(
this.config.getSettingOption(OptionParameters.PreferredCodec)
.selected
);
this.webRtcController.resizePlayerStyle();
this._webRtcController.resizePlayerStyle();

// connect if auto connect flag is enabled
this.checkForAutoConnect();
Expand All @@ -299,30 +299,30 @@ export class PixelStreaming {
* Connect to signaling server.
*/
public connect() {
this.webRtcController.connectToSignallingServer();
this._webRtcController.connectToSignallingServer();
}

/**
* Reconnects to the signaling server. If connection is up, disconnects first
* before establishing a new connection
*/
public reconnect() {
this.webRtcController.restartStreamAutomatically();
this._webRtcController.restartStreamAutomatically();
}

/**
* Disconnect from the signaling server and close open peer connections.
*/
public disconnect() {
this.webRtcController.close();
this._webRtcController.close();
}

/**
* Play the stream. Can be called only after a peer connection has been established.
*/
public play() {
this._onStreamLoading();
this.webRtcController.playStream();
this._webRtcController.playStream();
}

/**
Expand All @@ -333,7 +333,7 @@ export class PixelStreaming {
if (this.config.isFlagEnabled(Flags.AutoConnect)) {
// if autoplaying show an info overlay while while waiting for the connection to begin
this._onWebRtcAutoConnect();
this.webRtcController.connectToSignallingServer();
this._webRtcController.connectToSignallingServer();
}
}

Expand Down Expand Up @@ -367,13 +367,13 @@ export class PixelStreaming {
_onDisconnect(eventString: string) {
// if we have overridden the default disconnection message, assign the new value here
if (
this.webRtcController.getDisconnectMessageOverride() != '' &&
this.webRtcController.getDisconnectMessageOverride() !==
this._webRtcController.getDisconnectMessageOverride() != '' &&
this._webRtcController.getDisconnectMessageOverride() !==
undefined &&
this.webRtcController.getDisconnectMessageOverride() != null
this._webRtcController.getDisconnectMessageOverride() != null
) {
eventString = this.webRtcController.getDisconnectMessageOverride();
this.webRtcController.setDisconnectMessageOverride('');
eventString = this._webRtcController.getDisconnectMessageOverride();
this._webRtcController.setDisconnectMessageOverride('');
}

this._eventEmitter.dispatchEvent(
Expand Down Expand Up @@ -439,7 +439,7 @@ export class PixelStreaming {
videoStats.handleSessionStatistics(
this._videoStartTime,
this._inputController,
this.webRtcController.videoAvgQp
this._webRtcController.videoAvgQp
);

this._eventEmitter.dispatchEvent(
Expand Down Expand Up @@ -518,10 +518,10 @@ export class PixelStreaming {
* @returns
*/
public requestLatencyTest() {
if (!this.webRtcController.videoPlayer.isVideoReady()) {
if (!this._webRtcController.videoPlayer.isVideoReady()) {
return false;
}
this.webRtcController.sendLatencyTest();
this._webRtcController.sendLatencyTest();
return true;
}

Expand All @@ -531,10 +531,10 @@ export class PixelStreaming {
* @returns
*/
public requestShowFps() {
if (!this.webRtcController.videoPlayer.isVideoReady()) {
if (!this._webRtcController.videoPlayer.isVideoReady()) {
return false;
}
this.webRtcController.sendShowFps();
this._webRtcController.sendShowFps();
return true;
}

Expand All @@ -544,10 +544,10 @@ export class PixelStreaming {
* @returns
*/
public requestIframe() {
if (!this.webRtcController.videoPlayer.isVideoReady()) {
if (!this._webRtcController.videoPlayer.isVideoReady()) {
return false;
}
this.webRtcController.sendIframeRequest();
this._webRtcController.sendIframeRequest();
return true;
}

Expand Down Expand Up @@ -590,4 +590,19 @@ export class PixelStreaming {
public toggleXR() {
this.webXrController.xrClicked();
}

/**
* Public getter for the websocket controller. Access to this property allows you to send
* custom websocket messages.
*/
public get webSocketController() {
return this._webRtcController.webSocketController;
}

/**
* Public getter for the webXrController controller. Used for all XR features.
*/
public get webXrController() {
return this._webXrController;
}
}
Loading

0 comments on commit d232421

Please sign in to comment.