Skip to content

Commit d232421

Browse files
authored
Merge pull request #124 from lukehb/expose_ws_xr_controllers
Exposed websocketController and webXRController to public API
2 parents bfce874 + 56a64b3 commit d232421

5 files changed

Lines changed: 103 additions & 83 deletions

File tree

Frontend/implementations/EpicGames/src/player.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ document.body.onload = function() {
1414
const config = new Config({ useUrlParams: true });
1515

1616
// Create a Native DOM delegate instance that implements the Delegate interface class
17-
const pixelStreaming = new PixelStreaming(config);
18-
const application = new Application({ pixelStreaming });
17+
const stream = new PixelStreaming(config);
18+
const application = new Application({ stream });
1919
// document.getElementById("centrebox").appendChild(application.rootElement);
2020
document.body.appendChild(application.rootElement);
2121
}

Frontend/implementations/EpicGames/src/stresstest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export class StressTester {
145145
config.setFlagEnabled(Flags.StartVideoMuted, true);
146146

147147
// Create a Native DOM delegate instance that implements the Delegate interface class
148-
const pixelStreaming = new PixelStreaming(config);
149-
const application = new Application({ pixelStreaming });
148+
const stream = new PixelStreaming(config);
149+
const application = new Application({ stream });
150150
streamFrame.appendChild(application.rootElement);
151151
return streamFrame;
152152
}

Frontend/library/src/PixelStreaming/PixelStreaming.ts

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export interface PixelStreamingOverrides {
4646
* this will likely be the core of your Pixel Streaming experience in terms of functionality.
4747
*/
4848
export class PixelStreaming {
49-
private webRtcController: WebRtcPlayerController;
50-
private webXrController: WebXRController;
49+
private _webRtcController: WebRtcPlayerController;
50+
private _webXrController: WebXRController;
5151
/**
5252
* Configuration object. You can read or modify config through this object. Whenever
5353
* the configuration is changed, the library will emit a `settingsChanged` event.
@@ -94,14 +94,14 @@ export class PixelStreaming {
9494
x: number,
9595
y: number
9696
) =>
97-
this.webRtcController.requestUnquantizedAndDenormalizeUnsigned(
97+
this._webRtcController.requestUnquantizedAndDenormalizeUnsigned(
9898
x,
9999
y
100100
);
101101
this._activateOnScreenKeyboard = (command: MessageOnScreenKeyboard) =>
102102
this.onScreenKeyboardHelper.showOnScreenKeyboard(command);
103103

104-
this.webXrController = new WebXRController(this.webRtcController);
104+
this._webXrController = new WebXRController(this._webRtcController);
105105
}
106106

107107
/**
@@ -126,24 +126,24 @@ export class PixelStreaming {
126126
// and we aren't currently quality controller, send the request
127127
if (
128128
wantsQualityController === true &&
129-
!this.webRtcController.isQualityController
129+
!this._webRtcController.isQualityController
130130
) {
131-
this.webRtcController.sendRequestQualityControlOwnership();
131+
this._webRtcController.sendRequestQualityControlOwnership();
132132
}
133133
}
134134
);
135135

136136
this.config._addOnSettingChangedListener(
137137
Flags.AFKDetection,
138138
(isAFKEnabled: boolean) => {
139-
this.webRtcController.setAfkEnabled(isAFKEnabled);
139+
this._webRtcController.setAfkEnabled(isAFKEnabled);
140140
}
141141
);
142142

143143
this.config._addOnSettingChangedListener(
144144
Flags.MatchViewportResolution,
145145
() => {
146-
this.webRtcController.videoPlayer.updateVideoStreamSize();
146+
this._webRtcController.videoPlayer.updateVideoStreamSize();
147147
}
148148
);
149149

@@ -156,7 +156,7 @@ export class PixelStreaming {
156156
isHoveringMouse ? 'Hovering' : 'Locked'
157157
} Mouse`
158158
);
159-
this.webRtcController.activateRegisterMouse();
159+
this._webRtcController.activateRegisterMouse();
160160
}
161161
);
162162

@@ -169,7 +169,7 @@ export class PixelStreaming {
169169
'-------- Sending MinQP --------',
170170
7
171171
);
172-
this.webRtcController.sendEncoderMinQP(newValue);
172+
this._webRtcController.sendEncoderMinQP(newValue);
173173
Logger.Log(
174174
Logger.GetStackTrace(),
175175
'-------------------------------------------',
@@ -186,7 +186,7 @@ export class PixelStreaming {
186186
'-------- Sending encoder settings --------',
187187
7
188188
);
189-
this.webRtcController.sendEncoderMaxQP(newValue);
189+
this._webRtcController.sendEncoderMaxQP(newValue);
190190
Logger.Log(
191191
Logger.GetStackTrace(),
192192
'-------------------------------------------',
@@ -204,7 +204,7 @@ export class PixelStreaming {
204204
'-------- Sending web rtc settings --------',
205205
7
206206
);
207-
this.webRtcController.sendWebRTCMinBitrate(newValue * 1000 /* kbps to bps */);
207+
this._webRtcController.sendWebRTCMinBitrate(newValue * 1000 /* kbps to bps */);
208208
Logger.Log(
209209
Logger.GetStackTrace(),
210210
'-------------------------------------------',
@@ -221,7 +221,7 @@ export class PixelStreaming {
221221
'-------- Sending web rtc settings --------',
222222
7
223223
);
224-
this.webRtcController.sendWebRTCMaxBitrate(newValue * 1000 /* kbps to bps */);
224+
this._webRtcController.sendWebRTCMaxBitrate(newValue * 1000 /* kbps to bps */);
225225
Logger.Log(
226226
Logger.GetStackTrace(),
227227
'-------------------------------------------',
@@ -238,7 +238,7 @@ export class PixelStreaming {
238238
'-------- Sending web rtc settings --------',
239239
7
240240
);
241-
this.webRtcController.sendWebRTCFps(newValue);
241+
this._webRtcController.sendWebRTCFps(newValue);
242242
Logger.Log(
243243
Logger.GetStackTrace(),
244244
'-------------------------------------------',
@@ -250,8 +250,8 @@ export class PixelStreaming {
250250
this.config._addOnOptionSettingChangedListener(
251251
OptionParameters.PreferredCodec,
252252
(newValue: string) => {
253-
if (this.webRtcController) {
254-
this.webRtcController.setPreferredCodec(newValue);
253+
if (this._webRtcController) {
254+
this._webRtcController.setPreferredCodec(newValue);
255255
}
256256
}
257257
);
@@ -283,13 +283,13 @@ export class PixelStreaming {
283283
private setWebRtcPlayerController(
284284
webRtcPlayerController: WebRtcPlayerController
285285
) {
286-
this.webRtcController = webRtcPlayerController;
286+
this._webRtcController = webRtcPlayerController;
287287

288-
this.webRtcController.setPreferredCodec(
288+
this._webRtcController.setPreferredCodec(
289289
this.config.getSettingOption(OptionParameters.PreferredCodec)
290290
.selected
291291
);
292-
this.webRtcController.resizePlayerStyle();
292+
this._webRtcController.resizePlayerStyle();
293293

294294
// connect if auto connect flag is enabled
295295
this.checkForAutoConnect();
@@ -299,30 +299,30 @@ export class PixelStreaming {
299299
* Connect to signaling server.
300300
*/
301301
public connect() {
302-
this.webRtcController.connectToSignallingServer();
302+
this._webRtcController.connectToSignallingServer();
303303
}
304304

305305
/**
306306
* Reconnects to the signaling server. If connection is up, disconnects first
307307
* before establishing a new connection
308308
*/
309309
public reconnect() {
310-
this.webRtcController.restartStreamAutomatically();
310+
this._webRtcController.restartStreamAutomatically();
311311
}
312312

313313
/**
314314
* Disconnect from the signaling server and close open peer connections.
315315
*/
316316
public disconnect() {
317-
this.webRtcController.close();
317+
this._webRtcController.close();
318318
}
319319

320320
/**
321321
* Play the stream. Can be called only after a peer connection has been established.
322322
*/
323323
public play() {
324324
this._onStreamLoading();
325-
this.webRtcController.playStream();
325+
this._webRtcController.playStream();
326326
}
327327

328328
/**
@@ -333,7 +333,7 @@ export class PixelStreaming {
333333
if (this.config.isFlagEnabled(Flags.AutoConnect)) {
334334
// if autoplaying show an info overlay while while waiting for the connection to begin
335335
this._onWebRtcAutoConnect();
336-
this.webRtcController.connectToSignallingServer();
336+
this._webRtcController.connectToSignallingServer();
337337
}
338338
}
339339

@@ -367,13 +367,13 @@ export class PixelStreaming {
367367
_onDisconnect(eventString: string) {
368368
// if we have overridden the default disconnection message, assign the new value here
369369
if (
370-
this.webRtcController.getDisconnectMessageOverride() != '' &&
371-
this.webRtcController.getDisconnectMessageOverride() !==
370+
this._webRtcController.getDisconnectMessageOverride() != '' &&
371+
this._webRtcController.getDisconnectMessageOverride() !==
372372
undefined &&
373-
this.webRtcController.getDisconnectMessageOverride() != null
373+
this._webRtcController.getDisconnectMessageOverride() != null
374374
) {
375-
eventString = this.webRtcController.getDisconnectMessageOverride();
376-
this.webRtcController.setDisconnectMessageOverride('');
375+
eventString = this._webRtcController.getDisconnectMessageOverride();
376+
this._webRtcController.setDisconnectMessageOverride('');
377377
}
378378

379379
this._eventEmitter.dispatchEvent(
@@ -439,7 +439,7 @@ export class PixelStreaming {
439439
videoStats.handleSessionStatistics(
440440
this._videoStartTime,
441441
this._inputController,
442-
this.webRtcController.videoAvgQp
442+
this._webRtcController.videoAvgQp
443443
);
444444

445445
this._eventEmitter.dispatchEvent(
@@ -518,10 +518,10 @@ export class PixelStreaming {
518518
* @returns
519519
*/
520520
public requestLatencyTest() {
521-
if (!this.webRtcController.videoPlayer.isVideoReady()) {
521+
if (!this._webRtcController.videoPlayer.isVideoReady()) {
522522
return false;
523523
}
524-
this.webRtcController.sendLatencyTest();
524+
this._webRtcController.sendLatencyTest();
525525
return true;
526526
}
527527

@@ -531,10 +531,10 @@ export class PixelStreaming {
531531
* @returns
532532
*/
533533
public requestShowFps() {
534-
if (!this.webRtcController.videoPlayer.isVideoReady()) {
534+
if (!this._webRtcController.videoPlayer.isVideoReady()) {
535535
return false;
536536
}
537-
this.webRtcController.sendShowFps();
537+
this._webRtcController.sendShowFps();
538538
return true;
539539
}
540540

@@ -544,10 +544,10 @@ export class PixelStreaming {
544544
* @returns
545545
*/
546546
public requestIframe() {
547-
if (!this.webRtcController.videoPlayer.isVideoReady()) {
547+
if (!this._webRtcController.videoPlayer.isVideoReady()) {
548548
return false;
549549
}
550-
this.webRtcController.sendIframeRequest();
550+
this._webRtcController.sendIframeRequest();
551551
return true;
552552
}
553553

@@ -590,4 +590,19 @@ export class PixelStreaming {
590590
public toggleXR() {
591591
this.webXrController.xrClicked();
592592
}
593+
594+
/**
595+
* Public getter for the websocket controller. Access to this property allows you to send
596+
* custom websocket messages.
597+
*/
598+
public get webSocketController() {
599+
return this._webRtcController.webSocketController;
600+
}
601+
602+
/**
603+
* Public getter for the webXrController controller. Used for all XR features.
604+
*/
605+
public get webXrController() {
606+
return this._webXrController;
607+
}
593608
}

0 commit comments

Comments
 (0)