Skip to content
Snippets Groups Projects
Verified Commit 8cfa2f1c authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new Webconnect and Message

parent 52eb6caa
Branches
Tags
No related merge requests found
/**
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
* Node module: @schukai/monster
* This file is licensed under the AGPLv3 License.
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/
import {Base} from "../../types/base.mjs";
import {validateObject, validateString} from "../../types/validate.mjs";
export {Message}
const dataSymbol = Symbol("@@data");
/**
* This class represents a WebSocket message.
*/
class Message extends Base {
/**
* @param {Object} data
* @throws {TypeError} value is not a object
*/
constructor(data) {
super();
this[dataSymbol] = validateObject(data);
}
/**
* Returns the raw message.
*
* @returns {object}
*/
getData() {
return this[dataSymbol];
}
/**
* @returns {*}
*/
toJSON() {
return this[dataSymbol];
}
/**
* @param {string} json
* @returns {Message}
* @throws {TypeError} value is not a string
*/
static fromJSON(json) {
validateString(json);
return new Message(JSON.parse(json));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment