@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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/Logger.js +23 -9
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/PlayerConnection.js +8 -0
- package/dist/cjs/PlayerConnection.js.map +1 -1
- package/dist/cjs/SFUConnection.js +5 -0
- package/dist/cjs/SFUConnection.js.map +1 -1
- package/dist/cjs/SignallingServer.js +39 -10
- package/dist/cjs/SignallingServer.js.map +1 -1
- package/dist/cjs/StreamerConnection.js +6 -1
- package/dist/cjs/StreamerConnection.js.map +1 -1
- package/dist/cjs/StreamerRegistry.js +6 -3
- package/dist/cjs/StreamerRegistry.js.map +1 -1
- package/dist/cjs/Utils.js +25 -0
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/esm/Logger.js +24 -10
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/PlayerConnection.js +8 -0
- package/dist/esm/PlayerConnection.js.map +1 -1
- package/dist/esm/SFUConnection.js +5 -0
- package/dist/esm/SFUConnection.js.map +1 -1
- package/dist/esm/SignallingServer.js +38 -9
- package/dist/esm/SignallingServer.js.map +1 -1
- package/dist/esm/StreamerConnection.js +6 -1
- package/dist/esm/StreamerConnection.js.map +1 -1
- package/dist/esm/StreamerRegistry.js +6 -3
- package/dist/esm/StreamerRegistry.js.map +1 -1
- package/dist/esm/Utils.js +22 -0
- package/dist/esm/Utils.js.map +1 -1
- package/dist/types/Logger.d.ts +2 -0
- package/dist/types/SignallingServer.d.ts +33 -0
- package/dist/types/Utils.d.ts +14 -0
- package/eslint.config.mjs +1 -1
- package/jest.config.js +14 -0
- package/package.json +17 -14
- package/src/Logger.test.ts +109 -0
- package/src/Logger.ts +30 -9
- package/src/PlayerConnection.ts +12 -2
- package/src/SFUConnection.test.ts +45 -0
- package/src/SFUConnection.ts +5 -0
- package/src/SignallingServer.maxPayload.test.ts +69 -0
- package/src/SignallingServer.test.ts +63 -0
- package/src/SignallingServer.ts +82 -6
- package/src/StreamerConnection.test.ts +48 -0
- package/src/StreamerConnection.ts +7 -1
- package/src/StreamerRegistry.test.ts +27 -0
- package/src/StreamerRegistry.ts +7 -3
- package/src/Utils.test.ts +31 -0
- package/src/Utils.ts +25 -0
- package/tsconfig.jest.json +9 -0
- package/tsconfig.json +1 -0
package/src/StreamerRegistry.ts
CHANGED
|
@@ -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(
|
|
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
|
|
192
|
+
requestedId,
|
|
189
193
|
sanitizedId,
|
|
190
|
-
collided: !!
|
|
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
|
+
}
|