socket.js 714 B

1234567891011121314151617181920212223
  1. function socket(user, url) {
  2. this.user = user;
  3. this.io = (url ? io(url) : io('http://socketio.1473.cn/'));
  4. }
  5. socket.prototype = {
  6. join: function (house, fn) {//房间 用户
  7. this.io.on(house, fn);
  8. this.io.emit("join", { type: "join", house: house, from: this.user });
  9. },
  10. send: function (data, house) {
  11. this.io.emit("send", { type: "send", house: house, from: this.user, data: data });
  12. },
  13. exit: function (house) {
  14. this.io.emit("exit", { type: "exit", house: house, from: this.user });
  15. },
  16. list: function (house, fn) {
  17. this.io.emit("list", { type: "exit", house: house, from: this.user });
  18. this.io.on(socket.io.id, fn);
  19. }
  20. }