Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import * as utils from 'sportident/lib/utils'; import {ISiExternalApplication, SiExternalApplicationEvents, SiExternalApplicationReceiveEvent} from 'sportident-testbench-shell/lib/ISiExternalApplication'; export class SiExternalApplication implements ISiExternalApplication { private ws: WebSocket; private pollInterval: unknown; constructor(url: string) { this.ws = new WebSocket('ws://127.0.0.1:41271/si-external-application'); this.ws.onopen = () => { console.log('Websocket openend'); this.ws.send(url); }; this.ws.onerror = (err) => { console.log('WebSocket Error ', err); }; this.ws.onmessage = (e) => { Iif (e.data.length > 0) { this.handleSocketReceive(e.data); } }; this.pollInterval = setInterval(() => { this.ws.send(''); }, 1000); } handleSocketReceive(data: string): void { const uint8Data = JSON.parse(data) as number[]; this.dispatchEvent( 'receive', new SiExternalApplicationReceiveEvent(this, uint8Data), ); } send(uint8Data: number[]): void { const dataString = JSON.stringify([...uint8Data]); this.ws.send(dataString); } close(): void { clearInterval(this.pollInterval as Parameters<typeof clearInterval>[0]); this.ws.close(); } } // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface SiExternalApplication extends utils.EventTarget<SiExternalApplicationEvents> {} utils.applyMixins(SiExternalApplication, [utils.EventTarget]); |