-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser-session.js
52 lines (47 loc) · 1.55 KB
/
user-session.js
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
/**
* Created by eak on 9/14/15.
*/
function UserSession(id, socket) {
this.id = id;
this.socket = socket;
this.outgoingMedia = null;
this.incomingMedia = {};
this.iceCandidateQueue = {};
}
UserSession.prototype.addIceCandidate = function (data, candidate) {
// ice candidate for this user
if (data.sender === this.id) {
if (this.outgoingMedia) {
console.log(' add candidate to self : ' + data.sender);
this.outgoingMedia.addIceCandidate(candidate);
} else {
console.error(' still does not have outgoing endpoint for : ' + data.sender);
this.iceCandidateQueue[data.sender].push({
data: data,
candidate: candidate
});
}
} else {
var webRtc = this.incomingMedia[data.sender];
if (webRtc) {
console.log(this.id + ' add candidate to from : ' + data.sender);
webRtc.addIceCandidate(candidate);
} else {
console.error(this.id + ' still does not have endpoint for : ' + data.sender);
if (!this.iceCandidateQueue[data.sender]) {
this.iceCandidateQueue[data.sender] = [];
}
this.iceCandidateQueue[data.sender].push({
data: data,
candidate: candidate
});
}
}
};
UserSession.prototype.sendMessage = function (data) {
this.socket.emit('message', data);
};
UserSession.prototype.setRoomName = function (roomName){
this.roomName = roomName;
}
module.exports = UserSession;