当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript io-client.default.connect方法代码示例

本文整理汇总了TypeScript中socket.io-client.default.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript io-client.default.connect方法的具体用法?TypeScript io-client.default.connect怎么用?TypeScript io-client.default.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket.io-client.default的用法示例。


在下文中一共展示了io-client.default.connect方法的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.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。