本文整理匯總了TypeScript中socket.io.default.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript io.default.on方法的具體用法?TypeScript io.default.on怎麽用?TypeScript io.default.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類socket.io.default
的用法示例。
在下文中一共展示了io.default.on方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: require
import {expect} from 'chai';
import {
DataFrame,
FailureFrame,
MutationFrame,
RequestFrame,
SocketIOClient,
SocketIOServer
} from '../src/socket';
var Server = require('socket.io');
var Socket = require('socket.io-client');
var server: SocketIO.Server = new Server(8080);
var connHandler: Function = (socket: SocketIO.Socket): void => {};
server.on('connection', (socket: SocketIO.Socket) => connHandler(socket));
var options = {transports: ['websocket'], 'force new connection': true};
var key: Object = {key: true};
var cntxt: Object = {auth: true};
describe('SocketIOClient', () => {
it("request should send a request frame to the server", (done) => {
var ioSocket: SocketIO.Socket = Socket.connect('http://localhost:8080', options);
var client: SocketIOClient = new SocketIOClient(ioSocket);
connHandler = (socket: SocketIO.Socket) => {
socket.on('request', (frame: RequestFrame) => {
expect(frame.key).to.deep.equal(key);
expect(frame.context).to.deep.equal(cntxt);
示例2: before
before(() => {
server = new Server(8080);
server.on('connection', (socket: SocketIO.Socket) => connHandler(socket));
});