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

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 (112) hide show
  1. package/.lintstagedrc.mjs +7 -0
  2. package/.prettierignore +0 -0
  3. package/CHANGELOG.md +21 -0
  4. package/README.md +32 -0
  5. package/dist/cjs/Logger.js +148 -0
  6. package/dist/cjs/Logger.js.map +1 -0
  7. package/dist/cjs/LoggingUtils.js +64 -0
  8. package/dist/cjs/LoggingUtils.js.map +1 -0
  9. package/dist/cjs/PlayerConnection.js +220 -0
  10. package/dist/cjs/PlayerConnection.js.map +1 -0
  11. package/dist/cjs/PlayerRegistry.js +77 -0
  12. package/dist/cjs/PlayerRegistry.js.map +1 -0
  13. package/dist/cjs/SFUConnection.js +264 -0
  14. package/dist/cjs/SFUConnection.js.map +1 -0
  15. package/dist/cjs/SignallingServer.js +149 -0
  16. package/dist/cjs/SignallingServer.js.map +1 -0
  17. package/dist/cjs/StreamerConnection.js +172 -0
  18. package/dist/cjs/StreamerConnection.js.map +1 -0
  19. package/dist/cjs/StreamerRegistry.js +149 -0
  20. package/dist/cjs/StreamerRegistry.js.map +1 -0
  21. package/dist/cjs/Utils.js +19 -0
  22. package/dist/cjs/Utils.js.map +1 -0
  23. package/dist/cjs/WebServer.js +124 -0
  24. package/dist/cjs/WebServer.js.map +1 -0
  25. package/dist/cjs/pixelstreamingsignalling.js +28 -0
  26. package/dist/cjs/pixelstreamingsignalling.js.map +1 -0
  27. package/dist/esm/Logger.js +141 -0
  28. package/dist/esm/Logger.js.map +1 -0
  29. package/dist/esm/LoggingUtils.js +58 -0
  30. package/dist/esm/LoggingUtils.js.map +1 -0
  31. package/dist/esm/PlayerConnection.js +183 -0
  32. package/dist/esm/PlayerConnection.js.map +1 -0
  33. package/dist/esm/PlayerRegistry.js +73 -0
  34. package/dist/esm/PlayerRegistry.js.map +1 -0
  35. package/dist/esm/SFUConnection.js +227 -0
  36. package/dist/esm/SFUConnection.js.map +1 -0
  37. package/dist/esm/SignallingServer.js +112 -0
  38. package/dist/esm/SignallingServer.js.map +1 -0
  39. package/dist/esm/StreamerConnection.js +135 -0
  40. package/dist/esm/StreamerConnection.js.map +1 -0
  41. package/dist/esm/StreamerRegistry.js +145 -0
  42. package/dist/esm/StreamerRegistry.js.map +1 -0
  43. package/dist/esm/Utils.js +15 -0
  44. package/dist/esm/Utils.js.map +1 -0
  45. package/dist/esm/WebServer.js +117 -0
  46. package/dist/esm/WebServer.js.map +1 -0
  47. package/dist/esm/pixelstreamingsignalling.js +12 -0
  48. package/dist/esm/pixelstreamingsignalling.js.map +1 -0
  49. package/dist/types/Logger.d.ts +20 -0
  50. package/dist/types/LoggingUtils.d.ts +44 -0
  51. package/dist/types/PlayerConnection.d.ts +66 -0
  52. package/dist/types/PlayerRegistry.d.ts +66 -0
  53. package/dist/types/SFUConnection.d.ts +85 -0
  54. package/dist/types/SignallingServer.d.ts +48 -0
  55. package/dist/types/StreamerConnection.d.ts +61 -0
  56. package/dist/types/StreamerRegistry.d.ts +96 -0
  57. package/dist/types/Utils.d.ts +8 -0
  58. package/dist/types/WebServer.d.ts +42 -0
  59. package/dist/types/pixelstreamingsignalling.d.ts +9 -0
  60. package/docs/Logger/README.md +19 -0
  61. package/docs/Logger/functions/InitLogging.md +26 -0
  62. package/docs/Logger/interfaces/IConfig.md +41 -0
  63. package/docs/Logger/variables/Logger.md +15 -0
  64. package/docs/LoggingUtils/README.md +19 -0
  65. package/docs/LoggingUtils/functions/createHandlerListener.md +42 -0
  66. package/docs/LoggingUtils/functions/logForward.md +36 -0
  67. package/docs/LoggingUtils/functions/logIncoming.md +30 -0
  68. package/docs/LoggingUtils/functions/logOutgoing.md +30 -0
  69. package/docs/LoggingUtils/interfaces/IMessageLogger.md +29 -0
  70. package/docs/LoggingUtils/interfaces/IProtoLogObj.md +57 -0
  71. package/docs/PlayerConnection/README.md +11 -0
  72. package/docs/PlayerConnection/classes/PlayerConnection.md +177 -0
  73. package/docs/PlayerRegistry/README.md +16 -0
  74. package/docs/PlayerRegistry/classes/PlayerRegistry.md +423 -0
  75. package/docs/PlayerRegistry/interfaces/IPlayer.md +86 -0
  76. package/docs/PlayerRegistry/interfaces/IPlayerInfo.md +43 -0
  77. package/docs/README.md +19 -0
  78. package/docs/SFUConnection/README.md +11 -0
  79. package/docs/SFUConnection/classes/SFUConnection.md +554 -0
  80. package/docs/SignallingServer/README.md +19 -0
  81. package/docs/SignallingServer/classes/SignallingServer.md +76 -0
  82. package/docs/SignallingServer/interfaces/IServerConfig.md +92 -0
  83. package/docs/SignallingServer/type-aliases/ProtocolConfig.md +15 -0
  84. package/docs/StreamerConnection/README.md +11 -0
  85. package/docs/StreamerConnection/classes/StreamerConnection.md +507 -0
  86. package/docs/StreamerRegistry/README.md +16 -0
  87. package/docs/StreamerRegistry/classes/StreamerRegistry.md +431 -0
  88. package/docs/StreamerRegistry/interfaces/IStreamer.md +375 -0
  89. package/docs/StreamerRegistry/interfaces/IStreamerInfo.md +51 -0
  90. package/docs/Utils/README.md +12 -0
  91. package/docs/Utils/functions/beautify.md +23 -0
  92. package/docs/Utils/functions/stringify.md +23 -0
  93. package/docs/WebServer/README.md +15 -0
  94. package/docs/WebServer/classes/WebServer.md +50 -0
  95. package/docs/WebServer/interfaces/IWebServerConfig.md +76 -0
  96. package/docs/pixelstreamingsignalling/README.md +145 -0
  97. package/eslint.config.mjs +39 -0
  98. package/package.json +58 -0
  99. package/src/Logger.ts +189 -0
  100. package/src/LoggingUtils.ts +80 -0
  101. package/src/PlayerConnection.ts +257 -0
  102. package/src/PlayerRegistry.ts +116 -0
  103. package/src/SFUConnection.ts +329 -0
  104. package/src/SignallingServer.ts +214 -0
  105. package/src/StreamerConnection.ts +194 -0
  106. package/src/StreamerRegistry.ts +252 -0
  107. package/src/Utils.ts +16 -0
  108. package/src/WebServer.ts +213 -0
  109. package/src/pixelstreamingsignalling.ts +11 -0
  110. package/tsconfig.cjs.json +8 -0
  111. package/tsconfig.esm.json +8 -0
  112. package/tsconfig.json +29 -0
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamerRegistry = void 0;
4
+ // Copyright Epic Games, Inc. All Rights Reserved.
5
+ const lib_pixelstreamingcommon_ue5_8_1 = require("@epicgames-ps/lib-pixelstreamingcommon-ue5.8");
6
+ const Logger_1 = require("./Logger");
7
+ /**
8
+ * Handles all the streamer connections of a signalling server and
9
+ * can be used to lookup connections by id etc.
10
+ * Fires events when streamers are added or removed.
11
+ * Events:
12
+ * 'added': (playerId: string) Player was added.
13
+ * 'removed': (playerId: string) Player was removed.
14
+ */
15
+ class StreamerRegistry extends lib_pixelstreamingcommon_ue5_8_1.EventEmitter {
16
+ constructor(authorizeStreamerId) {
17
+ super();
18
+ this.defaultStreamerIdPrefix = 'UnknownStreamer';
19
+ this.streamers = [];
20
+ this.authorizeStreamerId = authorizeStreamerId;
21
+ }
22
+ /**
23
+ * Adds a streamer to the registry. If the streamer already has an id
24
+ * it will be sanitized (checked against existing ids and altered if
25
+ * there are collisions), or if it has no id it will be assigned a
26
+ * default unique id.
27
+ * @returns True if the add was successful.
28
+ */
29
+ add(streamer) {
30
+ streamer.streamerId = this.sanitizeStreamerId(streamer.streamerId);
31
+ if (this.find(streamer.streamerId)) {
32
+ Logger_1.Logger.error(`StreamerRegistry: Tried to register streamer ${streamer.streamerId} but that id already exists.`);
33
+ return false;
34
+ }
35
+ this.streamers.push(streamer);
36
+ // request that the new streamer id itself.
37
+ streamer.protocol.on(lib_pixelstreamingcommon_ue5_8_1.Messages.endpointId.typeName, this.onEndpointId.bind(this, streamer));
38
+ streamer.sendMessage(lib_pixelstreamingcommon_ue5_8_1.MessageHelpers.createMessage(lib_pixelstreamingcommon_ue5_8_1.Messages.identify));
39
+ this.emit('added', streamer.streamerId);
40
+ return true;
41
+ }
42
+ /**
43
+ * Removes a streamer from the registry. If the streamer isn't found
44
+ * it does nothing.
45
+ * @returns True if the streamer was removed.
46
+ */
47
+ remove(streamer) {
48
+ const index = this.streamers.indexOf(streamer);
49
+ if (index === -1) {
50
+ Logger_1.Logger.debug(`StreamerRegistry: Tried to remove streamer ${streamer.streamerId} but it doesn't exist`);
51
+ return false;
52
+ }
53
+ this.streamers.splice(index, 1);
54
+ this.emit('removed', streamer.streamerId);
55
+ return true;
56
+ }
57
+ /**
58
+ * Attempts to find the given streamer id in the registry.
59
+ */
60
+ find(streamerId) {
61
+ return this.streamers.find((streamer) => streamer.streamerId === streamerId);
62
+ }
63
+ /**
64
+ * Used by players who haven't subscribed but try to send a message.
65
+ * This is to cover legacy connections that do not know how to subscribe.
66
+ * The player will be assigned the first streamer in the list.
67
+ * @returns The first streamerId in the registry or null if there are none.
68
+ */
69
+ getFirstStreamerId() {
70
+ if (this.empty()) {
71
+ return null;
72
+ }
73
+ return this.streamers[0].streamerId;
74
+ }
75
+ /**
76
+ * Returns true when the registry is empty.
77
+ */
78
+ empty() {
79
+ return this.streamers.length === 0;
80
+ }
81
+ /**
82
+ * Returns the total number of connected streamers.
83
+ */
84
+ count() {
85
+ return this.streamers.length;
86
+ }
87
+ onEndpointId(streamer, message) {
88
+ const oldId = streamer.streamerId;
89
+ // id might conflict or be invalid so here we sanitize it
90
+ const sanitizedId = this.sanitizeStreamerId(message.id);
91
+ let committedId = sanitizedId;
92
+ if (this.authorizeStreamerId) {
93
+ // Let the consumer accept the default id, override it (e.g. namespace per tenant), or
94
+ // reject the registration entirely. This is where anti-squatting policy lives.
95
+ committedId = this.authorizeStreamerId({
96
+ streamer,
97
+ requestedId: message.id,
98
+ sanitizedId,
99
+ collided: !!message.id && sanitizedId !== message.id
100
+ });
101
+ if (committedId === null) {
102
+ Logger_1.Logger.warn(`StreamerRegistry: streamer id '${message.id}' (was ${oldId}) rejected by authorizer. Disconnecting.`);
103
+ this.remove(streamer);
104
+ streamer.protocol.disconnect(1008, 'streamer id not authorized');
105
+ return;
106
+ }
107
+ // An override must remain unique or it would corrupt id-based lookups. If the consumer
108
+ // hands back an id already held by a different streamer we reject rather than clobber.
109
+ const existing = this.find(committedId);
110
+ if (existing && existing !== streamer) {
111
+ Logger_1.Logger.error(`StreamerRegistry: authorizer returned id '${committedId}' which is already in use. Disconnecting.`);
112
+ this.remove(streamer);
113
+ streamer.protocol.disconnect(1008, 'streamer id not authorized');
114
+ return;
115
+ }
116
+ }
117
+ streamer.streamerId = committedId;
118
+ Logger_1.Logger.debug(`StreamerRegistry: Streamer id change. ${oldId} -> ${streamer.streamerId}`);
119
+ streamer.emit('id_changed', streamer.streamerId);
120
+ // because we might have sanitized the id, we confirm the id back to the streamer
121
+ streamer.sendMessage(lib_pixelstreamingcommon_ue5_8_1.MessageHelpers.createMessage(lib_pixelstreamingcommon_ue5_8_1.Messages.endpointIdConfirm, { committedId: streamer.streamerId }));
122
+ }
123
+ sanitizeStreamerId(id) {
124
+ // create a default id if none supplied
125
+ if (!id) {
126
+ id = this.defaultStreamerIdPrefix;
127
+ }
128
+ // search for existing streamerId and optionally append a numeric value
129
+ let maxPostfix = -1;
130
+ for (const streamer of this.streamers) {
131
+ const idMatchRegex = /^(.*?)(\d*)$/;
132
+ const [, baseId, postfix] = streamer.streamerId.match(idMatchRegex);
133
+ // if the id is numeric then base id will be empty and we need to compare with the postfix
134
+ if ((baseId !== '' && baseId !== id) || (baseId === '' && postfix !== id)) {
135
+ continue;
136
+ }
137
+ const numPostfix = Number(postfix);
138
+ if (numPostfix > maxPostfix) {
139
+ maxPostfix = numPostfix;
140
+ }
141
+ }
142
+ if (maxPostfix >= 0) {
143
+ return id + (maxPostfix + 1);
144
+ }
145
+ return id;
146
+ }
147
+ }
148
+ exports.StreamerRegistry = StreamerRegistry;
149
+ //# sourceMappingURL=StreamerRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamerRegistry.js","sourceRoot":"","sources":["../../src/StreamerRegistry.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,iGAO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QAED,uEAAuE;QACvE,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;QACpB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,MAAM,YAAY,GAAG,cAAc,CAAC;YAEpC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAE,CAAC;YACrE,0FAA0F;YAC1F,IAAI,CAAC,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,EAAE,IAAI,OAAO,KAAK,EAAE,CAAC,EAAE,CAAC;gBACxE,SAAS;YACb,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;YACnC,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;gBAC1B,UAAU,GAAG,UAAU,CAAC;YAC5B,CAAC;QACL,CAAC;QACD,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AA1KD,4CA0KC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringify = stringify;
4
+ exports.beautify = beautify;
5
+ // Copyright Epic Games, Inc. All Rights Reserved.
6
+ const jsonc_1 = require("jsonc");
7
+ /**
8
+ * Cirular reference safe version of JSON.stringify
9
+ */
10
+ function stringify(obj) {
11
+ return jsonc_1.jsonc.stringify(obj);
12
+ }
13
+ /**
14
+ * Circular reference save version of JSON.stringify with extra formatting.
15
+ */
16
+ function beautify(obj) {
17
+ return jsonc_1.jsonc.stringify(obj, undefined, '\t');
18
+ }
19
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../src/Utils.ts"],"names":[],"mappings":";;AAMA,8BAEC;AAKD,4BAEC;AAfD,kDAAkD;AAClD,iCAA8B;AAE9B;;GAEG;AACH,SAAgB,SAAS,CAAC,GAAQ;IAC9B,OAAO,aAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,GAAQ;IAC7B,OAAO,aAAK,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebServer = void 0;
7
+ // Copyright Epic Games, Inc. All Rights Reserved.
8
+ const express_1 = __importDefault(require("express"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const http_1 = __importDefault(require("http"));
12
+ const https_1 = __importDefault(require("https"));
13
+ const helmet_1 = __importDefault(require("helmet"));
14
+ const cors_1 = __importDefault(require("cors"));
15
+ const Logger_1 = require("./Logger");
16
+ const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18
+ const hsts = require('hsts');
19
+ /**
20
+ * An object to manage the initialization of a web server. Used to serve the
21
+ * pixel streaming frontend.
22
+ */
23
+ class WebServer {
24
+ constructor(app, config) {
25
+ var _a;
26
+ Logger_1.Logger.debug('Starting WebServer with config: %s', config);
27
+ // only listen on the http port if we're not using https or if we want to redirect
28
+ if (!config.httpsPort || config.https_redirect) {
29
+ this.httpServer = http_1.default.createServer(app);
30
+ this.httpServer.listen(config.httpPort, () => {
31
+ Logger_1.Logger.info(`Http server listening on port ${config.httpPort}`);
32
+ });
33
+ }
34
+ /* eslint-disable @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access */
35
+ // if using https listen on the given ports and setup some details
36
+ if (config.httpsPort) {
37
+ const options = { key: config.ssl_key, cert: config.ssl_cert };
38
+ this.httpsServer = https_1.default.createServer(options, app);
39
+ this.httpsServer.listen(config.httpsPort, () => {
40
+ Logger_1.Logger.info(`Https server listening on port ${config.httpsPort}`);
41
+ });
42
+ app.use((0, helmet_1.default)({
43
+ contentSecurityPolicy: {
44
+ directives: {
45
+ 'connect-src': ['*', "'self'"]
46
+ }
47
+ }
48
+ }));
49
+ app.use(hsts({
50
+ maxAge: 15552000 // 180 days in seconds
51
+ }));
52
+ // Setup http -> https redirect if requested
53
+ if (config.https_redirect) {
54
+ app.use((req, res, next) => {
55
+ if (!req.secure) {
56
+ if (req.get('Host')) {
57
+ const hostAddressParts = req.get('Host').split(':');
58
+ let hostAddress = hostAddressParts[0];
59
+ if (config.httpsPort != 443) {
60
+ hostAddress = `${hostAddress}:${config.httpsPort}`;
61
+ }
62
+ return res.redirect(['https://', hostAddress, req.originalUrl].join(''));
63
+ }
64
+ else {
65
+ Logger_1.Logger.error(`Unable to get host name from header. Requestor ${req.ip}, url path: '${req.originalUrl}', available headers ${JSON.stringify(req.headers)}`);
66
+ return res.status(400).send('Bad Request');
67
+ }
68
+ }
69
+ next();
70
+ });
71
+ }
72
+ }
73
+ if ((_a = config.cors) === null || _a === void 0 ? void 0 : _a.enabled) {
74
+ const corsOptions = {};
75
+ if (config.cors.allowedOrigins && config.cors.allowedOrigins.length > 0) {
76
+ corsOptions.origin = config.cors.allowedOrigins;
77
+ }
78
+ if (config.cors.allowedMethods && config.cors.allowedMethods.length > 0) {
79
+ corsOptions.methods = config.cors.allowedMethods;
80
+ }
81
+ if (config.cors.allowedHeaders && config.cors.allowedHeaders.length > 0) {
82
+ corsOptions.allowedHeaders = config.cors.allowedHeaders;
83
+ }
84
+ if (config.cors.credentials) {
85
+ corsOptions.credentials = true;
86
+ }
87
+ // Register cors before the rate limiter so that preflight (OPTIONS)
88
+ // requests are answered with CORS headers even when an origin is
89
+ // close to the rate limit, and before any route handlers so the
90
+ // homepage, static files, and the REST API all respond uniformly.
91
+ app.use((0, cors_1.default)(corsOptions));
92
+ Logger_1.Logger.info(`CORS enabled. Allowed origins: ${corsOptions.origin ? JSON.stringify(corsOptions.origin) : '*'}`);
93
+ }
94
+ const limiter = (0, express_rate_limit_1.default)({
95
+ windowMs: 60 * 1000, // 1 minute
96
+ max: config.perMinuteRateLimit ? config.perMinuteRateLimit : 3000
97
+ });
98
+ // apply rate limiter to all requests. Registered before any route
99
+ // handler so that static files, the homepage route, and any routes
100
+ // registered on `app` by downstream code are all subject to it.
101
+ app.use(limiter);
102
+ if (config.serveStatic) {
103
+ app.use(express_1.default.static(config.root));
104
+ // Request has been sent to site root, send the homepage file
105
+ app.get('/', function (req, res) {
106
+ // Try a few paths, see if any resolve to a homepage file the user has set
107
+ const p = path_1.default.resolve(path_1.default.join(config.root, config.homepageFile));
108
+ if (fs_1.default.existsSync(p)) {
109
+ // Send the file for browser to display it
110
+ res.sendFile(p);
111
+ return;
112
+ }
113
+ // Catch file doesn't exist, and send back 404 if not
114
+ const error = 'Unable to locate file ' + config.homepageFile;
115
+ Logger_1.Logger.error(error);
116
+ res.status(404).send(error);
117
+ return;
118
+ });
119
+ }
120
+ /* eslint-enable @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access */
121
+ }
122
+ }
123
+ exports.WebServer = WebServer;
124
+ //# sourceMappingURL=WebServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebServer.js","sourceRoot":"","sources":["../../src/WebServer.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkD;AAClD,sDAA8B;AAC9B,gDAAwB;AACxB,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,oDAA4B;AAC5B,gDAAwB;AACxB,qCAAkC;AAClC,4EAA2C;AAE3C,mEAAmE;AACnE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAsE7B;;;GAGG;AAC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,CAAC,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YAErC,6DAA6D;YAC7D,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,GAAQ,EAAE,GAAQ;gBACrC,0EAA0E;gBAC1E,MAAM,CAAC,GAAG,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;gBACpE,IAAI,YAAE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnB,0CAA0C;oBAC1C,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;oBAChB,OAAO;gBACX,CAAC;gBAED,qDAAqD;gBACrD,MAAM,KAAK,GAAG,wBAAwB,GAAG,MAAM,CAAC,YAAY,CAAC;gBAC7D,eAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACpB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC5B,OAAO;YACX,CAAC,CAAC,CAAC;QACP,CAAC;QAED,gGAAgG;IACpG,CAAC;CACJ;AA9HD,8BA8HC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Copyright Epic Games, Inc. All Rights Reserved.
18
+ __exportStar(require("./Logger"), exports);
19
+ __exportStar(require("./LoggingUtils"), exports);
20
+ __exportStar(require("./PlayerConnection"), exports);
21
+ __exportStar(require("./PlayerRegistry"), exports);
22
+ __exportStar(require("./SFUConnection"), exports);
23
+ __exportStar(require("./SignallingServer"), exports);
24
+ __exportStar(require("./StreamerConnection"), exports);
25
+ __exportStar(require("./StreamerRegistry"), exports);
26
+ __exportStar(require("./WebServer"), exports);
27
+ // keep Utils internal for now
28
+ //# sourceMappingURL=pixelstreamingsignalling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixelstreamingsignalling.js","sourceRoot":"","sources":["../../src/pixelstreamingsignalling.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAkD;AAClD,2CAAyB;AACzB,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,qDAAmC;AACnC,uDAAqC;AACrC,qDAAmC;AACnC,8CAA4B;AAC5B,8BAA8B"}
@@ -0,0 +1,141 @@
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+ import { stringify, beautify } from './Utils';
3
+ import path from 'path';
4
+ import winston from 'winston';
5
+ import 'winston-daily-rotate-file';
6
+ import { overrideLogger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.8';
7
+ const { combine, timestamp, printf, colorize, splat } = winston.format;
8
+ /**
9
+ * The actual logger object. This is just a winston logger.
10
+ * You can use InitLogging to get a decent result, or you can
11
+ * completely create your own winston logger and assign it.
12
+ */
13
+ export let Logger = createDefaultLogger();
14
+ /**
15
+ * A wrapper for the log calls in Common lib
16
+ */
17
+ class CommonLogger {
18
+ constructor(winstonLogger) {
19
+ this.logger = winstonLogger;
20
+ }
21
+ InitLogging(_logLevel, _includeStack) { }
22
+ Debug(message) {
23
+ this.logger.debug(message);
24
+ }
25
+ Info(message) {
26
+ this.logger.info(message);
27
+ }
28
+ Warning(message) {
29
+ this.logger.warn(message);
30
+ }
31
+ Error(message) {
32
+ this.logger.error(message);
33
+ }
34
+ }
35
+ /**
36
+ * Call this as early as possible to setup the logging module with your
37
+ * preferred settings.
38
+ * @param config - The settings to init the logger with. See IConfig interface
39
+ */
40
+ export function InitLogging(config) {
41
+ const logDir = config.logDir || 'logs';
42
+ const logLevelConsole = config.logLevelConsole || 'info';
43
+ const logLevelFile = config.logLevelFile || 'info';
44
+ logMessagesToConsole = config.logMessagesToConsole || 'none';
45
+ Logger = winston.createLogger({
46
+ transports: [createConsoleTransport(logLevelConsole), createFileTransport(logDir, logLevelFile)]
47
+ });
48
+ const commonLogger = new CommonLogger(Logger);
49
+ overrideLogger(commonLogger);
50
+ }
51
+ let logMessagesToConsole = 'none';
52
+ function createDefaultLogger() {
53
+ return winston.createLogger({
54
+ level: 'info',
55
+ format: winston.format.cli(),
56
+ transports: [new winston.transports.Console()]
57
+ });
58
+ }
59
+ function createConsoleTransport(logLevel) {
60
+ return new winston.transports.Console({
61
+ level: logLevel,
62
+ format: combine(createProtoMessageFilter()(), timestamp({ format: 'HH:mm:ss.SSS' }), colorize(), splat(), createConsoleFormat())
63
+ });
64
+ }
65
+ function isLogObject(object) {
66
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
67
+ return ('event' in object &&
68
+ object.event == 'proto_message' &&
69
+ 'direction' in object &&
70
+ 'protoMessage' in object);
71
+ /* eslint-enable @typescript-eslint/no-unsafe-member-access */
72
+ }
73
+ function createConsoleFormat() {
74
+ return printf((logObj) => {
75
+ const prefix = `[${String(logObj['timestamp'])}] ${logObj.level}: `;
76
+ if (typeof logObj.message === 'string') {
77
+ return prefix + logObj.message;
78
+ }
79
+ else if (isLogObject(logObj.message)) {
80
+ const { direction, receiver, sender, target, protoMessage } = logObj.message;
81
+ switch (direction) {
82
+ case 'incoming':
83
+ return prefix + `> ${receiver} :: ${formatMessageForConsole(protoMessage)}`;
84
+ case 'outgoing':
85
+ return prefix + `< ${sender} :: ${formatMessageForConsole(protoMessage)}`;
86
+ case 'forward':
87
+ return prefix + `${receiver} > ${target} :: ${formatMessageForConsole(protoMessage)}`;
88
+ default:
89
+ return prefix + `Unknown proto direction: ${direction}`;
90
+ }
91
+ }
92
+ return '';
93
+ });
94
+ }
95
+ function formatMessageForConsole(message) {
96
+ switch (logMessagesToConsole) {
97
+ case 'verbose':
98
+ return stringify(message);
99
+ case 'formatted':
100
+ return beautify(message);
101
+ default:
102
+ return `[${message.type}]`;
103
+ }
104
+ }
105
+ function createProtoMessageFilter() {
106
+ return winston.format((info, _opts) => {
107
+ if (typeof info.message !== 'string' && isLogObject(info.message) && logMessagesToConsole == 'none') {
108
+ return false;
109
+ }
110
+ return info;
111
+ });
112
+ }
113
+ function createFileTransport(logDirPath, logLevel) {
114
+ return new winston.transports.DailyRotateFile({
115
+ level: logLevel,
116
+ filename: path.join(logDirPath, 'server-%DATE%.log'),
117
+ datePattern: 'YYYY-MM-DD',
118
+ maxFiles: '14d',
119
+ format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), splat(), createFileFormat())
120
+ });
121
+ }
122
+ function createFileFormat() {
123
+ return printf((logObj) => {
124
+ if (typeof logObj.message === 'string') {
125
+ const { timestamp, level, message } = logObj;
126
+ return JSON.stringify({
127
+ timestamp,
128
+ level,
129
+ event: 'message',
130
+ message
131
+ });
132
+ }
133
+ else if (isLogObject(logObj.message)) {
134
+ const { timestamp, level, message } = logObj;
135
+ return JSON.stringify(Object.assign({ timestamp,
136
+ level }, message));
137
+ }
138
+ return '';
139
+ });
140
+ }
141
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,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C;AACP,CAAC;AAED,SAAS,mBAAmB,CAAC,UAAkB,EAAE,QAAgB;IAC7D,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC;QAC1C,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,mBAAmB,CAAC;QACpD,WAAW,EAAE,YAAY;QACzB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,CAAC;KACjG,CAAC,CAAC;AACP,CAAC;AAED,SAAS,gBAAgB;IACrB,OAAO,MAAM,CAAC,CAAC,MAAyB,EAAE,EAAE;QACxC,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;YAC7C,OAAO,IAAI,CAAC,SAAS,CAAC;gBAClB,SAAS;gBACT,KAAK;gBACL,KAAK,EAAE,SAAS;gBAChB,OAAO;aACV,CAAC,CAAC;QACP,CAAC;aAAM,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACrC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;YAC7C,OAAO,IAAI,CAAC,SAAS,iBACjB,SAAS;gBACT,KAAK,IACF,OAAO,EACZ,CAAC;QACP,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { Logger } from './Logger';
2
+ /**
3
+ * Call to log messages received on a connection that we will handle here at the server.
4
+ * Do not call this for messages being forwarded to another connection.
5
+ * @param recvr - IMessageLogger The connection the message was received on.
6
+ */
7
+ export function logIncoming(recvr, message) {
8
+ const logObj = {
9
+ event: 'proto_message',
10
+ direction: 'incoming',
11
+ receiver: recvr.getReadableIdentifier(),
12
+ protoMessage: message
13
+ };
14
+ Logger.info(logObj);
15
+ }
16
+ /**
17
+ * Call to log messages created here at the server and being sent to the connection.
18
+ * Do not call this for messages being forwarded to this connection.
19
+ * @param sender - IMessageLogger The connection the message is being sent to.
20
+ */
21
+ export function logOutgoing(sender, message) {
22
+ Logger.info({
23
+ event: 'proto_message',
24
+ direction: 'outgoing',
25
+ sender: sender.getReadableIdentifier(),
26
+ protoMessage: message
27
+ });
28
+ }
29
+ /**
30
+ * Call this for messages being forwarded to this connection. That is messages received on
31
+ * one connection and being sent to another with only minor changes being made.
32
+ * @param recvr - The connection the message was received on.
33
+ * @param target - The connection the message is being sent to.
34
+ */
35
+ export function logForward(recvr, target, message) {
36
+ Logger.info({
37
+ event: 'proto_message',
38
+ direction: 'forward',
39
+ receiver: recvr.getReadableIdentifier(),
40
+ target: target.getReadableIdentifier(),
41
+ protoMessage: message
42
+ });
43
+ }
44
+ /**
45
+ * We don't want to log every incoming and outgoing messages. This is because some messages are simply
46
+ * forwarded to other connections. This results in duplicated spam. So we only want to log incoming
47
+ * messages that we handle internally, and any messages that we forward we only log once for the recv
48
+ * and send events.
49
+ * This creation method allows a simple way to enforce this. Any events we handle directly will
50
+ * be preceded by the logging call.
51
+ */
52
+ export function createHandlerListener(obj, handler) {
53
+ return (message) => {
54
+ logIncoming(obj, message);
55
+ handler.bind(obj)(message);
56
+ };
57
+ }
58
+ //# sourceMappingURL=LoggingUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoggingUtils.js","sourceRoot":"","sources":["../../src/LoggingUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAmBlC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAqB,EAAE,OAAoB;IACnE,MAAM,MAAM,GAAiB;QACzB,KAAK,EAAE,eAAe;QACtB,SAAS,EAAE,UAAU;QACrB,QAAQ,E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