本文整理汇总了TypeScript中@appolo/socket.action函数的典型用法代码示例。如果您正苦于以下问题:TypeScript action函数的具体用法?TypeScript action怎么用?TypeScript action使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了action函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _subscribe
@action("subscribe")
public async _subscribe(data:{room:string}) {
this.roomsManager.addClientToRoom(data.room, this);
// subscribe the client to the room
this.socket.join(data.room);
// update all other clients about the online
this._updatePresence(data.room, 'online');
// send to the client a list of all subscribed clients in this room
let clients = [];
_.forEach(this.roomsManager.getClientsInRoom(data.room), (client)=> {
if (client.id != this.id) {
clients.push(client.clientData)
}
});
this.socket.emit('roomclients', {room: data.room, clients: clients});
let messages = await this.cacheProvider.getMessagesFromCache(data.room);
messages.reverse();
let output = _.map(messages, (msgData)=> {
return {client: msgData.clientData, message: msgData.message, room: data.room}
});
this.socket.emit('roomChatMessages', output);
}
示例2: _disconnect
@action("disconnect")
private _disconnect() {
_.forEach(this.roomsManager.getRoomsByClientId(this.id), (roomName)=> {
this._unSubscribe({room: roomName});
});
}
示例3: _chatMessage
@action("chatmessage")
private async _chatMessage(data:IMessage) {
this.socket.broadcast.to(data.room).emit('chatmessage', {
client: this._clientData,
message: data.message,
room: data.room
});
await this.cacheProvider.addMessageToCache(data.room, this._clientData, data.message);
}
示例4: _onNickname
@action("nickname")
private _onNickname(data: { nickname: string }) {
this._clientData.nickname = data.nickname;
this.socket.emit('ready', {clientId: this.id});
this._subscribe({room: 'lobby'});
this.socket.emit('roomslist', {rooms: this.roomsManager.getRoomsList()});
}
示例5: _unSubscribe
@action("unsubscribe")
public _unSubscribe(data:{room:string}) {
// update all other clients about the offline
// presence
this._updatePresence(data.room, 'offline');
// remove the client from socket.io room
this.socket.leave(data.room);
this.roomsManager.removeClientFromRoom(data.room, this);
}