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

Commit

Permalink
Adding a broadcast message event for listening to all messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mcottontensor committed Jan 31, 2024
1 parent e46bb15 commit 8d1c80f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@epicgames-ps/lib-pixelstreamingcommon-ue5.5",
"version": "0.0.7",
"version": "0.0.8",
"description": "Common utilities library for Unreal Engine 5.5 Pixel Streaming",
"main": "build/commonjs/pixelstreamingcommon.js",
"module": "build/es2015/pixelstreamingcommon.js",
Expand Down
8 changes: 5 additions & 3 deletions Common/src/WebSockets/SignallingProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class SignallingProtocol {
this.transportEvents = new EventEmitter();
this.messageHandlers = new EventEmitter();

transport.events.addListener('open', () => this.transportEvents.emit('open'));
transport.events.addListener('error', () => this.transportEvents.emit('error'));
transport.events.addListener('open', (event: Event) => this.transportEvents.emit('open', event));
transport.events.addListener('error', (event: Event) => this.transportEvents.emit('error', event));
transport.events.addListener('close', (event: CloseEvent) => this.transportEvents.emit('close', event));

transport.onMessage = (msg: BaseMessage) => {
Expand All @@ -38,8 +38,10 @@ export class SignallingProtocol {
const pongMessage = MessageHelpers.createMessage(Messages.pong, { time: new Date().getTime() });
transport.sendMessage(pongMessage);
}

// call the handlers
this.messageHandlers.emit(msg.type, msg);
this.messageHandlers.emit(msg.type, msg); // emit this for listeners listening for specific messages
this.transportEvents.emit('message', msg); // emit this for listeners listening to any message

This comment has been minimized.

Copy link
@lukehb

lukehb Jan 31, 2024

Contributor

This probably needs to be documented that this is how downstream users can now use this (I assume that is what this is for).

Where to document it? Perhaps we need a small programming examples folder in our repo root or, in this case, in /common?

This comment has been minimized.

Copy link
@lukehb

lukehb Jan 31, 2024

Contributor

Or better yet, a test that demonstrates it!

};
}

Expand Down

0 comments on commit 8d1c80f

Please sign in to comment.