1+ var quickconnect = require ( 'rtc-quickconnect' ) ;
2+ var captureConfig = require ( 'rtc-captureconfig' ) ;
3+ var capture = require ( 'rtc-capture' ) ;
4+ var attach = require ( 'rtc-attach' ) ;
5+ var health = require ( '../' ) ;
6+ var crel = require ( 'crel' ) ;
7+ var plugins = [ require ( 'rtc-plugin-temasys' ) ] ;
8+ var constraints = captureConfig ( 'camera min:1280x720' ) . toConstraints ( ) ;
9+
10+ function attachVideo ( stream , el ) {
11+ attach ( stream , {
12+ el : el ,
13+ plugins : plugins
14+ } , function ( err , el ) {
15+ if ( err || ! el ) return ;
16+ document . body . appendChild ( el ) ;
17+ } ) ;
18+ }
19+
20+ capture ( constraints , { plugins : plugins } , function ( err , stream ) {
21+
22+ attachVideo ( stream , crel ( 'div' , { class : 'local' , style : 'width: 50%;' } ) ) ;
23+
24+ var qc = window . qc =
25+ quickconnect ( 'http://rtc.io/switchboard/' , {
26+ room : 'health-temasys-capture' ,
27+ iceServers : [
28+ { url : 'stun:stun.l.google.com:19302' }
29+ ] ,
30+ disableHeartbeat : true ,
31+ plugins : [ require ( 'rtc-plugin-temasys' ) ]
32+ } ) . addStream ( stream )
33+ . on ( 'stream:added' , function ( id , stream ) {
34+ console . log ( 'added %s' , id ) ;
35+ var el = crel ( 'div' , { class : 'remote' , id : id , style : 'width: 50%;' } ) ;
36+ attachVideo ( stream , el ) ;
37+ } )
38+ . on ( 'stream:removed' , function ( id ) {
39+ console . log ( 'removed %s' , id ) ;
40+ var el = document . getElementById ( id ) ;
41+ if ( el ) el . remove ( ) ;
42+ } )
43+ . on ( 'local:announce' , function ( data ) {
44+ console . log ( '-> connected to %s' , data . room ) ;
45+ } )
46+ . on ( 'peer:announce' , function ( data ) {
47+ console . log ( '-> announce' ) ;
48+ console . log ( data ) ;
49+ } ) ;
50+
51+ var monitor = health ( qc , { pollInterval : 2500 , verbose : true } ) ;
52+ var previous = null ;
53+ monitor . on ( 'health:report' , function ( reporter ) {
54+
55+ var statistics = [ ] ;
56+ // console.log(reporter.isActive() ? 'Connection is active' : 'Connection is inactive');
57+ // var channels = reporter.getChannelReports();
58+ // for (var i = 0; i < channels.length; i++) {
59+ // var report = channels[i];
60+ // console.log(report.toJSON());
61+ // }
62+ previous = reporter . toJSON ( {
63+ exclude : [ 'googTrack' , 'googComponent' , 'googCertificate' , 'googLibjingleSession' ] ,
64+ compareTo : previous
65+ } ) ;
66+ console . log ( previous ) ;
67+ } ) ;
68+
69+ monitor . on ( 'health:notify' , function ( evt , opts , data ) {
70+ // console.log('[%s->%s] %s', opts.source, opts.about, evt);
71+ // if (data) {
72+ // console.log(JSON.stringify(data));
73+ // }
74+ } ) ;
75+
76+ monitor . on ( 'health:connection:status' , function ( conn , status , previousStatus ) {
77+ console . log ( 'Status changed from %s to %s' , previousStatus , status ) ;
78+ } ) ;
79+
80+ window . monitor = monitor ;
81+ } ) ;
0 commit comments