| 29 | } |
| 30 | |
| 31 | disconnect(ignoreAlreadyDisconnected?: boolean): void { |
| 32 | if (!this.EE) { |
| 33 | if (ignoreAlreadyDisconnected) return; |
| 34 | console.warn("Attempted to disconnect on a disconnected MockConnection."); |
| 35 | // 重复 disconnect() 不应该屏蔽错误 |
| 36 | throw new Error("Attempted to disconnect on a disconnected MockConnection."); |
| 37 | } |
| 38 | const EE = this.EE; |
| 39 | this.EE = null; |
| 40 | EE?.emit("disconnect", true); // MockMessageConnect 未有模拟由另一端触发 disconnect() 的情况 |
| 41 | } |
| 42 | |
| 43 | onDisconnect(callback: (isSelfDisconnected: boolean) => void) { |
| 44 | if (!this.EE) { |