(desc: string)
| 68 | } |
| 69 | |
| 70 | connectNow(desc: string) { |
| 71 | if (this.open || this.noReconnect) { |
| 72 | return; |
| 73 | } |
| 74 | this.lastReconnectTime = Date.now(); |
| 75 | dlog("try reconnect:", desc); |
| 76 | this.opening = true; |
| 77 | this.wsConn = newWebSocket( |
| 78 | this.baseHostPort + "/ws?stableid=" + encodeURIComponent(this.stableId), |
| 79 | this.eoOpts |
| 80 | ? { |
| 81 | [AuthKeyHeader]: this.eoOpts.authKey, |
| 82 | } |
| 83 | : null |
| 84 | ); |
| 85 | this.wsConn.onopen = (e: Event) => { |
| 86 | this.onopen(e); |
| 87 | }; |
| 88 | this.wsConn.onmessage = (e: MessageEvent) => { |
| 89 | this.onmessage(e); |
| 90 | }; |
| 91 | this.wsConn.onclose = (e: CloseEvent) => { |
| 92 | this.onclose(e); |
| 93 | }; |
| 94 | // turns out onerror is not necessary (onclose always follows onerror) |
| 95 | // this.wsConn.onerror = this.onerror; |
| 96 | } |
| 97 | |
| 98 | reconnect(forceClose?: boolean) { |
| 99 | if (this.noReconnect) { |
no test coverage detected