MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / disconnect

Method disconnect

packages/message/window_message.ts:188–204  ·  view source on GitHub ↗
(ignoreAlreadyDisconnected: boolean)

Source from the content-addressed store, hash-verified

186 }
187
188 disconnect(ignoreAlreadyDisconnected: boolean) {
189 if (!this.target) {
190 if (ignoreAlreadyDisconnected) return;
191 console.warn("Attempted to disconnect on a disconnected Target.");
192 // 重复 disconnect() 不应该屏蔽错误
193 throw new Error("Attempted to disconnect on a disconnected Target.");
194 }
195 this.isSelfDisconnected = true;
196 const body: WindowMessageBody<TMessage> = {
197 messageId: this.messageId,
198 type: "disconnect",
199 data: null,
200 };
201 this.target.postMessage(body);
202 // Note: .disconnect() will NOT automatically trigger the 'cleanup' listener
203 listenerMgr.emit(`cleanup:${this.listenerId}`);
204 }
205
206 onDisconnect(callback: (isSelfDisconnected: boolean) => void) {
207 if (!this.target) {

Callers

nothing calls this directly

Calls 3

warnMethod · 0.80
postMessageMethod · 0.65
emitMethod · 0.65

Tested by

no test coverage detected