本文整理匯總了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);
}
};
});
示例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;
}
});
}
示例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);
}
示例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);
});
示例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;
};