-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLogger.js
More file actions
53 lines (50 loc) · 1.45 KB
/
Logger.js
File metadata and controls
53 lines (50 loc) · 1.45 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
53
/*
All Events
*/
function Logger(ignore){
this.ignore = ignore;
this.debug = true;
this.state = 'all';
this.events = {
signal:['offer', 'answer', 'candidate', 'message'],
transport:['signal', 'sending', 'message', 'getting'],
pc: ['close', 'negotiationNeeded', 'iceConnectionStateChange', 'signalingStateChange', 'createPeer'],
data:['channelMessage'],
stream:['peerStreamAdded', 'localStream', 'localStreamStopped', 'peerStreamRemoved'],
voice:['stoppedSpeaking', 'audioOff', 'audioOn', 'speaking', 'volumeChange', 'mute', 'unmute'],
screen:[''],
error:['connectivityError', 'error']
};
this.states = Object.keys(this.events);
this.watch = 'peerStreamAdded';
this.log = function(){
if(this.checkEvent(arguments[1])){
var args = Array.prototype.slice.call(arguments);
console.log.apply(console, args);
}
};
}
Logger.prototype = Object.create(console);
Logger.prototype.changeState = function(state, watch){
this.state = state;
if(watch !== undefined){
this.watch = watch;
}
};
Logger.prototype.checkEvent = function(evt){
if(this.debug && this.ignore.indexOf(evt) === -1){
if(this.state === 'all' || this.watch === evt){
return true;
} else if(this.state === 'specific'){
return evt === this.watch;
} else {
return (
this.events[this.state].indexOf(evt) === -1 ?
false :
true
);
}
}
return false;
};
module.exports = Logger;