@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.
- package/.lintstagedrc.mjs +7 -0
- package/.prettierignore +0 -0
- package/CHANGELOG.md +21 -0
- package/README.md +32 -0
- package/dist/cjs/Logger.js +148 -0
- package/dist/cjs/Logger.js.map +1 -0
- package/dist/cjs/LoggingUtils.js +64 -0
- package/dist/cjs/LoggingUtils.js.map +1 -0
- package/dist/cjs/PlayerConnection.js +220 -0
- package/dist/cjs/PlayerConnection.js.map +1 -0
- package/dist/cjs/PlayerRegistry.js +77 -0
- package/dist/cjs/PlayerRegistry.js.map +1 -0
- package/dist/cjs/SFUConnection.js +264 -0
- package/dist/cjs/SFUConnection.js.map +1 -0
- package/dist/cjs/SignallingServer.js +149 -0
- package/dist/cjs/SignallingServer.js.map +1 -0
- package/dist/cjs/StreamerConnection.js +172 -0
- package/dist/cjs/StreamerConnection.js.map +1 -0
- package/dist/cjs/StreamerRegistry.js +149 -0
- package/dist/cjs/StreamerRegistry.js.map +1 -0
- package/dist/cjs/Utils.js +19 -0
- package/dist/cjs/Utils.js.map +1 -0
- package/dist/cjs/WebServer.js +124 -0
- package/dist/cjs/WebServer.js.map +1 -0
- package/dist/cjs/pixelstreamingsignalling.js +28 -0
- package/dist/cjs/pixelstreamingsignalling.js.map +1 -0
- package/dist/esm/Logger.js +141 -0
- package/dist/esm/Logger.js.map +1 -0
- package/dist/esm/LoggingUtils.js +58 -0
- package/dist/esm/LoggingUtils.js.map +1 -0
- package/dist/esm/PlayerConnection.js +183 -0
- package/dist/esm/PlayerConnection.js.map +1 -0
- package/dist/esm/PlayerRegistry.js +73 -0
- package/dist/esm/PlayerRegistry.js.map +1 -0
- package/dist/esm/SFUConnection.js +227 -0
- package/dist/esm/SFUConnection.js.map +1 -0
- package/dist/esm/SignallingServer.js +112 -0
- package/dist/esm/SignallingServer.js.map +1 -0
- package/dist/esm/StreamerConnection.js +135 -0
- package/dist/esm/StreamerConnection.js.map +1 -0
- package/dist/esm/StreamerRegistry.js +145 -0
- package/dist/esm/StreamerRegistry.js.map +1 -0
- package/dist/esm/Utils.js +15 -0
- package/dist/esm/Utils.js.map +1 -0
- package/dist/esm/WebServer.js +117 -0
- package/dist/esm/WebServer.js.map +1 -0
- package/dist/esm/pixelstreamingsignalling.js +12 -0
- package/dist/esm/pixelstreamingsignalling.js.map +1 -0
- package/dist/types/Logger.d.ts +20 -0
- package/dist/types/LoggingUtils.d.ts +44 -0
- package/dist/types/PlayerConnection.d.ts +66 -0
- package/dist/types/PlayerRegistry.d.ts +66 -0
- package/dist/types/SFUConnection.d.ts +85 -0
- package/dist/types/SignallingServer.d.ts +48 -0
- package/dist/types/StreamerConnection.d.ts +61 -0
- package/dist/types/StreamerRegistry.d.ts +96 -0
- package/dist/types/Utils.d.ts +8 -0
- package/dist/types/WebServer.d.ts +42 -0
- package/dist/types/pixelstreamingsignalling.d.ts +9 -0
- package/docs/Logger/README.md +19 -0
- package/docs/Logger/functions/InitLogging.md +26 -0
- package/docs/Logger/interfaces/IConfig.md +41 -0
- package/docs/Logger/variables/Logger.md +15 -0
- package/docs/LoggingUtils/README.md +19 -0
- package/docs/LoggingUtils/functions/createHandlerListener.md +42 -0
- package/docs/LoggingUtils/functions/logForward.md +36 -0
- package/docs/LoggingUtils/functions/logIncoming.md +30 -0
- package/docs/LoggingUtils/functions/logOutgoing.md +30 -0
- package/docs/LoggingUtils/interfaces/IMessageLogger.md +29 -0
- package/docs/LoggingUtils/interfaces/IProtoLogObj.md +57 -0
- package/docs/PlayerConnection/README.md +11 -0
- package/docs/PlayerConnection/classes/PlayerConnection.md +177 -0
- package/docs/PlayerRegistry/README.md +16 -0
- package/docs/PlayerRegistry/classes/PlayerRegistry.md +423 -0
- package/docs/PlayerRegistry/interfaces/IPlayer.md +86 -0
- package/docs/PlayerRegistry/interfaces/IPlayerInfo.md +43 -0
- package/docs/README.md +19 -0
- package/docs/SFUConnection/README.md +11 -0
- package/docs/SFUConnection/classes/SFUConnection.md +554 -0
- package/docs/SignallingServer/README.md +19 -0
- package/docs/SignallingServer/classes/SignallingServer.md +76 -0
- package/docs/SignallingServer/interfaces/IServerConfig.md +92 -0
- package/docs/SignallingServer/type-aliases/ProtocolConfig.md +15 -0
- package/docs/StreamerConnection/README.md +11 -0
- package/docs/StreamerConnection/classes/StreamerConnection.md +507 -0
- package/docs/StreamerRegistry/README.md +16 -0
- package/docs/StreamerRegistry/classes/StreamerRegistry.md +431 -0
- package/docs/StreamerRegistry/interfaces/IStreamer.md +375 -0
- package/docs/StreamerRegistry/interfaces/IStreamerInfo.md +51 -0
- package/docs/Utils/README.md +12 -0
- package/docs/Utils/functions/beautify.md +23 -0
- package/docs/Utils/functions/stringify.md +23 -0
- package/docs/WebServer/README.md +15 -0
- package/docs/WebServer/classes/WebServer.md +50 -0
- package/docs/WebServer/interfaces/IWebServerConfig.md +76 -0
- package/docs/pixelstreamingsignalling/README.md +145 -0
- package/eslint.config.mjs +39 -0
- package/package.json +58 -0
- package/src/Logger.ts +189 -0
- package/src/LoggingUtils.ts +80 -0
- package/src/PlayerConnection.ts +257 -0
- package/src/PlayerRegistry.ts +116 -0
- package/src/SFUConnection.ts +329 -0
- package/src/SignallingServer.ts +214 -0
- package/src/StreamerConnection.ts +194 -0
- package/src/StreamerRegistry.ts +252 -0
- package/src/Utils.ts +16 -0
- package/src/WebServer.ts +213 -0
- package/src/pixelstreamingsignalling.ts +11 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
[**@epicgames-ps/lib-pixelstreamingsignalling-ue5.5**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@epicgames-ps/lib-pixelstreamingsignalling-ue5.5](../README.md) / pixelstreamingsignalling
|
|
6
|
+
|
|
7
|
+
# pixelstreamingsignalling
|
|
8
|
+
|
|
9
|
+
## References
|
|
10
|
+
|
|
11
|
+
### createHandlerListener
|
|
12
|
+
|
|
13
|
+
Re-exports [createHandlerListener](../LoggingUtils/functions/createHandlerListener.md)
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### IConfig
|
|
18
|
+
|
|
19
|
+
Re-exports [IConfig](../Logger/interfaces/IConfig.md)
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### IMessageLogger
|
|
24
|
+
|
|
25
|
+
Re-exports [IMessageLogger](../LoggingUtils/interfaces/IMessageLogger.md)
|
|
26
|
+
|
|
27
|
+
***
|
|
28
|
+
|
|
29
|
+
### InitLogging
|
|
30
|
+
|
|
31
|
+
Re-exports [InitLogging](../Logger/functions/InitLogging.md)
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### IPlayer
|
|
36
|
+
|
|
37
|
+
Re-exports [IPlayer](../PlayerRegistry/interfaces/IPlayer.md)
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### IPlayerInfo
|
|
42
|
+
|
|
43
|
+
Re-exports [IPlayerInfo](../PlayerRegistry/interfaces/IPlayerInfo.md)
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
### IProtoLogObj
|
|
48
|
+
|
|
49
|
+
Re-exports [IProtoLogObj](../LoggingUtils/interfaces/IProtoLogObj.md)
|
|
50
|
+
|
|
51
|
+
***
|
|
52
|
+
|
|
53
|
+
### IServerConfig
|
|
54
|
+
|
|
55
|
+
Re-exports [IServerConfig](../SignallingServer/interfaces/IServerConfig.md)
|
|
56
|
+
|
|
57
|
+
***
|
|
58
|
+
|
|
59
|
+
### IStreamer
|
|
60
|
+
|
|
61
|
+
Re-exports [IStreamer](../StreamerRegistry/interfaces/IStreamer.md)
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### IStreamerInfo
|
|
66
|
+
|
|
67
|
+
Re-exports [IStreamerInfo](../StreamerRegistry/interfaces/IStreamerInfo.md)
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### IWebServerConfig
|
|
72
|
+
|
|
73
|
+
Re-exports [IWebServerConfig](../WebServer/interfaces/IWebServerConfig.md)
|
|
74
|
+
|
|
75
|
+
***
|
|
76
|
+
|
|
77
|
+
### logForward
|
|
78
|
+
|
|
79
|
+
Re-exports [logForward](../LoggingUtils/functions/logForward.md)
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### Logger
|
|
84
|
+
|
|
85
|
+
Re-exports [Logger](../Logger/variables/Logger.md)
|
|
86
|
+
|
|
87
|
+
***
|
|
88
|
+
|
|
89
|
+
### logIncoming
|
|
90
|
+
|
|
91
|
+
Re-exports [logIncoming](../LoggingUtils/functions/logIncoming.md)
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
95
|
+
### logOutgoing
|
|
96
|
+
|
|
97
|
+
Re-exports [logOutgoing](../LoggingUtils/functions/logOutgoing.md)
|
|
98
|
+
|
|
99
|
+
***
|
|
100
|
+
|
|
101
|
+
### PlayerConnection
|
|
102
|
+
|
|
103
|
+
Re-exports [PlayerConnection](../PlayerConnection/classes/PlayerConnection.md)
|
|
104
|
+
|
|
105
|
+
***
|
|
106
|
+
|
|
107
|
+
### PlayerRegistry
|
|
108
|
+
|
|
109
|
+
Re-exports [PlayerRegistry](../PlayerRegistry/classes/PlayerRegistry.md)
|
|
110
|
+
|
|
111
|
+
***
|
|
112
|
+
|
|
113
|
+
### ProtocolConfig
|
|
114
|
+
|
|
115
|
+
Re-exports [ProtocolConfig](../SignallingServer/type-aliases/ProtocolConfig.md)
|
|
116
|
+
|
|
117
|
+
***
|
|
118
|
+
|
|
119
|
+
### SFUConnection
|
|
120
|
+
|
|
121
|
+
Re-exports [SFUConnection](../SFUConnection/classes/SFUConnection.md)
|
|
122
|
+
|
|
123
|
+
***
|
|
124
|
+
|
|
125
|
+
### SignallingServer
|
|
126
|
+
|
|
127
|
+
Re-exports [SignallingServer](../SignallingServer/classes/SignallingServer.md)
|
|
128
|
+
|
|
129
|
+
***
|
|
130
|
+
|
|
131
|
+
### StreamerConnection
|
|
132
|
+
|
|
133
|
+
Re-exports [StreamerConnection](../StreamerConnection/classes/StreamerConnection.md)
|
|
134
|
+
|
|
135
|
+
***
|
|
136
|
+
|
|
137
|
+
### StreamerRegistry
|
|
138
|
+
|
|
139
|
+
Re-exports [StreamerRegistry](../StreamerRegistry/classes/StreamerRegistry.md)
|
|
140
|
+
|
|
141
|
+
***
|
|
142
|
+
|
|
143
|
+
### WebServer
|
|
144
|
+
|
|
145
|
+
Re-exports [WebServer](../WebServer/classes/WebServer.md)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
import tsdocPlugin from 'eslint-plugin-tsdoc';
|
|
5
|
+
import baseConfig from '../eslint.config.mjs'
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
baseConfig,
|
|
9
|
+
{
|
|
10
|
+
ignores: [],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
languageOptions: {
|
|
14
|
+
parser: tseslint.parser,
|
|
15
|
+
parserOptions: {
|
|
16
|
+
project: 'tsconfig.cjs.json',
|
|
17
|
+
tsconfigRootDir: import.meta.dirname,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
files: ["src/**/*.ts"],
|
|
21
|
+
plugins: {
|
|
22
|
+
'tsdoc': tsdocPlugin,
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
"tsdoc/syntax": "warn",
|
|
26
|
+
"@typescript-eslint/require-array-sort-compare": "error",
|
|
27
|
+
"no-unused-vars": "off",
|
|
28
|
+
"@typescript-eslint/no-misused-promises": "off", // http.createServer(app) is throwing this
|
|
29
|
+
"@typescript-eslint/no-unused-vars": [
|
|
30
|
+
"error",
|
|
31
|
+
{
|
|
32
|
+
"argsIgnorePattern": "^_",
|
|
33
|
+
"varsIgnorePattern": "^_",
|
|
34
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@epicgames-ps/lib-pixelstreamingsignalling-ue5.8",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Basic signalling library for developers wishing to build applications that signal a Pixel Streaming application.",
|
|
5
|
+
"main": "dist/cjs/pixelstreamingsignalling.js",
|
|
6
|
+
"module": "dist/esm/pixelstreamingsignalling.js",
|
|
7
|
+
"types": "dist/types/pixelstreamingsignalling.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "rimraf ./dist",
|
|
10
|
+
"build:docs": "echo \"Make sure you're passing the right --gitRemote so the source links are correct!\" && typedoc --tsconfig tsconfig.cjs.json",
|
|
11
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
12
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
13
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
14
|
+
"rebuild": "npm run clean && npm run build",
|
|
15
|
+
"watch": "nodemon -V -d 3 --watch src --watch ../Common/dist -e \"ts,js,mjs,cjs,json\" --exec \"npm run build:cjs\"",
|
|
16
|
+
"lint": "eslint src",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
18
|
+
},
|
|
19
|
+
"author": "Epic Games",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@eslint/js": "^9.20.0",
|
|
23
|
+
"@types/cors": "^2.8.17",
|
|
24
|
+
"@types/express": "^5.0.0",
|
|
25
|
+
"@types/node": "^22.14.0",
|
|
26
|
+
"@types/ws": "^8.5.14",
|
|
27
|
+
"eslint": "^9.39.0",
|
|
28
|
+
"eslint-config-prettier": "^10.0.1",
|
|
29
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
30
|
+
"eslint-plugin-tsdoc": "^0.4.0",
|
|
31
|
+
"nodemon": "^3.1.9",
|
|
32
|
+
"rimraf": "^6.0.1",
|
|
33
|
+
"typedoc": "^0.28.0",
|
|
34
|
+
"typedoc-plugin-markdown": "^4.4.2",
|
|
35
|
+
"typescript": "^5.7.3",
|
|
36
|
+
"typescript-eslint": "8.57.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"body-parser": "^1.20.4",
|
|
40
|
+
"cors": "^2.8.5",
|
|
41
|
+
"express": "^4.22.1",
|
|
42
|
+
"express-rate-limit": "^8.5.1",
|
|
43
|
+
"helmet": "^8.0.0",
|
|
44
|
+
"hsts": "^2.2.0",
|
|
45
|
+
"jsonc": "^2.0.0",
|
|
46
|
+
"logform": "^2.7.0",
|
|
47
|
+
"winston": "^3.17.0",
|
|
48
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
49
|
+
"ws": "^8.18.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@epicgames-ps/lib-pixelstreamingcommon-ue5.8": "^0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "https://github.com/EpicGames/PixelStreamingInfrastructure"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/Logger.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
2
|
+
import { stringify, beautify } from './Utils';
|
|
3
|
+
import { IProtoLogObj } from './LoggingUtils';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
import 'winston-daily-rotate-file';
|
|
7
|
+
import { TransformableInfo } from 'logform';
|
|
8
|
+
import { BaseMessage, ILogger, overrideLogger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.8';
|
|
9
|
+
|
|
10
|
+
const { combine, timestamp, printf, colorize, splat } = winston.format;
|
|
11
|
+
|
|
12
|
+
type WinstonLogger = ReturnType<typeof winston.createLogger>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The actual logger object. This is just a winston logger.
|
|
16
|
+
* You can use InitLogging to get a decent result, or you can
|
|
17
|
+
* completely create your own winston logger and assign it.
|
|
18
|
+
*/
|
|
19
|
+
export let Logger = createDefaultLogger();
|
|
20
|
+
|
|
21
|
+
export interface IConfig {
|
|
22
|
+
// the directory to store log files
|
|
23
|
+
logDir?: string;
|
|
24
|
+
|
|
25
|
+
// if true, every message will be logged to the console in a condensed form
|
|
26
|
+
logMessagesToConsole?: string;
|
|
27
|
+
|
|
28
|
+
// the minimum log level for console messages
|
|
29
|
+
logLevelConsole?: string;
|
|
30
|
+
|
|
31
|
+
// the minimum log level for file messages
|
|
32
|
+
logLevelFile?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A wrapper for the log calls in Common lib
|
|
37
|
+
*/
|
|
38
|
+
class CommonLogger implements ILogger {
|
|
39
|
+
logger: WinstonLogger;
|
|
40
|
+
|
|
41
|
+
constructor(winstonLogger: WinstonLogger) {
|
|
42
|
+
this.logger = winstonLogger;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
InitLogging(_logLevel: number, _includeStack: boolean): void {}
|
|
46
|
+
|
|
47
|
+
Debug(message: string): void {
|
|
48
|
+
this.logger.debug(message);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
Info(message: string): void {
|
|
52
|
+
this.logger.info(message);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Warning(message: string): void {
|
|
56
|
+
this.logger.warn(message);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Error(message: string): void {
|
|
60
|
+
this.logger.error(message);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Call this as early as possible to setup the logging module with your
|
|
66
|
+
* preferred settings.
|
|
67
|
+
* @param config - The settings to init the logger with. See IConfig interface
|
|
68
|
+
*/
|
|
69
|
+
export function InitLogging(config: IConfig): void {
|
|
70
|
+
const logDir = config.logDir || 'logs';
|
|
71
|
+
const logLevelConsole = config.logLevelConsole || 'info';
|
|
72
|
+
const logLevelFile = config.logLevelFile || 'info';
|
|
73
|
+
logMessagesToConsole = config.logMessagesToConsole || 'none';
|
|
74
|
+
|
|
75
|
+
Logger = winston.createLogger({
|
|
76
|
+
transports: [createConsoleTransport(logLevelConsole), createFileTransport(logDir, logLevelFile)]
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const commonLogger = new CommonLogger(Logger);
|
|
80
|
+
overrideLogger(commonLogger);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let logMessagesToConsole = 'none';
|
|
84
|
+
|
|
85
|
+
function createDefaultLogger() {
|
|
86
|
+
return winston.createLogger({
|
|
87
|
+
level: 'info',
|
|
88
|
+
format: winston.format.cli(),
|
|
89
|
+
transports: [new winston.transports.Console()]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function createConsoleTransport(logLevel: string) {
|
|
94
|
+
return new winston.transports.Console({
|
|
95
|
+
level: logLevel,
|
|
96
|
+
format: combine(
|
|
97
|
+
createProtoMessageFilter()(),
|
|
98
|
+
timestamp({ format: 'HH:mm:ss.SSS' }),
|
|
99
|
+
colorize(),
|
|
100
|
+
splat(),
|
|
101
|
+
createConsoleFormat()
|
|
102
|
+
)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isLogObject(object: any): object is IProtoLogObj {
|
|
107
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
108
|
+
return (
|
|
109
|
+
'event' in object &&
|
|
110
|
+
object.event == 'proto_message' &&
|
|
111
|
+
'direction' in object &&
|
|
112
|
+
'protoMessage' in object
|
|
113
|
+
);
|
|
114
|
+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function createConsoleFormat() {
|
|
118
|
+
return printf((logObj: TransformableInfo) => {
|
|
119
|
+
const prefix = `[${String(logObj['timestamp'])}] ${logObj.level}: `;
|
|
120
|
+
if (typeof logObj.message === 'string') {
|
|
121
|
+
return prefix + logObj.message;
|
|
122
|
+
} else if (isLogObject(logObj.message)) {
|
|
123
|
+
const { direction, receiver, sender, target, protoMessage } = logObj.message;
|
|
124
|
+
switch (direction) {
|
|
125
|
+
case 'incoming':
|
|
126
|
+
return prefix + `> ${receiver} :: ${formatMessageForConsole(protoMessage)}`;
|
|
127
|
+
case 'outgoing':
|
|
128
|
+
return prefix + `< ${sender} :: ${formatMessageForConsole(protoMessage)}`;
|
|
129
|
+
case 'forward':
|
|
130
|
+
return prefix + `${receiver} > ${target} :: ${formatMessageForConsole(protoMessage)}`;
|
|
131
|
+
default:
|
|
132
|
+
return prefix + `Unknown proto direction: ${direction}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return '';
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function formatMessageForConsole(message: BaseMessage) {
|
|
140
|
+
switch (logMessagesToConsole) {
|
|
141
|
+
case 'verbose':
|
|
142
|
+
return stringify(message);
|
|
143
|
+
case 'formatted':
|
|
144
|
+
return beautify(message);
|
|
145
|
+
default:
|
|
146
|
+
return `[${message.type}]`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function createProtoMessageFilter() {
|
|
151
|
+
return winston.format((info: TransformableInfo, _opts: any) => {
|
|
152
|
+
if (typeof info.message !== 'string' && isLogObject(info.message) && logMessagesToConsole == 'none') {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return info;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function createFileTransport(logDirPath: string, logLevel: string) {
|
|
160
|
+
return new winston.transports.DailyRotateFile({
|
|
161
|
+
level: logLevel,
|
|
162
|
+
filename: path.join(logDirPath, 'server-%DATE%.log'),
|
|
163
|
+
datePattern: 'YYYY-MM-DD',
|
|
164
|
+
maxFiles: '14d',
|
|
165
|
+
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), splat(), createFileFormat())
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function createFileFormat() {
|
|
170
|
+
return printf((logObj: TransformableInfo) => {
|
|
171
|
+
if (typeof logObj.message === 'string') {
|
|
172
|
+
const { timestamp, level, message } = logObj;
|
|
173
|
+
return JSON.stringify({
|
|
174
|
+
timestamp,
|
|
175
|
+
level,
|
|
176
|
+
event: 'message',
|
|
177
|
+
message
|
|
178
|
+
});
|
|
179
|
+
} else if (isLogObject(logObj.message)) {
|
|
180
|
+
const { timestamp, level, message } = logObj;
|
|
181
|
+
return JSON.stringify({
|
|
182
|
+
timestamp,
|
|
183
|
+
level,
|
|
184
|
+
...message
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return '';
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
2
|
+
import { BaseMessage } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.8';
|
|
3
|
+
import { Logger } from './Logger';
|
|
4
|
+
|
|
5
|
+
export interface IProtoLogObj {
|
|
6
|
+
event: string;
|
|
7
|
+
direction: string;
|
|
8
|
+
sender?: string;
|
|
9
|
+
receiver?: string;
|
|
10
|
+
target?: string;
|
|
11
|
+
protoMessage: BaseMessage;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Most methods in here rely on connections implementing this interface so we can identify
|
|
16
|
+
* who is sending or receiving etc.
|
|
17
|
+
*/
|
|
18
|
+
export interface IMessageLogger {
|
|
19
|
+
getReadableIdentifier(): string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Call to log messages received on a connection that we will handle here at the server.
|
|
24
|
+
* Do not call this for messages being forwarded to another connection.
|
|
25
|
+
* @param recvr - IMessageLogger The connection the message was received on.
|
|
26
|
+
*/
|
|
27
|
+
export function logIncoming(recvr: IMessageLogger, message: BaseMessage): void {
|
|
28
|
+
const logObj: IProtoLogObj = {
|
|
29
|
+
event: 'proto_message',
|
|
30
|
+
direction: 'incoming',
|
|
31
|
+
receiver: recvr.getReadableIdentifier(),
|
|
32
|
+
protoMessage: message
|
|
33
|
+
};
|
|
34
|
+
Logger.info(logObj);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Call to log messages created here at the server and being sent to the connection.
|
|
39
|
+
* Do not call this for messages being forwarded to this connection.
|
|
40
|
+
* @param sender - IMessageLogger The connection the message is being sent to.
|
|
41
|
+
*/
|
|
42
|
+
export function logOutgoing(sender: IMessageLogger, message: BaseMessage): void {
|
|
43
|
+
Logger.info({
|
|
44
|
+
event: 'proto_message',
|
|
45
|
+
direction: 'outgoing',
|
|
46
|
+
sender: sender.getReadableIdentifier(),
|
|
47
|
+
protoMessage: message
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Call this for messages being forwarded to this connection. That is messages received on
|
|
53
|
+
* one connection and being sent to another with only minor changes being made.
|
|
54
|
+
* @param recvr - The connection the message was received on.
|
|
55
|
+
* @param target - The connection the message is being sent to.
|
|
56
|
+
*/
|
|
57
|
+
export function logForward(recvr: IMessageLogger, target: IMessageLogger, message: BaseMessage): void {
|
|
58
|
+
Logger.info({
|
|
59
|
+
event: 'proto_message',
|
|
60
|
+
direction: 'forward',
|
|
61
|
+
receiver: recvr.getReadableIdentifier(),
|
|
62
|
+
target: target.getReadableIdentifier(),
|
|
63
|
+
protoMessage: message
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* We don't want to log every incoming and outgoing messages. This is because some messages are simply
|
|
69
|
+
* forwarded to other connections. This results in duplicated spam. So we only want to log incoming
|
|
70
|
+
* messages that we handle internally, and any messages that we forward we only log once for the recv
|
|
71
|
+
* and send events.
|
|
72
|
+
* This creation method allows a simple way to enforce this. Any events we handle directly will
|
|
73
|
+
* be preceded by the logging call.
|
|
74
|
+
*/
|
|
75
|
+
export function createHandlerListener(obj: IMessageLogger, handler: (message: any) => void) {
|
|
76
|
+
return (message: BaseMessage) => {
|
|
77
|
+
logIncoming(obj, message);
|
|
78
|
+
handler.bind(obj)(message);
|
|
79
|
+
};
|
|
80
|
+
}
|