@epicgames-ps/lib-pixelstreamingsignalling-ue5.8 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/Logger.js +23 -9
  3. package/dist/cjs/Logger.js.map +1 -1
  4. package/dist/cjs/PlayerConnection.js +8 -0
  5. package/dist/cjs/PlayerConnection.js.map +1 -1
  6. package/dist/cjs/SFUConnection.js +5 -0
  7. package/dist/cjs/SFUConnection.js.map +1 -1
  8. package/dist/cjs/SignallingServer.js +39 -10
  9. package/dist/cjs/SignallingServer.js.map +1 -1
  10. package/dist/cjs/StreamerConnection.js +6 -1
  11. package/dist/cjs/StreamerConnection.js.map +1 -1
  12. package/dist/cjs/StreamerRegistry.js +6 -3
  13. package/dist/cjs/StreamerRegistry.js.map +1 -1
  14. package/dist/cjs/Utils.js +25 -0
  15. package/dist/cjs/Utils.js.map +1 -1
  16. package/dist/esm/Logger.js +24 -10
  17. package/dist/esm/Logger.js.map +1 -1
  18. package/dist/esm/PlayerConnection.js +8 -0
  19. package/dist/esm/PlayerConnection.js.map +1 -1
  20. package/dist/esm/SFUConnection.js +5 -0
  21. package/dist/esm/SFUConnection.js.map +1 -1
  22. package/dist/esm/SignallingServer.js +38 -9
  23. package/dist/esm/SignallingServer.js.map +1 -1
  24. package/dist/esm/StreamerConnection.js +6 -1
  25. package/dist/esm/StreamerConnection.js.map +1 -1
  26. package/dist/esm/StreamerRegistry.js +6 -3
  27. package/dist/esm/StreamerRegistry.js.map +1 -1
  28. package/dist/esm/Utils.js +22 -0
  29. package/dist/esm/Utils.js.map +1 -1
  30. package/dist/types/Logger.d.ts +2 -0
  31. package/dist/types/SignallingServer.d.ts +33 -0
  32. package/dist/types/Utils.d.ts +14 -0
  33. package/eslint.config.mjs +1 -1
  34. package/jest.config.js +14 -0
  35. package/package.json +17 -14
  36. package/src/Logger.test.ts +109 -0
  37. package/src/Logger.ts +30 -9
  38. package/src/PlayerConnection.ts +12 -2
  39. package/src/SFUConnection.test.ts +45 -0
  40. package/src/SFUConnection.ts +5 -0
  41. package/src/SignallingServer.maxPayload.test.ts +69 -0
  42. package/src/SignallingServer.test.ts +63 -0
  43. package/src/SignallingServer.ts +82 -6
  44. package/src/StreamerConnection.test.ts +48 -0
  45. package/src/StreamerConnection.ts +7 -1
  46. package/src/StreamerRegistry.test.ts +27 -0
  47. package/src/StreamerRegistry.ts +7 -3
  48. package/src/Utils.test.ts +31 -0
  49. package/src/Utils.ts +25 -0
  50. package/tsconfig.jest.json +9 -0
  51. package/tsconfig.json +1 -0
@@ -176,8 +176,12 @@ export class StreamerRegistry extends EventEmitter {
176
176
  private onEndpointId(streamer: IStreamer, message: Messages.endpointId): void {
177
177
  const oldId = streamer.streamerId;
178
178
 
179
+ // The id arrives as any JSON value. A non-string one is treated as no id, because sanitizing it
180
+ // would store a value that later lookups cannot handle.
181
+ const requestedId = typeof message.id === 'string' ? message.id : '';
182
+
179
183
  // id might conflict or be invalid so here we sanitize it
180
- const sanitizedId = this.sanitizeStreamerId(message.id);
184
+ const sanitizedId = this.sanitizeStreamerId(requestedId);
181
185
 
182
186
  let committedId: string | null = sanitizedId;
183
187
  if (this.authorizeStreamerId) {
@@ -185,9 +189,9 @@ export class StreamerRegistry extends EventEmitter {
185
189
  // reject the registration entirely. This is where anti-squatting policy lives.
186
190
  committedId = this.authorizeStreamerId({
187
191
  streamer,
188
- requestedId: message.id,
192
+ requestedId,
189
193
  sanitizedId,
190
- collided: !!message.id && sanitizedId !== message.id
194
+ collided: !!requestedId && sanitizedId !== requestedId
191
195
  });
192
196
 
193
197
  if (committedId === null) {
@@ -0,0 +1,31 @@
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+ import { MAX_LOGGED_LENGTH, limitLogText, limitLoggedMessage } from './Utils';
3
+
4
+ describe('limitLogText', () => {
5
+ it('returns text up to the limit unchanged', () => {
6
+ const text = 'a'.repeat(MAX_LOGGED_LENGTH);
7
+ expect(limitLogText(text)).toBe(text);
8
+ });
9
+
10
+ it('cuts longer text to the limit and gives its full length', () => {
11
+ const text = 'a'.repeat(MAX_LOGGED_LENGTH + 1);
12
+ expect(limitLogText(text)).toBe(
13
+ `${'a'.repeat(MAX_LOGGED_LENGTH)}... (${MAX_LOGGED_LENGTH + 1} characters)`
14
+ );
15
+ });
16
+ });
17
+
18
+ describe('limitLoggedMessage', () => {
19
+ it('returns a message whose JSON fits as the message itself', () => {
20
+ const message = { type: 'ping', time: 1 };
21
+ expect(limitLoggedMessage(message)).toBe(message);
22
+ });
23
+
24
+ it('returns a message whose JSON is too long as its JSON text, cut', () => {
25
+ const message = { type: 'ping', pad: 'a'.repeat(MAX_LOGGED_LENGTH) };
26
+ const json = JSON.stringify(message);
27
+ expect(limitLoggedMessage(message)).toBe(
28
+ `${json.slice(0, MAX_LOGGED_LENGTH)}... (${json.length} characters)`
29
+ );
30
+ });
31
+ });
package/src/Utils.ts CHANGED
@@ -14,3 +14,28 @@ export function stringify(obj: any): string {
14
14
  export function beautify(obj: any): string {
15
15
  return jsonc.stringify(obj, undefined, '\t');
16
16
  }
17
+
18
+ /**
19
+ * The longest text, or protocol message as JSON, that the logger writes whole. A client chooses the
20
+ * size of what it sends, so anything longer is cut rather than written to the log in full.
21
+ */
22
+ export const MAX_LOGGED_LENGTH = 16 * 1024;
23
+
24
+ /**
25
+ * Returns the text, or if it is longer than MAX_LOGGED_LENGTH, its start and its full length.
26
+ */
27
+ export function limitLogText(text: string): string {
28
+ if (text.length <= MAX_LOGGED_LENGTH) {
29
+ return text;
30
+ }
31
+ return `${text.slice(0, MAX_LOGGED_LENGTH)}... (${text.length} characters)`;
32
+ }
33
+
34
+ /**
35
+ * Returns a protocol message as the log file should hold it: the message itself while its JSON fits in
36
+ * MAX_LOGGED_LENGTH, otherwise its JSON text cut by limitLogText.
37
+ */
38
+ export function limitLoggedMessage(message: object): object | string {
39
+ const text = JSON.stringify(message);
40
+ return text.length <= MAX_LOGGED_LENGTH ? message : limitLogText(text);
41
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["./src/**/*.ts"],
4
+ "exclude": [],
5
+ "compilerOptions": {
6
+ "module": "commonjs",
7
+ "moduleResolution": "node"
8
+ }
9
+ }
package/tsconfig.json CHANGED
@@ -16,6 +16,7 @@
16
16
  "moduleResolution": "bundler" // helps IDEs
17
17
  },
18
18
  "include": ["./src/*.ts"],
19
+ "exclude": ["./src/*.test.ts"],
19
20
  "typedocOptions": {
20
21
  "entryPoints": ["src/**/*.ts"],
21
22
  "out": "docs",