MCPcopy
hub / github.com/coder/mux / postMessage

Method postMessage

vscode/src/extension.ts:1239–1291  ·  view source on GitHub ↗
(message: ExtensionToWebviewMessage)

Source from the content-addressed store, hash-verified

1237 }
1238
1239 private postMessage(message: ExtensionToWebviewMessage): void {
1240 const shouldLog = message.type !== "chatEvent" && message.type !== "orpcStreamData";
1241
1242 if (!this.view) {
1243 if (shouldLog) {
1244 muxLogDebug("mux.chatView: -> drop postMessage (no view)", {
1245 traceId: this.traceId,
1246 type: message.type,
1247 });
1248 }
1249 return;
1250 }
1251
1252 if (!this.isWebviewReady) {
1253 if (shouldLog) {
1254 muxLogDebug("mux.chatView: -> drop postMessage (webview not ready)", {
1255 traceId: this.traceId,
1256 type: message.type,
1257 });
1258 }
1259 return;
1260 }
1261
1262 const seq = this.nextWebviewMessageSeq++;
1263 const meta = {
1264 traceId: this.traceId,
1265 seq,
1266 sentAtMs: Date.now(),
1267 };
1268
1269 const envelope: Record<string, unknown> = { __muxMeta: meta, ...message };
1270
1271 void this.view.webview.postMessage(envelope).then(
1272 (delivered) => {
1273 if (shouldLog) {
1274 muxLogDebug("mux.chatView: -> postMessage", {
1275 traceId: this.traceId,
1276 seq,
1277 type: message.type,
1278 delivered,
1279 });
1280 }
1281 },
1282 (error) => {
1283 muxLogWarn("mux.chatView: postMessage failed", {
1284 traceId: this.traceId,
1285 seq,
1286 type: message.type,
1287 error: formatError(error),
1288 });
1289 }
1290 );
1291 }
1292
1293 private async onWebviewMessage(raw: unknown): Promise<void> {
1294 const msg = parseWebviewToExtensionMessage(raw);

Callers 15

resolveWebviewViewMethod · 0.95
onWebviewMessageMethod · 0.95
refreshWorkspacesMethod · 0.95
pumpOrpcStreamMethod · 0.95
handleOrpcCallMethod · 0.95
openWorkspaceFromViewMethod · 0.95
createElectronClientFunction · 0.45
preload.tsFile · 0.45
runFunction · 0.45

Calls 3

muxLogDebugFunction · 0.85
muxLogWarnFunction · 0.85
formatErrorFunction · 0.70

Tested by

no test coverage detected