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

Commit

Permalink
Added XR events: xrSessionStarted, xrSessionEnded, xrFrame (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehb authored Feb 25, 2023
1 parent d232421 commit c3f0b83
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 19 deletions.
6 changes: 1 addition & 5 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { AggregatedStats } from '../PeerConnectionController/AggregatedStats';
import { WebRtcPlayerController } from '../WebRtcPlayer/WebRtcPlayerController';
import { Flags, NumericParameters } from '../Config/Config';
import { Logger } from '../Logger/Logger';
import {
InitialSettings,
EncoderSettings,
WebRTCSettings
} from '../DataChannel/InitialSettings';
import { InitialSettings } from '../DataChannel/InitialSettings';
import { OnScreenKeyboard } from '../UI/OnScreenKeyboard';
import {
EventEmitter,
Expand Down
44 changes: 43 additions & 1 deletion Frontend/library/src/Util/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,45 @@ export class SettingsChangedEvent extends Event {
}
}

/**
* Event emitted when an XR Session starts
*/
export class XrSessionStartedEvent extends Event {
readonly type: 'xrSessionStarted';
constructor() {
super('xrSessionStarted');
}
}

/**
* Event emitted when an XR Session ends
*/
export class XrSessionEndedEvent extends Event {
readonly type: 'xrSessionEnded';
constructor() {
super('xrSessionEnded');
}
}

export type XrFrameData = {
/** The frame timestamp */
time: DOMHighResTimeStamp;
/** The XRFrame */
frame: XRFrame;
};

/**
* Event emitted when an XR Frame is complete
*/
export class XrFrameEvent extends Event {
readonly type: 'xrFrame';
readonly data: XrFrameData
constructor(data: XrFrameEvent['data']) {
super('xrFrame');
this.data = data;
}
}

export type PixelStreamingEvent =
| AfkWarningActivateEvent
| AfkWarningUpdateEvent
Expand All @@ -427,7 +466,10 @@ export type PixelStreamingEvent =
| StreamerListMessageEvent
| LatencyTestResultEvent
| InitialSettingsEvent
| SettingsChangedEvent;
| SettingsChangedEvent
| XrSessionStartedEvent
| XrSessionEndedEvent
| XrFrameEvent;

export class EventEmitter extends EventTarget {
/**
Expand Down
42 changes: 29 additions & 13 deletions Frontend/library/src/WebXR/WebXRController.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
// Copyright Epic Games, Inc. All Rights Reserved.

import { Logger } from '../Logger/Logger';
import { WebRtcPlayerController } from '../pixelstreamingfrontend';
import { WebRtcPlayerController } from '../WebRtcPlayer/WebRtcPlayerController';
import { WebGLUtils } from '../Util/WebGLUtils';
import { Controller } from '../Inputs/GamepadTypes';
import { XRGamepadController } from '../Inputs/XRGamepadController';
import { XrFrameEvent } from '../Util/EventEmitter'

export class WebXRController {
xrSession: XRSession;
xrRefSpace: XRReferenceSpace;
gl: WebGL2RenderingContext;
private xrSession: XRSession;
private xrRefSpace: XRReferenceSpace;
private gl: WebGL2RenderingContext;

positionLocation: number;
texcoordLocation: number;
resolutionLocation: WebGLUniformLocation;
offsetLocation: WebGLUniformLocation;
private positionLocation: number;
private texcoordLocation: number;
private resolutionLocation: WebGLUniformLocation;
private offsetLocation: WebGLUniformLocation;

positionBuffer: WebGLBuffer;
texcoordBuffer: WebGLBuffer;
private positionBuffer: WebGLBuffer;
private texcoordBuffer: WebGLBuffer;

webRtcController: WebRtcPlayerController;
xrGamepadController: XRGamepadController;
xrControllers: Array<Controller>;
private webRtcController: WebRtcPlayerController;
private xrGamepadController: XRGamepadController;
private xrControllers: Array<Controller>;

onSessionStarted: EventTarget;
onSessionEnded: EventTarget;
onFrame: EventTarget;

constructor(webRtcPlayerController: WebRtcPlayerController) {
this.xrSession = null;
Expand All @@ -30,6 +35,9 @@ export class WebXRController {
this.xrGamepadController = new XRGamepadController(
this.webRtcController.streamMessageController
);
this.onSessionEnded = new EventTarget();
this.onSessionStarted = new EventTarget();
this.onFrame = new EventTarget();
}

public xrClicked() {
Expand All @@ -47,6 +55,7 @@ export class WebXRController {
onXrSessionEnded() {
Logger.Log(Logger.GetStackTrace(), 'XR Session ended');
this.xrSession = null;
this.onSessionEnded.dispatchEvent(new Event('xrSessionEnded'));
}

onXrSessionStarted(session: XRSession) {
Expand Down Expand Up @@ -142,6 +151,8 @@ export class WebXRController {
this.onXrFrame(time, frame)
);
});

this.onSessionStarted.dispatchEvent(new Event('xrSessionStarted'));
}

onXrFrame(time: DOMHighResTimeStamp, frame: XRFrame) {
Expand Down Expand Up @@ -194,6 +205,11 @@ export class WebXRController {
(time: DOMHighResTimeStamp, frame: XRFrame) =>
this.onXrFrame(time, frame)
);

this.onFrame.dispatchEvent(new XrFrameEvent({
time,
frame
}));
}

private render(videoElement: HTMLVideoElement) {
Expand Down

0 comments on commit c3f0b83

Please sign in to comment.