11// Copyright Epic Games, Inc. All Rights Reserved.
22
33import { Logger } from '../Logger/Logger' ;
4- import { WebRtcPlayerController } from '../pixelstreamingfrontend ' ;
4+ import { WebRtcPlayerController } from '../WebRtcPlayer/WebRtcPlayerController ' ;
55import { WebGLUtils } from '../Util/WebGLUtils' ;
66import { Controller } from '../Inputs/GamepadTypes' ;
77import { XRGamepadController } from '../Inputs/XRGamepadController' ;
8+ import { XrFrameEvent } from '../Util/EventEmitter'
89
910export class WebXRController {
10- xrSession : XRSession ;
11- xrRefSpace : XRReferenceSpace ;
12- gl : WebGL2RenderingContext ;
11+ private xrSession : XRSession ;
12+ private xrRefSpace : XRReferenceSpace ;
13+ private gl : WebGL2RenderingContext ;
1314
14- positionLocation : number ;
15- texcoordLocation : number ;
16- resolutionLocation : WebGLUniformLocation ;
17- offsetLocation : WebGLUniformLocation ;
15+ private positionLocation : number ;
16+ private texcoordLocation : number ;
17+ private resolutionLocation : WebGLUniformLocation ;
18+ private offsetLocation : WebGLUniformLocation ;
1819
19- positionBuffer : WebGLBuffer ;
20- texcoordBuffer : WebGLBuffer ;
20+ private positionBuffer : WebGLBuffer ;
21+ private texcoordBuffer : WebGLBuffer ;
2122
22- webRtcController : WebRtcPlayerController ;
23- xrGamepadController : XRGamepadController ;
24- xrControllers : Array < Controller > ;
23+ private webRtcController : WebRtcPlayerController ;
24+ private xrGamepadController : XRGamepadController ;
25+ private xrControllers : Array < Controller > ;
26+
27+ onSessionStarted : EventTarget ;
28+ onSessionEnded : EventTarget ;
29+ onFrame : EventTarget ;
2530
2631 constructor ( webRtcPlayerController : WebRtcPlayerController ) {
2732 this . xrSession = null ;
@@ -30,6 +35,9 @@ export class WebXRController {
3035 this . xrGamepadController = new XRGamepadController (
3136 this . webRtcController . streamMessageController
3237 ) ;
38+ this . onSessionEnded = new EventTarget ( ) ;
39+ this . onSessionStarted = new EventTarget ( ) ;
40+ this . onFrame = new EventTarget ( ) ;
3341 }
3442
3543 public xrClicked ( ) {
@@ -47,6 +55,7 @@ export class WebXRController {
4755 onXrSessionEnded ( ) {
4856 Logger . Log ( Logger . GetStackTrace ( ) , 'XR Session ended' ) ;
4957 this . xrSession = null ;
58+ this . onSessionEnded . dispatchEvent ( new Event ( 'xrSessionEnded' ) ) ;
5059 }
5160
5261 onXrSessionStarted ( session : XRSession ) {
@@ -142,6 +151,8 @@ export class WebXRController {
142151 this . onXrFrame ( time , frame )
143152 ) ;
144153 } ) ;
154+
155+ this . onSessionStarted . dispatchEvent ( new Event ( 'xrSessionStarted' ) ) ;
145156 }
146157
147158 onXrFrame ( time : DOMHighResTimeStamp , frame : XRFrame ) {
@@ -194,6 +205,11 @@ export class WebXRController {
194205 ( time : DOMHighResTimeStamp , frame : XRFrame ) =>
195206 this . onXrFrame ( time , frame )
196207 ) ;
208+
209+ this . onFrame . dispatchEvent ( new XrFrameEvent ( {
210+ time,
211+ frame
212+ } ) ) ;
197213 }
198214
199215 private render ( videoElement : HTMLVideoElement ) {
0 commit comments