當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript socket.io-client類代碼示例

本文整理匯總了TypeScript中socket.io-client的典型用法代碼示例。如果您正苦於以下問題:TypeScript io-client類的具體用法?TypeScript io-client怎麽用?TypeScript io-client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了io-client類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

 constructor() {
     super();
     this.socket = io(HOST);
     this._app = feathers()
         .configure(socketio(this.socket))
         .configure(hooks())
 }
開發者ID:yberstad,項目名稱:angular2-quickstart,代碼行數:7,代碼來源:feathers.service.ts

示例2: constructor

 constructor() {
   this.socket = io(HOST);
   this._app = feathers()
     .configure(socketio(this.socket))
     .configure(hooks())
     .configure(authentication({ storage: localstorage }));
 }
開發者ID:s-robertson,項目名稱:things-front,代碼行數:7,代碼來源:feathers.service.ts

示例3: chimes

 chimes() {
   const socket = io.connect('http://chimes-us.teropa.info/chimes');
   return Observable.create((observer) => {
     socket.on('chime', (chime) => observer.next(chime));
     return () => socket.close();
   });
 }
開發者ID:TheLarkInn,項目名稱:windchimes,代碼行數:7,代碼來源:remote.service.ts

示例4: return

    return (dispatch, getState) => {
        dispatch({ type: 'CONNECTING' });
        // const socket = io({
        //     path: '/api/socket.io'
        // });
        const socket = io();

        socket.on('connect', () => {
            let username = getState().user.username;
            if (username) {
                socket.emit('login', { username }, (resp: Protocol.Response) => {
                    if (!resp.success) {
                        dispatch({ type: 'LOGOUT' });
                    } else {
                        dispatch({
                            type: 'CONNECTED',
                            payload: socket
                        });
                    }
                });
            } else {
                dispatch({
                    type: 'CONNECTED',
                    payload: socket
                });
            }
        });

        socket.on('disconnect', () => {
            dispatch({ type: 'DISCONNECTED' });
        });

        socket.on('canvas:history:new', (event: Protocol.NewHistoryEvent) => {
            dispatch({
                type: 'CANVAS_HISTORY_NEW',
                payload: event.entry
            });
        });

        socket.on('canvas:user:join', (event: Protocol.UserEvent) => {
            dispatch({
                type: 'CANVAS_USER_JOIN',
                payload: event.user
            });
        });

        socket.on('canvas:user:leave', (event: Protocol.UserEvent) => {
            dispatch({
                type: 'CANVAS_USER_LEAVE',
                payload: event.user
            });
        });

        socket.on('canvas:user:update', (event: Protocol.UserEvent) => {
            dispatch({
                type: 'CANVAS_USER_UPDATE',
                payload: event.user
            });
        });
    }
開發者ID:cschram,項目名稱:drawgaiden,代碼行數:60,代碼來源:connection.ts

示例5: initSocket

export function initSocket(context: Context) {
  const core = context.getMethodsOf<CoreSpec>('core');
  if (!core.isDevServerOn()) {
    return;
  }

  socket = io();
  socket.on(SERVER_MESSAGE_EVENT_NAME, handleServerMessage);
  socket.on(RENDERER_MESSAGE_EVENT_NAME, handleRendererMessage);

  return () => {
    if (socket) {
      socket.off(SERVER_MESSAGE_EVENT_NAME, handleServerMessage);
      socket.off(RENDERER_MESSAGE_EVENT_NAME, handleRendererMessage);
      socket = undefined;
    }
  };

  function handleServerMessage(msg: Message) {
    context.emit('serverMessage', msg);
  }

  function handleRendererMessage(msg: Message) {
    context.emit('rendererResponse', msg);
  }
}
開發者ID:skidding,項目名稱:cosmos,代碼行數:26,代碼來源:socket.ts

示例6: tweets

 tweets() {
   const socket = io.connect('http://tweets-us.teropa.info/tweets');
   return Observable.create((observer) => {
     socket.on('tweet', (tweet) => observer.next(tweet));
     return () => socket.close();
   });
 }
開發者ID:1337programming,項目名稱:twitter-sentiment-analysis,代碼行數:7,代碼來源:remote.service.ts

示例7: constructor

  constructor(opts: { port?: number; namespace?: string } = {}) {
    this.port = opts.port;
    this.namespace = opts.namespace || 'admin';

    if (!AppContext.isServer && !WsAdapter.io) {
      WsAdapter.io = connect(
        '/admin',
        { secure: true, reconnectionDelay: 10e3, reconnectionDelayMax: 60e3 },
      );

      WsAdapter.io.on('connect', () => {
        logger.log('[connect]', { id: WsAdapter.io.id, AppContext });
        AppContext.dispatch(appActions.heartbeat());
      });
      WsAdapter.io.on('reconnect', () => {
        logger.log('[reconnect]', { id: WsAdapter.io.id, AppContext });
        AppContext.dispatch(appActions.heartbeat());
      });
      WsAdapter.io.on('disconnect', () => {
        const { heartbeat } = AppContext.store.select(state => state.app);
        logger.error('[disconnect]', { id: WsAdapter.io.id, heartbeat });
        if (heartbeat) {
          AppContext.dispatch(appActions.heartbeatStop());
        }
      });
      WsAdapter.io.on('error', error => {
        const { heartbeat } = AppContext.store.select(state => state.app);
        logger.error('[error]', { id: WsAdapter.io.id, heartbeat, error });
        if (heartbeat) {
          AppContext.dispatch(appActions.heartbeatStop());
        }
      });
    }
  }
開發者ID:danielwii,項目名稱:asuna-admin,代碼行數:34,代碼來源:ws.ts

示例8: Promise

  it(`should handle message (2 gateways)`, async () => {
    app = await createNestApp(ApplicationGateway, NamespaceGateway);
    await app.listenAsync(3000);

    ws = io.connect('http://localhost:8080');
    io.connect('http://localhost:8080/test').emit('push', {})
    ws.emit('push', {
      test: 'test',
    });
    await new Promise(resolve =>
      ws.on('pop', data => {
        expect(data.test).to.be.eql('test');
        resolve();
      }),
    );
  });
開發者ID:a1r0,項目名稱:nest,代碼行數:16,代碼來源:gateway.spec.ts

示例9: constructor

 constructor(http: Http, threadService: ThreadService) {
   this._io = io.connect();
   this._http = http;
   this._threadService = threadService;
   this.messages = new Observable(observer => this._messagesObservers = observer).share();
   this._dataStore = { messages: [] };
   this._socketOn();
 }
開發者ID:Crazy-Ace,項目名稱:MEAN-Blueprints,代碼行數:8,代碼來源:message.service.ts

示例10:

 }).then((t: PushToken) => {
   this.socket = io.connect('http://'+SOCKET_LINK);
   this._storage.setToStorage('@device:token' , {token: t.token})
   // alert('token:' + t.token)
   this.socket.emit('save-device' , {affiliate: resJson.result.affiliate , token: t.token , server:'AU'})
   this._store.dispatch(this._userAction.addUserToStorage({key:resJson.result.key , user:resJson.result.user}))
   this._loader.loaded()
   this.navCtrl.setRoot(ShowMoreJobPage)
 });
開發者ID:hivoova,項目名稱:travelsafe-operator,代碼行數:9,代碼來源:register.ts


注:本文中的socket.io-client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。