buttplug 3.2.1 → 4.0.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/.eslintrc.js +25 -25
- package/.jscsrc +2 -2
- package/.jshintrc +5 -5
- package/.prettierrc.json +3 -3
- package/.yarnrc.yml +5 -1
- package/CHANGELOG.md +577 -571
- package/LICENSE +27 -27
- package/README.md +97 -97
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js +6 -9
- package/dist/main/src/client/ButtplugBrowserWebsocketClientConnector.js.map +1 -1
- package/dist/main/src/client/{Client.d.ts → ButtplugClient.d.ts} +3 -4
- package/dist/main/src/client/ButtplugClient.js +227 -0
- package/dist/main/src/client/ButtplugClient.js.map +1 -0
- package/dist/main/src/client/ButtplugClientConnectorException.js +17 -7
- package/dist/main/src/client/ButtplugClientConnectorException.js.map +1 -1
- package/dist/main/src/client/ButtplugClientDevice.d.ts +13 -28
- package/dist/main/src/client/ButtplugClientDevice.js +105 -247
- package/dist/main/src/client/ButtplugClientDevice.js.map +1 -1
- package/dist/main/src/client/ButtplugClientDeviceCommand.d.ts +42 -0
- package/dist/main/src/client/ButtplugClientDeviceCommand.js +105 -0
- package/dist/main/src/client/ButtplugClientDeviceCommand.js.map +1 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.d.ts +18 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.js +166 -0
- package/dist/main/src/client/ButtplugClientDeviceFeature.js.map +1 -0
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -8
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js +1 -4
- package/dist/main/src/client/ButtplugNodeWebsocketClientConnector.js.map +1 -1
- package/dist/main/src/core/Exceptions.js +27 -9
- package/dist/main/src/core/Exceptions.js.map +1 -1
- package/dist/main/src/core/Logging.js +12 -6
- package/dist/main/src/core/Logging.js.map +1 -1
- package/dist/main/src/core/Messages.d.ts +118 -228
- package/dist/main/src/core/Messages.js +51 -404
- package/dist/main/src/core/Messages.js.map +1 -1
- package/dist/main/src/index.d.ts +2 -2
- package/dist/main/src/index.js +4 -2
- package/dist/main/src/index.js.map +1 -1
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js +40 -52
- package/dist/main/src/utils/ButtplugBrowserWebsocketConnector.js.map +1 -1
- package/dist/main/src/utils/ButtplugMessageSorter.js +27 -15
- package/dist/main/src/utils/ButtplugMessageSorter.js.map +1 -1
- package/dist/main/src/utils/Utils.js +1 -2
- package/dist/main/src/utils/Utils.js.map +1 -1
- package/dist/web/buttplug.js +1 -38
- package/dist/web/buttplug.mjs +595 -1984
- package/dist/web/client/ButtplugBrowserWebsocketClientConnector.d.ts +0 -7
- package/dist/web/client/{Client.d.ts → ButtplugClient.d.ts} +3 -11
- package/dist/web/client/ButtplugClientConnectorException.d.ts +0 -7
- package/dist/web/client/ButtplugClientDevice.d.ts +14 -29
- package/dist/web/client/ButtplugClientDeviceCommand.d.ts +42 -0
- package/dist/web/client/ButtplugClientDeviceFeature.d.ts +18 -0
- package/dist/web/client/ButtplugNodeWebsocketClientConnector.d.ts +1 -15
- package/dist/web/client/IButtplugClientConnector.d.ts +0 -7
- package/dist/web/core/Exceptions.d.ts +1 -1
- package/dist/web/core/Logging.d.ts +0 -7
- package/dist/web/core/Messages.d.ts +118 -227
- package/dist/web/index.d.ts +2 -2
- package/dist/web/utils/ButtplugBrowserWebsocketConnector.d.ts +0 -7
- package/examples/node/SYNC_MANIFEST.md +105 -0
- package/examples/node/application-example.ts +213 -0
- package/examples/node/async-example.ts +124 -0
- package/examples/node/connection-example.ts +76 -0
- package/examples/node/device-control-example.ts +131 -0
- package/examples/node/device-enumeration-example.ts +86 -0
- package/examples/node/device-info-example.ts +131 -0
- package/examples/node/errors-example.ts +166 -0
- package/examples/node/package-lock.json +281 -0
- package/examples/node/package.json +25 -0
- package/examples/node/remote-connector-example.ts +84 -0
- package/examples/node/tsconfig.json +14 -0
- package/examples/web/application-example.js +197 -0
- package/examples/web/async-example.js +90 -0
- package/examples/web/device-control-example.js +87 -0
- package/examples/web/device-enumeration-example.js +49 -0
- package/examples/web/device-info-example.js +100 -0
- package/examples/web/errors-example.js +110 -0
- package/examples/web/index.html +55 -0
- package/examples/web/logging.js +42 -0
- package/examples/web/ping-timeout-example.js +59 -0
- package/examples/web/remote-connector-example.js +68 -0
- package/node-test.js +24 -0
- package/node-test.ts +23 -5
- package/package.json +85 -87
- package/src/client/ButtplugBrowserWebsocketClientConnector.ts +25 -25
- package/src/client/ButtplugClient.ts +242 -0
- package/src/client/ButtplugClientConnectorException.ts +16 -16
- package/src/client/ButtplugClientDevice.ts +178 -401
- package/src/client/ButtplugClientDeviceCommand.ts +112 -0
- package/src/client/ButtplugClientDeviceFeature.ts +138 -0
- package/src/client/ButtplugNodeWebsocketClientConnector.ts +17 -17
- package/src/client/IButtplugClientConnector.ts +18 -18
- package/src/core/Exceptions.ts +107 -101
- package/src/core/Logging.ts +197 -197
- package/src/core/Messages.ts +209 -480
- package/src/core/index.d.ts +4 -4
- package/src/index.ts +21 -19
- package/src/utils/ButtplugBrowserWebsocketConnector.ts +89 -92
- package/src/utils/ButtplugMessageSorter.ts +66 -65
- package/src/utils/Utils.ts +3 -3
- package/tsconfig.json +22 -22
- package/tsfmt.json +14 -14
- package/tslint.json +27 -27
- package/typedocconfig.js +6 -6
- package/vite.config.ts +26 -26
- package/dist/main/src/client/Client.js +0 -242
- package/dist/main/src/client/Client.js.map +0 -1
- package/dist/main/src/core/MessageUtils.d.ts +0 -10
- package/dist/main/src/core/MessageUtils.js +0 -65
- package/dist/main/src/core/MessageUtils.js.map +0 -1
- package/dist/web/core/MessageUtils.d.ts +0 -10
- package/doc/.nojekyll +0 -1
- package/doc/assets/highlight.css +0 -22
- package/doc/assets/main.js +0 -58
- package/doc/assets/search.js +0 -1
- package/doc/assets/style.css +0 -1280
- package/doc/classes/ButtplugBrowserWebsocketClientConnector.html +0 -234
- package/doc/classes/ButtplugClient.html +0 -331
- package/doc/classes/ButtplugClientConnectorException.html +0 -216
- package/doc/classes/ButtplugClientDevice.html +0 -489
- package/doc/classes/ButtplugDeviceError.html +0 -218
- package/doc/classes/ButtplugDeviceMessage.html +0 -165
- package/doc/classes/ButtplugError.html +0 -220
- package/doc/classes/ButtplugInitError.html +0 -218
- package/doc/classes/ButtplugLogger.html +0 -288
- package/doc/classes/ButtplugMessage.html +0 -147
- package/doc/classes/ButtplugMessageError.html +0 -218
- package/doc/classes/ButtplugMessageSorter.html +0 -128
- package/doc/classes/ButtplugNodeWebsocketClientConnector.html +0 -239
- package/doc/classes/ButtplugPingError.html +0 -218
- package/doc/classes/ButtplugSystemMessage.html +0 -150
- package/doc/classes/ButtplugUnknownError.html +0 -218
- package/doc/classes/DeviceAdded.html +0 -186
- package/doc/classes/DeviceInfo.html +0 -114
- package/doc/classes/DeviceList.html +0 -160
- package/doc/classes/DeviceRemoved.html +0 -158
- package/doc/classes/Error.html +0 -179
- package/doc/classes/GenericDeviceMessageAttributes.html +0 -107
- package/doc/classes/GenericMessageSubcommand.html +0 -90
- package/doc/classes/LinearCmd.html +0 -187
- package/doc/classes/LogMessage.html +0 -134
- package/doc/classes/MessageAttributes.html +0 -160
- package/doc/classes/Ok.html +0 -151
- package/doc/classes/Ping.html +0 -151
- package/doc/classes/RawDeviceMessageAttributes.html +0 -86
- package/doc/classes/RawReadCmd.html +0 -188
- package/doc/classes/RawReading.html +0 -179
- package/doc/classes/RawSubscribeCmd.html +0 -170
- package/doc/classes/RawUnsubscribeCmd.html +0 -170
- package/doc/classes/RawWriteCmd.html +0 -188
- package/doc/classes/RequestDeviceList.html +0 -151
- package/doc/classes/RequestServerInfo.html +0 -169
- package/doc/classes/RotateCmd.html +0 -187
- package/doc/classes/RotateSubcommand.html +0 -108
- package/doc/classes/ScalarCmd.html +0 -170
- package/doc/classes/ScalarSubcommand.html +0 -108
- package/doc/classes/ScanningFinished.html +0 -146
- package/doc/classes/SensorDeviceMessageAttributes.html +0 -107
- package/doc/classes/SensorReadCmd.html +0 -179
- package/doc/classes/SensorReading.html +0 -188
- package/doc/classes/ServerInfo.html +0 -178
- package/doc/classes/StartScanning.html +0 -151
- package/doc/classes/StopAllDevices.html +0 -151
- package/doc/classes/StopDeviceCmd.html +0 -161
- package/doc/classes/StopScanning.html +0 -151
- package/doc/classes/VectorSubcommand.html +0 -108
- package/doc/enums/ActuatorType.html +0 -104
- package/doc/enums/ButtplugLogLevel.html +0 -97
- package/doc/enums/ErrorClass.html +0 -90
- package/doc/enums/SensorType.html +0 -90
- package/doc/functions/FromJSON.html +0 -113
- package/doc/index.html +0 -184
- package/doc/interfaces/IButtplugClientConnector.html +0 -137
- package/doc/modules.html +0 -176
- package/doc/variables/DEFAULT_MESSAGE_ID.html +0 -104
- package/doc/variables/MAX_ID.html +0 -104
- package/doc/variables/MESSAGE_SPEC_VERSION.html +0 -104
- package/doc/variables/SYSTEM_MESSAGE_ID.html +0 -104
- package/src/client/Client.ts +0 -276
- package/src/core/MessageUtils.ts +0 -48
package/src/core/Logging.ts
CHANGED
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about
|
|
3
|
-
* the project. Licensed under the BSD 3-Clause license. See LICENSE file in the
|
|
4
|
-
* project root for full license information.
|
|
5
|
-
*
|
|
6
|
-
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { EventEmitter } from 'eventemitter3';
|
|
10
|
-
|
|
11
|
-
export enum ButtplugLogLevel {
|
|
12
|
-
Off,
|
|
13
|
-
Error,
|
|
14
|
-
Warn,
|
|
15
|
-
Info,
|
|
16
|
-
Debug,
|
|
17
|
-
Trace,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Representation of log messages for the internal logging utility.
|
|
22
|
-
*/
|
|
23
|
-
export class LogMessage {
|
|
24
|
-
/** Timestamp for the log message */
|
|
25
|
-
private timestamp: string;
|
|
26
|
-
|
|
27
|
-
/** Log Message */
|
|
28
|
-
private logMessage: string;
|
|
29
|
-
|
|
30
|
-
/** Log Level */
|
|
31
|
-
private logLevel: ButtplugLogLevel;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param logMessage Log message.
|
|
35
|
-
* @param logLevel: Log severity level.
|
|
36
|
-
*/
|
|
37
|
-
public constructor(logMessage: string, logLevel: ButtplugLogLevel) {
|
|
38
|
-
const a = new Date();
|
|
39
|
-
const hour = a.getHours();
|
|
40
|
-
const min = a.getMinutes();
|
|
41
|
-
const sec = a.getSeconds();
|
|
42
|
-
this.timestamp = `${hour}:${min}:${sec}`;
|
|
43
|
-
this.logMessage = logMessage;
|
|
44
|
-
this.logLevel = logLevel;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Returns the log message.
|
|
49
|
-
*/
|
|
50
|
-
public get Message() {
|
|
51
|
-
return this.logMessage;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Returns the log message level.
|
|
56
|
-
*/
|
|
57
|
-
public get LogLevel() {
|
|
58
|
-
return this.logLevel;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Returns the log message timestamp.
|
|
63
|
-
*/
|
|
64
|
-
public get Timestamp() {
|
|
65
|
-
return this.timestamp;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns a formatted string with timestamp, level, and message.
|
|
70
|
-
*/
|
|
71
|
-
public get FormattedMessage() {
|
|
72
|
-
return `${ButtplugLogLevel[this.logLevel]} : ${this.timestamp} : ${
|
|
73
|
-
this.logMessage
|
|
74
|
-
}`;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Simple, global logging utility for the Buttplug client and server. Keeps an
|
|
80
|
-
* internal static reference to an instance of itself (singleton pattern,
|
|
81
|
-
* basically), and allows message logging throughout the module.
|
|
82
|
-
*/
|
|
83
|
-
export class ButtplugLogger extends EventEmitter {
|
|
84
|
-
/** Singleton instance for the logger */
|
|
85
|
-
protected static sLogger: ButtplugLogger | undefined = undefined;
|
|
86
|
-
/** Sets maximum log level to log to console */
|
|
87
|
-
protected maximumConsoleLogLevel: ButtplugLogLevel = ButtplugLogLevel.Off;
|
|
88
|
-
/** Sets maximum log level for all log messages */
|
|
89
|
-
protected maximumEventLogLevel: ButtplugLogLevel = ButtplugLogLevel.Off;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Returns the stored static instance of the logger, creating one if it
|
|
93
|
-
* doesn't currently exist.
|
|
94
|
-
*/
|
|
95
|
-
public static get Logger(): ButtplugLogger {
|
|
96
|
-
if (ButtplugLogger.sLogger === undefined) {
|
|
97
|
-
ButtplugLogger.sLogger = new ButtplugLogger();
|
|
98
|
-
}
|
|
99
|
-
return this.sLogger!;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Constructor. Can only be called internally since we regulate ButtplugLogger
|
|
104
|
-
* ownership.
|
|
105
|
-
*/
|
|
106
|
-
protected constructor() {
|
|
107
|
-
super();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Set the maximum log level to output to console.
|
|
112
|
-
*/
|
|
113
|
-
public get MaximumConsoleLogLevel() {
|
|
114
|
-
return this.maximumConsoleLogLevel;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get the maximum log level to output to console.
|
|
119
|
-
*/
|
|
120
|
-
public set MaximumConsoleLogLevel(buttplugLogLevel: ButtplugLogLevel) {
|
|
121
|
-
this.maximumConsoleLogLevel = buttplugLogLevel;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Set the global maximum log level
|
|
126
|
-
*/
|
|
127
|
-
public get MaximumEventLogLevel() {
|
|
128
|
-
return this.maximumEventLogLevel;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Get the global maximum log level
|
|
133
|
-
*/
|
|
134
|
-
public set MaximumEventLogLevel(logLevel: ButtplugLogLevel) {
|
|
135
|
-
this.maximumEventLogLevel = logLevel;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Log new message at Error level.
|
|
140
|
-
*/
|
|
141
|
-
public Error(msg: string) {
|
|
142
|
-
this.AddLogMessage(msg, ButtplugLogLevel.Error);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Log new message at Warn level.
|
|
147
|
-
*/
|
|
148
|
-
public Warn(msg: string) {
|
|
149
|
-
this.AddLogMessage(msg, ButtplugLogLevel.Warn);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Log new message at Info level.
|
|
154
|
-
*/
|
|
155
|
-
public Info(msg: string) {
|
|
156
|
-
this.AddLogMessage(msg, ButtplugLogLevel.Info);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Log new message at Debug level.
|
|
161
|
-
*/
|
|
162
|
-
public Debug(msg: string) {
|
|
163
|
-
this.AddLogMessage(msg, ButtplugLogLevel.Debug);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Log new message at Trace level.
|
|
168
|
-
*/
|
|
169
|
-
public Trace(msg: string) {
|
|
170
|
-
this.AddLogMessage(msg, ButtplugLogLevel.Trace);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Checks to see if message should be logged, and if so, adds message to the
|
|
175
|
-
* log buffer. May also print message and emit event.
|
|
176
|
-
*/
|
|
177
|
-
protected AddLogMessage(msg: string, level: ButtplugLogLevel) {
|
|
178
|
-
// If nothing wants the log message we have, ignore it.
|
|
179
|
-
if (
|
|
180
|
-
level > this.maximumEventLogLevel &&
|
|
181
|
-
level > this.maximumConsoleLogLevel
|
|
182
|
-
) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const logMsg = new LogMessage(msg, level);
|
|
186
|
-
// Clients and console logging may have different needs. For instance, it
|
|
187
|
-
// could be that the client requests trace level, while all we want in the
|
|
188
|
-
// console is info level. This makes sure the client can't also spam the
|
|
189
|
-
// console.
|
|
190
|
-
if (level <= this.maximumConsoleLogLevel) {
|
|
191
|
-
console.log(logMsg.FormattedMessage);
|
|
192
|
-
}
|
|
193
|
-
if (level <= this.maximumEventLogLevel) {
|
|
194
|
-
this.emit('log', logMsg);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
1
|
+
/*!
|
|
2
|
+
* Buttplug JS Source Code File - Visit https://buttplug.io for more info about
|
|
3
|
+
* the project. Licensed under the BSD 3-Clause license. See LICENSE file in the
|
|
4
|
+
* project root for full license information.
|
|
5
|
+
*
|
|
6
|
+
* @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { EventEmitter } from 'eventemitter3';
|
|
10
|
+
|
|
11
|
+
export enum ButtplugLogLevel {
|
|
12
|
+
Off,
|
|
13
|
+
Error,
|
|
14
|
+
Warn,
|
|
15
|
+
Info,
|
|
16
|
+
Debug,
|
|
17
|
+
Trace,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Representation of log messages for the internal logging utility.
|
|
22
|
+
*/
|
|
23
|
+
export class LogMessage {
|
|
24
|
+
/** Timestamp for the log message */
|
|
25
|
+
private timestamp: string;
|
|
26
|
+
|
|
27
|
+
/** Log Message */
|
|
28
|
+
private logMessage: string;
|
|
29
|
+
|
|
30
|
+
/** Log Level */
|
|
31
|
+
private logLevel: ButtplugLogLevel;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param logMessage Log message.
|
|
35
|
+
* @param logLevel: Log severity level.
|
|
36
|
+
*/
|
|
37
|
+
public constructor(logMessage: string, logLevel: ButtplugLogLevel) {
|
|
38
|
+
const a = new Date();
|
|
39
|
+
const hour = a.getHours();
|
|
40
|
+
const min = a.getMinutes();
|
|
41
|
+
const sec = a.getSeconds();
|
|
42
|
+
this.timestamp = `${hour}:${min}:${sec}`;
|
|
43
|
+
this.logMessage = logMessage;
|
|
44
|
+
this.logLevel = logLevel;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the log message.
|
|
49
|
+
*/
|
|
50
|
+
public get Message() {
|
|
51
|
+
return this.logMessage;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns the log message level.
|
|
56
|
+
*/
|
|
57
|
+
public get LogLevel() {
|
|
58
|
+
return this.logLevel;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the log message timestamp.
|
|
63
|
+
*/
|
|
64
|
+
public get Timestamp() {
|
|
65
|
+
return this.timestamp;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns a formatted string with timestamp, level, and message.
|
|
70
|
+
*/
|
|
71
|
+
public get FormattedMessage() {
|
|
72
|
+
return `${ButtplugLogLevel[this.logLevel]} : ${this.timestamp} : ${
|
|
73
|
+
this.logMessage
|
|
74
|
+
}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Simple, global logging utility for the Buttplug client and server. Keeps an
|
|
80
|
+
* internal static reference to an instance of itself (singleton pattern,
|
|
81
|
+
* basically), and allows message logging throughout the module.
|
|
82
|
+
*/
|
|
83
|
+
export class ButtplugLogger extends EventEmitter {
|
|
84
|
+
/** Singleton instance for the logger */
|
|
85
|
+
protected static sLogger: ButtplugLogger | undefined = undefined;
|
|
86
|
+
/** Sets maximum log level to log to console */
|
|
87
|
+
protected maximumConsoleLogLevel: ButtplugLogLevel = ButtplugLogLevel.Off;
|
|
88
|
+
/** Sets maximum log level for all log messages */
|
|
89
|
+
protected maximumEventLogLevel: ButtplugLogLevel = ButtplugLogLevel.Off;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the stored static instance of the logger, creating one if it
|
|
93
|
+
* doesn't currently exist.
|
|
94
|
+
*/
|
|
95
|
+
public static get Logger(): ButtplugLogger {
|
|
96
|
+
if (ButtplugLogger.sLogger === undefined) {
|
|
97
|
+
ButtplugLogger.sLogger = new ButtplugLogger();
|
|
98
|
+
}
|
|
99
|
+
return this.sLogger!;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Constructor. Can only be called internally since we regulate ButtplugLogger
|
|
104
|
+
* ownership.
|
|
105
|
+
*/
|
|
106
|
+
protected constructor() {
|
|
107
|
+
super();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Set the maximum log level to output to console.
|
|
112
|
+
*/
|
|
113
|
+
public get MaximumConsoleLogLevel() {
|
|
114
|
+
return this.maximumConsoleLogLevel;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the maximum log level to output to console.
|
|
119
|
+
*/
|
|
120
|
+
public set MaximumConsoleLogLevel(buttplugLogLevel: ButtplugLogLevel) {
|
|
121
|
+
this.maximumConsoleLogLevel = buttplugLogLevel;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Set the global maximum log level
|
|
126
|
+
*/
|
|
127
|
+
public get MaximumEventLogLevel() {
|
|
128
|
+
return this.maximumEventLogLevel;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the global maximum log level
|
|
133
|
+
*/
|
|
134
|
+
public set MaximumEventLogLevel(logLevel: ButtplugLogLevel) {
|
|
135
|
+
this.maximumEventLogLevel = logLevel;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Log new message at Error level.
|
|
140
|
+
*/
|
|
141
|
+
public Error(msg: string) {
|
|
142
|
+
this.AddLogMessage(msg, ButtplugLogLevel.Error);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Log new message at Warn level.
|
|
147
|
+
*/
|
|
148
|
+
public Warn(msg: string) {
|
|
149
|
+
this.AddLogMessage(msg, ButtplugLogLevel.Warn);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Log new message at Info level.
|
|
154
|
+
*/
|
|
155
|
+
public Info(msg: string) {
|
|
156
|
+
this.AddLogMessage(msg, ButtplugLogLevel.Info);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Log new message at Debug level.
|
|
161
|
+
*/
|
|
162
|
+
public Debug(msg: string) {
|
|
163
|
+
this.AddLogMessage(msg, ButtplugLogLevel.Debug);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Log new message at Trace level.
|
|
168
|
+
*/
|
|
169
|
+
public Trace(msg: string) {
|
|
170
|
+
this.AddLogMessage(msg, ButtplugLogLevel.Trace);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Checks to see if message should be logged, and if so, adds message to the
|
|
175
|
+
* log buffer. May also print message and emit event.
|
|
176
|
+
*/
|
|
177
|
+
protected AddLogMessage(msg: string, level: ButtplugLogLevel) {
|
|
178
|
+
// If nothing wants the log message we have, ignore it.
|
|
179
|
+
if (
|
|
180
|
+
level > this.maximumEventLogLevel &&
|
|
181
|
+
level > this.maximumConsoleLogLevel
|
|
182
|
+
) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const logMsg = new LogMessage(msg, level);
|
|
186
|
+
// Clients and console logging may have different needs. For instance, it
|
|
187
|
+
// could be that the client requests trace level, while all we want in the
|
|
188
|
+
// console is info level. This makes sure the client can't also spam the
|
|
189
|
+
// console.
|
|
190
|
+
if (level <= this.maximumConsoleLogLevel) {
|
|
191
|
+
console.log(logMsg.FormattedMessage);
|
|
192
|
+
}
|
|
193
|
+
if (level <= this.maximumEventLogLevel) {
|
|
194
|
+
this.emit('log', logMsg);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|