-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleChat.js
More file actions
53 lines (43 loc) · 1.17 KB
/
Copy pathSimpleChat.js
File metadata and controls
53 lines (43 loc) · 1.17 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Chat(){
this.peer = undefined;
this.conn = undefined;
this.id = undefined;
this.init = function(){
console.log("Inside Init");
this.peer = new Peer({key: 'lwjd5qra8257b9'});
this.peer.on('open', function(id){
console.log('Peer ID = ' + id);
this.id = id;
});
/**
this.peer.on('connection', function(conn){
this.conn = conn;
console.log("Connection established");
conn.on('open', function(){
conn.on('data', receiveMsg(msg));
});
});
*/
console.log("Exiting Init");
}
this.getId = function(){
console.log("Inside getId");
this.peer.on('open', function(id){
console.log('Peer ID = ' + id);
this.id = id;
});
}
this.connectTo = function(id){
this.conn = this.peer.connect(id);
//Add conn.on('open') here
}
this.sendMsg = function(str){
if(this.conn !== undefined){
this.conn.send(str);
}
}
this.receiveMsg = function(str){
console.log(str);
}
}
var myChat = new Chat();