Simple messages
This commit is contained in:
parent
a783a71789
commit
04b2455aaf
|
@ -63,5 +63,14 @@ models.NetworkCollection = Backbone.Collection.extend({
|
|||
this.add(new models.Network({
|
||||
host: "Lobby"
|
||||
}));
|
||||
},
|
||||
getChannel: function(id) {
|
||||
var networks = this.models;
|
||||
for (var i = 0; i < networks.length; i++) {
|
||||
var find = networks[i].get("channels").findWhere({id: id});
|
||||
if (find) {
|
||||
return find;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,6 +20,12 @@ Server.prototype.listen = function(port) {
|
|||
this.sockets = io.listen(http).sockets;
|
||||
this.sockets.on("connection", function(socket) {
|
||||
init.call(self, socket);
|
||||
socket.on(
|
||||
"input",
|
||||
function(input) {
|
||||
handleUserInput.call(self, input);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return this;
|
||||
|
@ -31,3 +37,16 @@ function init(socket) {
|
|||
this.networks
|
||||
)
|
||||
}
|
||||
|
||||
function handleUserInput(input) {
|
||||
var channel = this.networks.getChannel(input.id);
|
||||
if (channel) {
|
||||
channel.get("messages").push(
|
||||
new models.Message({user: "user", text: input.text})
|
||||
);
|
||||
this.sockets.emit(
|
||||
"event",
|
||||
this.networks
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue