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

Commit

Permalink
Updating to the new messages handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcottontensor committed Jan 30, 2024
1 parent f8e503c commit 220186d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Frontend/library/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Frontend/library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@epicgames-ps/lib-pixelstreamingfrontend-ue5.5",
"version": "0.0.6",
"version": "0.0.7",
"description": "Frontend library for Unreal Engine 5.5 Pixel Streaming",
"main": "dist/lib-pixelstreamingfrontend.js",
"module": "dist/lib-pixelstreamingfrontend.esm.js",
Expand Down
5 changes: 2 additions & 3 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
DataChannelLatencyTestResultEvent,
PlayerCountEvent
} from '../Util/EventEmitter';
import { MessageReceive } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
import { WebXRController } from '../WebXR/WebXRController';
import { MessageDirection } from '../UeInstanceMessage/StreamMessageController';
import {
Expand Down Expand Up @@ -112,7 +111,7 @@ export class PixelStreaming {
x,
y
);
this._activateOnScreenKeyboard = (command: MessageReceive.MessageOnScreenKeyboard) =>
this._activateOnScreenKeyboard = (command: any) =>
this.onScreenKeyboardHelper.showOnScreenKeyboard(command);

this._webXrController = new WebXRController(this._webRtcController);
Expand Down Expand Up @@ -307,7 +306,7 @@ export class PixelStreaming {
* @param command - the keyboard command
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_activateOnScreenKeyboard(command: MessageReceive.MessageOnScreenKeyboard): void {
_activateOnScreenKeyboard(command: any): void {
throw new Error('Method not implemented.');
}

Expand Down
3 changes: 1 addition & 2 deletions Frontend/library/src/UI/OnScreenKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.

import { UnquantizedDenormalizedUnsignedCoord } from '../Util/CoordinateConverter';
import { MessageReceive } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';

/**
* Class for handling on screen keyboard usage
Expand Down Expand Up @@ -76,7 +75,7 @@ export class OnScreenKeyboard {
* Shows the on screen keyboard
* @param command the command received via the data channel containing keyboard positions
*/
showOnScreenKeyboard(command: MessageReceive.MessageOnScreenKeyboard) {
showOnScreenKeyboard(command: any) {
if (command.showOnScreenKeyboard) {
// Show the 'edit text' button.
this.editTextButton.classList.remove('hiddenState');
Expand Down
4 changes: 2 additions & 2 deletions Frontend/library/src/Util/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { LatencyTestResults } from '../DataChannel/LatencyTestResults';
import { AggregatedStats } from '../PeerConnectionController/AggregatedStats';
import { InitialSettings } from '../pixelstreamingfrontend';
import { MessageReceive } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
import { Messages } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
import { SettingFlag } from '../Config/SettingFlag';
import { SettingNumber } from '../Config/SettingNumber';
import { SettingText } from '../Config/SettingText';
Expand Down Expand Up @@ -345,7 +345,7 @@ export class StreamerListMessageEvent extends Event {
readonly type: 'streamerListMessage';
readonly data: {
/** Streamer list message containing an array of streamer ids */
messageStreamerList: MessageReceive.MessageStreamerList;
messageStreamerList: Messages.streamerList;
/** Auto-selected streamer from the list, or null if unable to auto-select and user should be prompted to select */
autoSelectedStreamerId: string;
/** Wanted streamer id from various configurations. */
Expand Down
71 changes: 37 additions & 34 deletions Frontend/library/src/WebRtcPlayer/WebRtcPlayerController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Epic Games, Inc. All Rights Reserved.

import {
MessageSend,
MessageReceive,
WebSocketTransport,
Logger,
SignallingProtocol,
ITransport
ITransport,
Messages,
MessageHelpers,
BaseMessage
} from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
import { StreamController } from '../VideoPlayer/StreamController';
import { FreezeFrameController } from '../FreezeFrame/FreezeFrameController';
Expand Down Expand Up @@ -191,36 +192,37 @@ export class WebRtcPlayerController {
// set up websocket methods
this.transport = new WebSocketTransport();
this.protocol = new SignallingProtocol(this.transport);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.CONFIG, (msg: MessageReceive.MessageRecv) =>
this.handleOnConfigMessage(msg as MessageReceive.MessageConfig)
this.protocol.messageHandlers.addListener(Messages.config.typeName, (msg: BaseMessage) =>
this.handleOnConfigMessage(msg as Messages.config)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.STREAMER_LIST, (msg: MessageReceive.MessageRecv) =>
this.handleStreamerListMessage(msg as MessageReceive.MessageStreamerList)
this.protocol.messageHandlers.addListener(Messages.streamerList.typeName, (msg: BaseMessage) =>
this.handleStreamerListMessage(msg as Messages.streamerList)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.STREAMER_ID_CHANGED, (msg: MessageReceive.MessageRecv) =>
this.handleStreamerIDChangedMessage(msg as MessageReceive.MessageStreamerIDChanged)
this.protocol.messageHandlers.addListener(Messages.streamerIdChanged.typeName, (msg: BaseMessage) =>
this.handleStreamerIDChangedMessage(msg as Messages.streamerIdChanged)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.PLAYER_COUNT, (msg: MessageReceive.MessageRecv) => {
const playerCountMessage = msg as MessageReceive.MessagePlayerCount;
this.protocol.messageHandlers.addListener(Messages.playerCount.typeName, (msg: BaseMessage) => {
const playerCountMessage = msg as Messages.playerCount;
this.pixelStreaming._onPlayerCount(playerCountMessage.count);
});
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.ANSWER, (msg: MessageReceive.MessageRecv) =>
this.handleWebRtcAnswer(msg as MessageReceive.MessageAnswer)
this.protocol.messageHandlers.addListener(Messages.answer.typeName, (msg: BaseMessage) =>
this.handleWebRtcAnswer(msg as Messages.answer)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.OFFER, (msg: MessageReceive.MessageRecv) =>
this.handleWebRtcOffer(msg as MessageReceive.MessageOffer)
this.protocol.messageHandlers.addListener(Messages.offer.typeName, (msg: BaseMessage) =>
this.handleWebRtcOffer(msg as Messages.offer)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.PEER_DATA_CHANNELS, (msg: MessageReceive.MessageRecv) =>
this.handleWebRtcSFUPeerDatachannels(msg as MessageReceive.MessagePeerDataChannels)
this.protocol.messageHandlers.addListener(Messages.streamerDataChannels.typeName, (msg: BaseMessage) =>
this.handleWebRtcSFUPeerDatachannels(msg as Messages.streamerDataChannels)
);
this.protocol.messageHandlers.addListener(MessageReceive.MessageRecvTypes.ICE_CANDIDATE, (msg: MessageReceive.MessageRecv) => {
const iceCandidateMessage = msg as MessageReceive.MessageIceCandidate;
this.protocol.messageHandlers.addListener(Messages.iceCandidate.typeName, (msg: BaseMessage) => {
const iceCandidateMessage = msg as Messages.iceCandidate;
this.handleIceCandidate(iceCandidateMessage.candidate);
});
this.protocol.transportEvents.addListener('open', () => {
const BrowserSendsOffer = this.config.isFlagEnabled(Flags.BrowserSendOffer);
if (!BrowserSendsOffer) {
this.protocol.sendMessage(new MessageSend.MessageListStreamers());
const message = MessageHelpers.createMessage(Messages.listStreamers);
this.protocol.sendMessage(message);
}
});
this.protocol.transportEvents.addListener('error', () => {
Expand Down Expand Up @@ -305,7 +307,8 @@ export class WebRtcPlayerController {
this.preferredCodec
);
this.subscribedStream = streamerid;
this.protocol.sendMessage(new MessageSend.MessageSubscribe(streamerid));
const message = MessageHelpers.createMessage(Messages.subscribe, { streamerId: streamerid });
this.protocol.sendMessage(message);
}
);

Expand Down Expand Up @@ -789,7 +792,7 @@ export class WebRtcPlayerController {
'Data Channel Command: ' + commandAsString,
6
);
const command: MessageReceive.MessageOnScreenKeyboard = JSON.parse(commandAsString);
const command = JSON.parse(commandAsString);
if (command.command === 'onScreenKeyboard') {
this.pixelStreaming._activateOnScreenKeyboard(command);
}
Expand Down Expand Up @@ -1306,7 +1309,7 @@ export class WebRtcPlayerController {
* Handles when a Config Message is received contains the Peer Connection Options required (STUN and TURN Server Info)
* @param messageConfig - Config Message received from the signaling server
*/
handleOnConfigMessage(messageConfig: MessageReceive.MessageConfig) {
handleOnConfigMessage(messageConfig: Messages.config) {
this.resizePlayerStyle();

// Tell the WebRtcController to start a session with the peer options sent from the signaling server
Expand All @@ -1316,7 +1319,7 @@ export class WebRtcPlayerController {
/**
* Handles when the signalling server gives us the list of streamer ids.
*/
handleStreamerListMessage(messageStreamerList: MessageReceive.MessageStreamerList) {
handleStreamerListMessage(messageStreamerList: Messages.streamerList) {
Logger.Log(
Logger.GetStackTrace(),
`Got streamer list ${messageStreamerList.ids}`,
Expand Down Expand Up @@ -1404,7 +1407,7 @@ export class WebRtcPlayerController {
);
}

handleStreamerIDChangedMessage(streamerIDChangedMessage: MessageReceive.MessageStreamerIDChanged) {
handleStreamerIDChangedMessage(streamerIDChangedMessage: Messages.streamerIdChanged) {
const newID = streamerIDChangedMessage.newID;

// need to edit the selected streamer in the settings list
Expand Down Expand Up @@ -1447,7 +1450,7 @@ export class WebRtcPlayerController {
* Handle the RTC Answer from the signaling server
* @param Answer - Answer SDP from the peer.
*/
handleWebRtcAnswer(Answer: MessageReceive.MessageAnswer) {
handleWebRtcAnswer(Answer: Messages.answer) {
Logger.Log(Logger.GetStackTrace(), `Got answer sdp ${Answer.sdp}`, 6);

const sdpAnswer: RTCSessionDescriptionInit = {
Expand All @@ -1463,7 +1466,7 @@ export class WebRtcPlayerController {
* Handle the RTC offer from a WebRTC peer (received through the signalling server).
* @param Offer - Offer SDP from the peer.
*/
handleWebRtcOffer(Offer: MessageReceive.MessageOffer) {
handleWebRtcOffer(Offer: Messages.offer) {
Logger.Log(Logger.GetStackTrace(), `Got offer sdp ${Offer.sdp}`, 6);

this.isUsingSFU = Offer.sfu ? Offer.sfu : false;
Expand All @@ -1485,9 +1488,7 @@ export class WebRtcPlayerController {
* Handle when the SFU provides the peer with its data channels
* @param DataChannels - The message from the SFU containing the data channels ids
*/
handleWebRtcSFUPeerDatachannels(
DataChannels: MessageReceive.MessagePeerDataChannels
) {
handleWebRtcSFUPeerDatachannels(DataChannels: Messages.streamerDataChannels) {
const SendOptions: RTCDataChannelInit = {
ordered: true,
negotiated: true,
Expand Down Expand Up @@ -1603,12 +1604,13 @@ export class WebRtcPlayerController {
6
);

const extraParams: MessageSend.ExtraOfferParameters = {
const extraParams = {
sdp: offer.sdp,
minBitrateBps: 1000 * this.config.getNumericSettingValue(NumericParameters.WebRTCMinBitrate),
maxBitrateBps: 1000 * this.config.getNumericSettingValue(NumericParameters.WebRTCMaxBitrate)
};

this.protocol.sendWebRtcOffer(offer, extraParams);
this.protocol.sendWebRtcOffer(MessageHelpers.createMessage(Messages.offer, extraParams));
}

/**
Expand All @@ -1622,12 +1624,13 @@ export class WebRtcPlayerController {
6
);

const extraParams: MessageSend.ExtraAnswerParameters = {
const extraParams = {
sdp: answer.sdp,
minBitrateBps: 1000 * this.config.getNumericSettingValue(NumericParameters.WebRTCMinBitrate),
maxBitrateBps: 1000 * this.config.getNumericSettingValue(NumericParameters.WebRTCMaxBitrate)
};

this.protocol.sendWebRtcAnswer(answer, extraParams);
this.protocol.sendWebRtcOffer(MessageHelpers.createMessage(Messages.answer, extraParams));

This comment has been minimized.

Copy link
@lukehb

lukehb Jan 31, 2024

Contributor

Removed sendWebRTCAnswer in favour of sendWebRTCOffer is that correct?

This comment has been minimized.

Copy link
@mcottontensor

mcottontensor Jan 31, 2024

Author Contributor

I'm surprised this was working at all.

Ah it was because of the way we merge the "extra parameters" with a fresh message.. essentially if you pass in a full message as an "extra parameter" itll merge it with a fresh made message leaving you with essentially the message you already made. Maybe neat? Maybe terrible? I don't really know.


if (this.isUsingSFU) {
this.protocol.sendWebRtcDatachannelRequest();
Expand Down

0 comments on commit 220186d

Please sign in to comment.