feat(wetsock) auto parse incoming messages as JSON
This commit is contained in:
@@ -32,6 +32,14 @@ export default class WetSock {
|
||||
|
||||
handleMessage(ws, message) {
|
||||
const client = this.#clients.get(ws.data.clientId);
|
||||
|
||||
try {
|
||||
const messageData = JSON.parse(message);
|
||||
if(typeof(messageData) == 'object' && messageData.constructor.name == 'Object') {
|
||||
message = messageData;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
for(const plugin of this.#plugins) {
|
||||
if(plugin.onMessage(ws.data.clientId, message)) break; // plugin consumes message by returning a truthy value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user