MCPcopy Create free account
hub / github.com/msgbyte/tailchat / createSocket

Function createSocket

client/shared/api/socket.ts:205–236  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

203 * @param token Token
204 */
205export function createSocket(token: string): Promise<AppSocket> {
206 if (!_isNil(_socket)) {
207 _socket.close();
208 }
209
210 return new Promise((resolve, reject) => {
211 const disableMsgpack = getGlobalConfig().disableMsgpack;
212 _socket = io(getServiceUrl(), {
213 transports: ['websocket'],
214 auth: {
215 token,
216 },
217 forceNew: true,
218 parser: disableMsgpack ? undefined : msgpackParser,
219 });
220 _socket.once('connect', () => {
221 // 连接成功
222 const appSocket = new AppSocket(_socket);
223 appSocket.setupSocketStatusTip();
224 resolve(appSocket);
225 });
226 _socket.once('error', () => {
227 reject();
228 });
229
230 if (isDevelopment) {
231 _socket.onAny((...args) => {
232 console.debug('Receive Notify:', args);
233 });
234 }
235 });
236}

Callers 1

useAppStateFunction · 0.50

Calls 5

setupSocketStatusTipMethod · 0.95
getGlobalConfigFunction · 0.90
rejectFunction · 0.85
closeMethod · 0.80
onceMethod · 0.80

Tested by

no test coverage detected