(src: SocketRTTSource)
| 30 | } |
| 31 | |
| 32 | private connectToSource(src: SocketRTTSource) { |
| 33 | this.hrTimer = new HrTimer(); |
| 34 | this.binaryFormatter = new BinaryFormatter(this.ptyTerm, this.options.encoding, this.options.scale); |
| 35 | src.once('disconnected', () => { this.onClose(); }); |
| 36 | src.on('error', (e) => { |
| 37 | const code: string = (e as any).code; |
| 38 | if (code === 'ECONNRESET') { |
| 39 | // Server closed the connection. We are done with this session |
| 40 | } else if (code === 'ECONNREFUSED') { |
| 41 | // We expect 'ECONNREFUSED' if the server has not yet started after all the retries |
| 42 | magentaWrite(`${e}\n.`, this.ptyTerm); |
| 43 | } else { |
| 44 | magentaWrite(`${e}\n`, this.ptyTerm); |
| 45 | } |
| 46 | }); |
| 47 | src.on('data', (data) => { this.onData(data); }); |
| 48 | |
| 49 | if (src.connError) { |
| 50 | this.source = src; |
| 51 | magentaWrite(`${src.connError.message}\n`, this.ptyTerm); |
| 52 | } else if (src.connected) { |
| 53 | this.source = src; |
| 54 | } else { |
| 55 | src.once('connected', () => { |
| 56 | this.source = src; |
| 57 | }); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private onClose() { |
| 62 | this.source = null; |
no test coverage detected