Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed NodeJS event emitter in common library. #330

Merged
merged 29 commits into from
Nov 28, 2024
Merged

Removed NodeJS event emitter in common library. #330

merged 29 commits into from
Nov 28, 2024

Conversation

lukehb
Copy link
Contributor

@lukehb lukehb commented Nov 26, 2024

Relevant components:

  • Signalling server
  • Common library
  • Frontend library
  • Frontend UI library

Problem statement:

The Common library contained a NodeJS type, EventEmitter this was causing it to fail when used in the browser. This was not a problem previously when we bundled at the library build step, but since #324 have been a few dependencies that do not work well in the browser without bundling.

This issue was reported in: #328 and impacts the latest version of UE 5.5 frontend library.

Solution

This PR solves the issue by making a browser compatible EventEmitter type using EventTarget under the hood.

Documentation

N/A

Test Plan and Compatibility

I have tested by:

  • Running the unit tests
  • Running the frontend tests
  • Running with an actual UE instance
  • Running the signalling server

@@ -7,7 +7,7 @@
"module": "build/pixelstreamingjsstreamer.js",
"scripts": {
"develop": "webpack-dev-server --mode development",
"build": "tsc --project tsconfig.json && webpack --mode production",
"build": "tsc --project tsconfig.json && webpack --mode development",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't really make sense to minify/obscure this code as it is only used in dev.

@@ -45,7 +45,7 @@ module.exports = {
},
},
static: path.join(__dirname, 'dist'),
compress: true,
compress: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't make sense to compress this code as we only use it for testing/dev.

@@ -581,7 +581,7 @@ export type PixelStreamingEvent =
| PlayerCountEvent
| WebRtcTCPRelayDetectedEvent;

export class EventEmitter extends EventTarget {
export class PixelStreamingEventEmitter extends EventTarget {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already had a class called EventEmitter, so I renamed it here. This seemed like the lesser impactful rename as opposed to renaming the one in common.

@@ -4,13 +4,14 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "npx playwright test"
"test": "npx playwright test",
"build": ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may notice a few empty build scripts in this commit.

Those were added to enable running npm run build in the root of the repo and building all workspaces - handy.

@@ -1,6 +1,7 @@
# Use the current Long Term Support (LTS) version of Node.js
FROM node:lts
# Copy the signalling server and frontend source code from the build context
COPY package.json package.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed in the Dockerfile to make it use the new NPM workspaces way of doing things.

"private": true,
"scripts": {
"build": "npm run build --ws"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lets us run npm run build in the repo root and build everything.

this._callback = callback;
}

handleEvent(_evt: Event): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the event not be passed to the callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still questioning this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing that Event to the downstream listener would actually introduce different behaviour than what node js was doing with its event emitter

It has no meaningful information attached to it and is really an internal implementation detail, exposing it to the listener would be a leaky abstraction considering the point was the make something that looks and smells likes NodeJS event emitter but actually uses EventTarget under the hood.

@lukehb lukehb merged commit afbeb07 into UE5.5 Nov 28, 2024
13 checks passed
@lukehb lukehb deleted the EventEmitter branch November 28, 2024 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants