12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { Socket } from "socket.io"
- import * as U from '../Utils'
- import * as I from '../Interfaces'
- import * as socketio from 'socket.io-client'
-
- export class PromiseIOClient {
-
- static connect = (port: number, host = "localhost", protocol : 'http' | 'https' = "http"): Promise<I.Socket> => new Promise((res, rej) => {
- try {
- const address = `${host}:${port}`
- const socket = socketio(`${protocol}://${address}`, {
- reconnectionAttempts: 2,
- reconnectionDelay: 200,
- timeout: 450,
- reconnection: false,
- })
-
- socket.on('connect_error', e => {
- sock.emit('error', e)
- rej(e)
- })
-
- socket['address'] = address
- const sock = U.makePioSocket(socket)
- socket.on('connect', ()=>{
- res(sock)
- })
-
-
- /*
- socket.on('connect_timeout', ()=>console.log('connect_timeout'))
- socket.on('disconnect', ()=>console.log('disconnect'))
- socket.on('reconnect', ()=>console.log('reconnect'))
- socket.on('reconnect_attempt', ()=>console.log('reconnect_attempt'))
- socket.on('reconnecting', ()=>console.log('reconnecting'));
- socket.on('reconnect_failed', ()=>console.log('reconnect_failed'));
- socket.on('reconnecting', ()=>console.log('reconnecting'));
- */
- } catch (e) {
- rej(e)
- }
- })
- }
|