Skip to content
黃健旻 edited this page Jan 31, 2019 · 6 revisions
class BroadcastMsg {
     title: String,
     content: String,
}
class ChatMsg {
     from: String,
     to: String,
     content: String,
}
class RoomIdName {
     id: String,
     name: String,
}
class MemberInfo {
     account: String,
     character: String,
     status: String,
}
class Protocol {
     roomId: String,
     name: String,
     type: String,
     rooms: List<RoomIdName>,
     membersInfo: List<MemberInfo>,
     killWho: String,
     beatWho: String,
     from: String,
     msg: String,
     isPublic: Boolean
}

Init

var socket = io.connect('http://localhost:9092');

Bind

  • send
socket.emit('Bind', JSON.stringify({"account": "Vincent"}), function (acknowledgement) { ... });

Broadcast Chat

  • send
socket.emit('Broadcast', JSON.stringify({"title": "test", "content": "test 123 broadcast"}), function (acknowledgement) { ... });
  • listen
socket.on('Broadcast', function (msg: BroadcastMsg) {
    ...
});

Private Chat

  • send
socket.emit('Chat', JSON.stringify({"to": "Vincent", "content": "test 123 to Vincent"}), function (acknowledgement) { ... });
  • listen
socket.on('Chat', function (msg: ChatMsg) {
    ...
});

Room Chat

  • send
socket.emit('Game', JSON.stringify({"roomId": roomId, "name": "RoomChat", "content": "I'm Human"}), function (acknowledgement) { ... });
  • listen
socket.on('Room', function (msg: ProtocolMsg)) {
    ...
});

Woo Chat

  • send
socket.emit('Game', JSON.stringify({"roomId": roomId, "name": "WooChat", "content": "I'm werewolf"}), function (acknowledgement) { ... });
  • listen
socket.on('Woo', function (msg: ProtocolMsg) {
    ...
});

Clone this wiki locally