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

Commit

Permalink
Show player count in stats panel (#303)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6bdbf50)
  • Loading branch information
Belchy06 committed Jul 18, 2023
1 parent 4b5660c commit 310b4ff
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
WebRtcConnectingEvent,
WebRtcDisconnectedEvent,
WebRtcFailedEvent,
WebRtcSdpEvent
WebRtcSdpEvent,
PlayerCountEvent
} from '../Util/EventEmitter';
import { MessageOnScreenKeyboard } from '../WebSockets/MessageReceive';
import { WebXRController } from '../WebXR/WebXRController';
Expand Down Expand Up @@ -561,6 +562,12 @@ export class PixelStreaming {
);
}

_onPlayerCount(playerCount: number) {
this._eventEmitter.dispatchEvent(
new PlayerCountEvent({ count: playerCount })
);
}

/**
* Request a connection latency test.
* NOTE: There are plans to refactor all request* functions. Expect changes if you use this!
Expand Down
18 changes: 17 additions & 1 deletion Frontend/library/src/Util/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,21 @@ export class XrFrameEvent extends Event {
}
}

/**
* An event that is emitted when receiving a player count from the signalling server
*/
export class PlayerCountEvent extends Event {
readonly type: 'playerCount';
readonly data: {
/** count object */
count: number
};
constructor(data: PlayerCountEvent['data']) {
super('playerCount');
this.data = data;
}
}

export type PixelStreamingEvent =
| AfkWarningActivateEvent
| AfkWarningUpdateEvent
Expand Down Expand Up @@ -502,7 +517,8 @@ export type PixelStreamingEvent =
| SettingsChangedEvent
| XrSessionStartedEvent
| XrSessionEndedEvent
| XrFrameEvent;
| XrFrameEvent
| PlayerCountEvent;

export class EventEmitter extends EventTarget {
/**
Expand Down
3 changes: 3 additions & 0 deletions Frontend/library/src/WebRtcPlayer/WebRtcPlayerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export class WebRtcPlayerController {
);
this.setVideoEncoderAvgQP(0);
};
this.webSocketController.onPlayerCount = (playerCount: MessageReceive.MessagePlayerCount) => {
this.pixelStreaming._onPlayerCount(playerCount.count);
};
this.webSocketController.onOpen.addEventListener('open', () => {
const BrowserSendsOffer = this.config.isFlagEnabled(
Flags.BrowserSendOffer
Expand Down
1 change: 1 addition & 0 deletions Frontend/library/src/WebSockets/SignallingProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class SignallingProtocol {
'Player Count: ' + playerCount.count,
6
);
websocketController.onPlayerCount(playerCount)
}
);

Expand Down
11 changes: 8 additions & 3 deletions Frontend/library/src/WebSockets/WebSocketController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ export class WebSocketController {
* @param messageDataChannels - The data channels details
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
onWebRtcPeerDataChannels(
messageDataChannels: MessageReceive.MessagePeerDataChannels
) {}
onWebRtcPeerDataChannels(messageDataChannels: MessageReceive.MessagePeerDataChannels) {}

/**
* Event is fired when the websocket receives the an updated player count from cirrus
* @param MessagePlayerCount - The new player count
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
onPlayerCount(playerCount: MessageReceive.MessagePlayerCount) {}
}
9 changes: 9 additions & 0 deletions Frontend/ui-library/src/Application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ export class Application {
'settingsChanged',
(event) => this.configUI.onSettingsChanged(event)
);
this.stream.addEventListener(
'playerCount',
({ data: { count }}) =>
this.onPlayerCount(count)
);
}

/**
Expand Down Expand Up @@ -662,6 +667,10 @@ export class Application {
this.statsPanel.latencyTest.handleTestResult(latencyTimings);
}

onPlayerCount(playerCount: number) {
this.statsPanel.handlePlayerCount(playerCount);
}

handleStreamerListMessage(messageStreamingList: MessageStreamerList, autoSelectedStreamerId: string | null) {
if (autoSelectedStreamerId === null) {
if(messageStreamingList.ids.length === 0) {
Expand Down
8 changes: 8 additions & 0 deletions Frontend/ui-library/src/UI/StatsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export class StatsPanel {
}
}

public handlePlayerCount(playerCount: number) {
this.addOrUpdateStat(
'PlayerCountStat',
'Players',
playerCount.toString()
);
}

/**
* Handle stats coming in from browser/UE
* @param stats the stats structure
Expand Down

0 comments on commit 310b4ff

Please sign in to comment.