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


TypeScript socket.io-client.default類代碼示例

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


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

示例1: it

  it("broadcast should send a data frame to all connected clients", (done) => {
    var clientA: SocketIO.Socket = Socket.connect('http://localhost:8080', options);
    var clientB: SocketIO.Socket = Socket.connect('http://localhost:8080', options);
    var socketServer: SocketIOServer = new SocketIOServer(null, server);
    var clients: number = 0;

    var version: string = 'foobase';
    var data: Object = {foo: 'foo'};
    var mutationId: Object = {id: -1};

    var dataHandler: Function = (frame: DataFrame) => {
      expect(frame.version).to.equal(version);
      expect(frame.key).to.deep.equal(key);
      expect(frame.data).to.deep.equal(data);
      expect(frame.mutationId).to.deep.equal(mutationId);
      if (--clients == 0) {
        clientA.disconnect(true);
        clientB.disconnect(true);
        done();
      }
    };

    clientA.on('data', dataHandler);
    clientB.on('data', dataHandler);

    connHandler = (socket: SocketIO.Socket) => {
      if (++clients == 2) {
        socketServer.broadcastData(key, version, data);
      }
    };
  });
開發者ID:alxhub,項目名稱:tactical,代碼行數:31,代碼來源:socket_spec.ts

示例2: enableCache

 /**
  * @param communibaseAdministrationId
  * @param socketServiceUrl
  */
 public enableCache(communibaseAdministrationId: string, socketServiceUrl: string):void {
   this.cache = {
     getIdsCaches: {},
     aggregateCaches: {},
     dirtySock: socketIoClient.connect(socketServiceUrl, { port: '443' }),
     objectCache: {},
     isAvailable(objectType, objectId) {
       return this.cache.objectCache[objectType] && this.cache.objectCache[objectType][objectId];
     },
   };
   this.cache.dirtySock.on('connect', () => {
     this.cache.dirtySock.emit('join', `${communibaseAdministrationId}_dirty`);
   });
   this.cache.dirtySock.on('message', (dirtyness:string) => {
     const dirtyInfo = dirtyness.split('|');
     if (dirtyInfo.length !== 2) {
       winston.warn(`${new Date()}: Got weird dirty sock data? ${dirtyness}`);
       return;
     }
     this.cache.getIdsCaches[dirtyInfo[0]] = null;
     this.cache.aggregateCaches[dirtyInfo[0]] = null;
     if ((dirtyInfo.length === 2) && this.cache.objectCache[dirtyInfo[0]]) {
       this.cache.objectCache[dirtyInfo[0]][dirtyInfo[1]] = null;
     }
   });
 }
開發者ID:kingsquare,項目名稱:communibase-connector-js,代碼行數:30,代碼來源:index.ts

示例3: connected

function connected(dbConnection) {
  console.log("Connected with mongo: ", dbHost);
  db = dbConnection;

  console.log("Connecting with socket.io:  ", host);
  socket = client.connect(host);
  socket.on('connect', function () {
    console.log("Connected with socket.io: ", host);
  });

  socket.on('*', reportSignal);
}
開發者ID:filipstachura,項目名稱:sensas-platform,代碼行數:12,代碼來源:index.ts

示例4: it

  it("mutate should send a mutation frame to the server", (done) => {
    var ioSocket: SocketIO.Socket = Socket.connect('http://localhost:8080', options);
    var client: SocketIOClient = new SocketIOClient(ioSocket);

    var mutationFrame:
        MutationFrame = {key: key, base: 'foobase', data: {foo: 'baz'}, context: context};

    connHandler = (socket: SocketIO.Socket) => {
      socket.on('mutation', (frame: MutationFrame) => {
        expect(frame).to.deep.equal(mutationFrame);
        socket.disconnect(true);
        done();
      });
    };

    client.mutate(key, mutationFrame.data, mutationFrame.base, context);
  });
開發者ID:angular,項目名稱:tactical,代碼行數:17,代碼來源:socket_spec.ts

示例5: require

const register = (name, bussUrl) => {
  console.log('Registering client ', name, ' to ', bussUrl);
  var io = require('socket.io-client');
  // var middleware = require('socketio-wildcard')();
  // io().use(middleware);
  var socket = io.connect(bussUrl, {reconnect: true});
  console.log('Connected client ', name, ' to ', bussUrl);
  socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
    console.log('Connected'); // data will be 'woot'
    socket.emit('REGISTER_CLIENT', name);
    console.log('Sent REGISTER_CLIENT client ', name, ' to ', bussUrl);
  });

  var patch = require('socketio-wildcard')(io.Manager);
  patch(socket);

  //socket.on('*', function(){ /* … */ })

  return socket;
};
開發者ID:knsv,項目名稱:crib-ui,代碼行數:20,代碼來源:mq.service.ts


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