import MWSE from "./index"; import { Message } from "./WSTSProtocol"; export default class EventPool { public wsts : MWSE; public events : Map = new Map(); public signals : Map = new Map(); public requests : Map = new Map(); public count = 0; constructor(wsts:MWSE){ this.wsts = wsts; } public request(msg: Message) : Promise { return new Promise((ok,rej) => { let id = ++this.count; this.events.set(id,[ (data:any) => { ok(data); }, (data:any) => { rej(data); } ]); this.wsts.WSTSProtocol.SendRequest(msg, id); }) } public stream(msg: Message, callback: Function) { let id = ++this.count; this.wsts.WSTSProtocol.StartStream(msg, id); this.events.set(id,[ (data:any) => { callback(data); }, () => { } ]); } public signal(event: string, callback: Function) { let T = this.signals.get(event); if(!T) { this.signals.set(event, [callback]); }else{ T.push(callback); } } }