本文整理汇总了TypeScript中socket.io-client.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript io-client.connect方法的具体用法?TypeScript io-client.connect怎么用?TypeScript io-client.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket.io-client
的用法示例。
在下文中一共展示了io-client.connect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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();
});
}
示例2: 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());
}
});
}
}
示例3: it
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();
}),
);
});
示例4: 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();
});
}
示例5: 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();
}
示例6:
}).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)
});
示例7: ngOnInit
ngOnInit():any{
this.socket = io.connect("http://localhost:3000");
this.socket.on("newMessage", (message) => {
this._messageService.listener.next(message);
});
this.socket.on("roomAdded", (rooms) => {
this._registerService.newRoom.next(rooms);
});
}
示例8: it
it(`should handle message with ack (http)`, async () => {
app = await createNestApp(AckGateway);
await app.listenAsync(3000);
ws = io.connect('http://localhost:8080');
await new Promise(resolve =>
ws.emit('push', { test: 'test' }, data => {
expect(data).to.be.eql('pong');
resolve();
}),
);
});
示例9: onConnectClick
function onConnectClick(event: MouseEvent) {
event.preventDefault();
const host = localStorage["gameServerHost"] = ui.getValue("server-host");
socket = io.connect(host, { reconnection: false });
log(`Connecting to ${host}...`);
ui.getPane("server").hidden = true;
socket.on("connect", onConnected);
socket.on("disconnect", onDisconnected);
}
示例10: ngOnInit
ngOnInit(){
this.gameMatch = this.matesExchange.getSelectedGameMatch()
// this.matesServices
// .getGameInstance(this.gameMatch.gameId)
// .subscribe(gameInstance => this.gameControl.setGameInstance(gameInstance))
this.socket = io.connect('http://localhost:4001', { 'forceNew': true });
this.socket.on(this.gameMatch._id, (message) =>
message.type === 'start'
? this.gameMatch.isStarted = true
: console.log(message))
}