forked from jslatts/nodechat-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.js
More file actions
37 lines (27 loc) · 999 Bytes
/
Copy pathcontrollers.js
File metadata and controls
37 lines (27 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
//Controllers
//
var NodeChatController = {
init: function(options) {
var ioc, user, view, hashpassword;
ioc = io.connect('http://localhost')
this.socket = ioc;
user = this.userName = options.userName;
hashpassword = this.hashpassword = options.hashpassword
this.model = new models.NodeChatModel();
this.view = new NodeChatView({model: this.model, socket: this.socket, el: $('#content')});
view = this.view;
this.socket.on('connect', function () {
ioc.emit('clientauthrequest', {
user: user
, hashpassword: hashpassword
});
log('Connected! Oh hai!');
});
this.socket.on('chat', function(msg) {view.msgReceived(msg)});
this.socket.on('initial', function(msg) {view.initReceived(msg)});
this.socket.on('update', function(msg) {view.updReceived(msg)});
this.view.render();
return this;
}
};