import { SocketHandler } from './Base/SocketHandler' ; import { createFromID } from '../Util/Header' ; import { serialize } from 'binarytf' ; export class NodeMessage { since public readonly client ! : SocketHandler ; since public readonly id ! : number ; since public data : any ; since public readonly receptive ! : boolean ; since param client param id param receptive param data public constructor ( client , id , receptive , data ) { Object . defineProperties ( this , { client : { value : client } , id : { value : id , enumerable : true } , receptive : { value : receptive , enumerable : true } } ) ; this . data = data ; } since param content public reply ( content ) { if ( this . receptive ) { this . client . socket ! . write ( createFromID ( this . id , false , serialize ( content ) ) ) ; } } since public freeze ( ) { return Object . freeze ( this ) ; } since public toJSON ( ) { return { id : this . id , data : this . data , receptive : this . receptive } ; } since public toString ( ) { return `NodeMessage<${ this . id }>` ; } }