MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / send

Function send

src/plugins/websocket/www/websocket.js:155–171  ·  view source on GitHub ↗
(instanceId, message, binary)

Source from the content-addressed store, hash-verified

153/** Utility functions, in-case you lost the websocketInstance returned from the connect function */
154
155const send = function(instanceId, message, binary) {
156 return new Promise((resolve, reject) => {
157 if (typeof message === 'string') {
158
159 if(binary) message = btoa(message);
160
161 exec(resolve, reject, "WebSocketPlugin", "send", [instanceId, message, binary]);
162 } else if (message instanceof ArrayBuffer || ArrayBuffer.isView(message)) {
163 const uint8Array = message instanceof ArrayBuffer ? new Uint8Array(message) : message;
164 const base64Message = btoa(String.fromCharCode.apply(null, uint8Array));
165
166 exec(resolve, reject, "WebSocketPlugin", "send", [instanceId, base64Message, true]);
167 } else {
168 reject(`Unsupported message type: ${typeof message}`);
169 }
170 });
171};
172
173/**
174 * Closes the WebSocket connection.

Callers

nothing calls this directly

Calls 1

execFunction · 0.50

Tested by

no test coverage detected