Skip to content

Commit e4b5c76

Browse files
committed
monitor.getConnection(target) for getting the tracked connection
1 parent c6dc228 commit e4b5c76

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

example/capture.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ localMedia.render(local);
1717

1818
localMedia.once('capture', function(stream) {
1919

20-
var qc = window.qc =
21-
quickconnect('http://rtc.io/switchboard/', {
20+
var qc = window.qc =
21+
quickconnect('http://rtc.io/switchboard/', {
2222
room: 'health-capture',
2323
iceServers: [
2424
{ url: 'stun:stun.l.google.com:19302' }
@@ -66,7 +66,7 @@ localMedia.once('capture', function(stream) {
6666
monitor.on('health:notify', function(evt, opts, data) {
6767
// console.log('[%s->%s] %s', opts.source, opts.about, evt);
6868
// if (data) {
69-
// console.log(JSON.stringify(data));
69+
// console.log(JSON.stringify(data));
7070
// }
7171
});
7272

index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var wildcard = require('wildcard');
1111

1212
var OPTIONAL_MONITOR_EVENTS = [
1313
'negotiate:request', 'negotiate:renegotiate', 'negotiate:abort',
14-
'negotiate:createOffer', 'negotiate:createOffer:created',
14+
'negotiate:createOffer', 'negotiate:createOffer:created',
1515
'negotiate:createAnswer', 'negotiate:createAnswer:created',
1616
'negotiate:setlocaldescription',
1717
'icecandidate:local', 'icecandidate:remote', 'icecandidate:gathered', 'icecandidate:added',
@@ -23,7 +23,7 @@ var OPTIONAL_MONITOR_EVENTS = [
2323
2424
The `rtc-health` module helps make it easier to expose health information
2525
about your RTC connections. It hooks into the WebRTC Stats API, as well as the
26-
underlying signaller and PeerConnection events to provide insight as to events,
26+
underlying signaller and PeerConnection events to provide insight as to events,
2727
and metrics about any peer connections initiated by the provided quickconnect instance.
2828
2929
## Example Usage
@@ -60,16 +60,16 @@ module.exports = function(qc, opts) {
6060
if (tc) {
6161
timers[data.id] = setTimeout(log.bind(this, peerId, pc, data), emitter.pollInterval);
6262
}
63-
63+
6464
var reporter = new Reporter({
65-
source: qc.id,
65+
source: qc.id,
6666
about: data,
6767
pc: pc,
6868
reports: reports
6969
});
7070

7171
emitter.emit('health:report', reporter, pc);
72-
});
72+
});
7373
}
7474

7575
/**
@@ -102,7 +102,7 @@ module.exports = function(qc, opts) {
102102
**/
103103
qc.on('peer:connect', trackConnection);
104104

105-
qc.on('peer:couple', function(peerId, pc, data, monitor) {
105+
qc.on('peer:couple', function(peerId, pc, data, monitor) {
106106

107107
// Store that we are currently tracking the target peer
108108
var tc = connections[data.id];
@@ -112,8 +112,8 @@ module.exports = function(qc, opts) {
112112
monitor.on('statechange', function(pc, state) {
113113
var iceConnectionState = pc.iceConnectionState;
114114
var newStatus = util.toStatus(iceConnectionState);
115-
notify('icestatus', {
116-
source: qc.id, about: data.id, tracker: tc
115+
notify('icestatus', {
116+
source: qc.id, about: data.id, tracker: tc
117117
}, iceConnectionState);
118118
emitter.emit('health:changed', tc, iceConnectionState);
119119

@@ -129,7 +129,7 @@ module.exports = function(qc, opts) {
129129
});
130130

131131
monitor.on('closed', function() {
132-
132+
133133
tc.closed();
134134

135135
// Stop the reporting for this peer connection
@@ -138,7 +138,7 @@ module.exports = function(qc, opts) {
138138

139139
// Emit a closure status update
140140
emitter.emit('health:report', new Reporter({
141-
source: qc.id,
141+
source: qc.id,
142142
about: data,
143143
status: 'closed',
144144
force: true
@@ -155,7 +155,7 @@ module.exports = function(qc, opts) {
155155

156156
if (util.SIGNALLER_EVENTS.indexOf(name) >= 0) {
157157
return notify.apply(
158-
notify,
158+
notify,
159159
[name, { source: qc.id, about: 'signaller' }].concat(evt.args)
160160
);
161161
}
@@ -167,7 +167,7 @@ module.exports = function(qc, opts) {
167167
var shortName = matching.slice(2).join('.');
168168
var tc = connections[peerId];
169169
return notify.apply(
170-
notify,
170+
notify,
171171
[shortName, { source: qc.id, about: peerId, tracker: tc }].concat(evt.args)
172172
);
173173
}
@@ -187,7 +187,12 @@ module.exports = function(qc, opts) {
187187
results.push(connections[target]);
188188
}
189189
return results;
190-
}
190+
};
191+
192+
// Get the tracked connection for the given target peer
193+
emitter.getConnection = function(target) {
194+
return connections && connections[target];
195+
};
191196

192197
return emitter;
193198
};

0 commit comments

Comments
 (0)