(token: string)
| 203 | * @param token Token |
| 204 | */ |
| 205 | export 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 | } |
no test coverage detected