JSON-stringifies and sends a frame.
(frame: object)
| 101 | |
| 102 | /** JSON-stringifies and sends a frame. */ |
| 103 | send(frame: object): void { |
| 104 | if (!this.ws) throw new Error('ws not open'); |
| 105 | this.ws.send(JSON.stringify(frame)); |
| 106 | recordReportEvent( |
| 107 | { kind: 'ws', direction: 'out', url: this.opts.url, frame }, |
| 108 | { reportDir: this.opts.reportDir }, |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | /** Register a frame subscriber. Returns an unsubscribe handle. */ |
| 113 | onFrame(handler: (f: AnyFrame) => void): () => void { |