@ -475,6 +475,7 @@ function initVroom(room) {
return false ;
return false ;
} )
} )
. css ( 'max-height' , maxHeight ( ) )
. css ( 'max-height' , maxHeight ( ) )
. removeClass ( 'latencyUnknown latencyGood latencyMedium latencyWarn latencyPoor' )
. attr ( 'id' , el . attr ( 'id' ) + '_main' )
. attr ( 'id' , el . attr ( 'id' ) + '_main' )
) ;
) ;
$ ( '.selected' ) . removeClass ( 'selected' ) ;
$ ( '.selected' ) . removeClass ( 'selected' ) ;
@ -515,6 +516,7 @@ function initVroom(room) {
id = 'local' ;
id = 'local' ;
$ ( '<div></div>' ) . addClass ( 'displayName' ) . attr ( 'id' , 'name_local_screen' ) . appendTo ( div ) ;
$ ( '<div></div>' ) . addClass ( 'displayName' ) . attr ( 'id' , 'name_local_screen' ) . appendTo ( div ) ;
updateDisplayName ( id ) ;
updateDisplayName ( id ) ;
$ ( video ) . addClass ( 'latencyUnknown' ) ;
}
}
// video id contains screen ? it's a peer sharing it's screen
// video id contains screen ? it's a peer sharing it's screen
else if ( video . id . match ( /screen/ ) ) {
else if ( video . id . match ( /screen/ ) ) {
@ -582,6 +584,7 @@ function initVroom(room) {
micMuted : false ,
micMuted : false ,
videoPaused : false ,
videoPaused : false ,
hasVideo : true ,
hasVideo : true ,
lastPong : + new Date ,
dc : peer . getDataChannel ( 'vroom' ) ,
dc : peer . getDataChannel ( 'vroom' ) ,
obj : peer
obj : peer
} ;
} ;
@ -605,6 +608,7 @@ function initVroom(room) {
getPeerRole ( peer . id ) ;
getPeerRole ( peer . id ) ;
} , 3000 ) ;
} , 3000 ) ;
video . volume = . 7 ;
video . volume = . 7 ;
$ ( video ) . addClass ( 'latencyUnknown' ) ;
// Stop moh, we're not alone anymore
// Stop moh, we're not alone anymore
$ ( '#mohPlayer' ) [ 0 ] . pause ( ) ;
$ ( '#mohPlayer' ) [ 0 ] . pause ( ) ;
$ ( '.aloneEl' ) . hide ( 300 ) ;
$ ( '.aloneEl' ) . hide ( 300 ) ;
@ -652,6 +656,24 @@ function initVroom(room) {
}
}
}
}
// Feedback for latency with this peer
function updatePeerLatency ( id , time ) {
if ( ! peers [ id ] ) {
return ;
}
var cl = 'latencyPoor' ;
if ( time < 60 ) {
cl = 'latencyGood' ;
}
else if ( time < 150 ) {
cl = 'latencyMedium' ;
}
else if ( time < 250 ) {
cl = 'latencyWarn' ;
}
$ ( '#' + id + '_video_incoming' ) . removeClass ( 'latencyUnknown latencyGood latencyMedium latencyWarn latencyPoor' ) . addClass ( cl ) ;
}
// Add a new message to the chat history
// Add a new message to the chat history
function newChatMessage ( from , message , time , color ) {
function newChatMessage ( from , message , time , color ) {
var cl = ( from === 'local' ) ? 'chatMsgSelf' : 'chatMsgOthers' ;
var cl = ( from === 'local' ) ? 'chatMsgSelf' : 'chatMsgOthers' ;
@ -969,6 +991,16 @@ function initVroom(room) {
if ( label !== 'vroom' ) {
if ( label !== 'vroom' ) {
return ;
return ;
}
}
// Ping from the peer, lets just respond
else if ( data . type == 'ping' ) {
peers [ peer . id ] . obj . sendDirectly ( 'vroom' , 'pong' , data . payload ) ;
}
// Pong from the peer, lets compute reponse time
else if ( data . type == 'pong' ) {
var diff = + new Date - parseInt ( data . payload ) ;
peers [ peer . id ] . lastPong = + new Date ;
updatePeerLatency ( peer . id , diff ) ;
}
// The peer sets a displayName, record this in our peers object
// The peer sets a displayName, record this in our peers object
else if ( data . type == 'setDisplayName' ) {
else if ( data . type == 'setDisplayName' ) {
var name = data . payload ;
var name = data . payload ;
@ -1909,6 +1941,18 @@ function initVroom(room) {
} ) ;
} ) ;
} , 60000 ) ;
} , 60000 ) ;
// Ping all the peers every 5 sec to measure latency
// Do this through dataChannel
setInterval ( function ( ) {
$ . each ( peers , function ( id ) {
// No response from last ping ? mark latency as poor
if ( parseInt ( peers [ id ] . lastPong ) + 5000 > + new Date ) {
$ ( '#' + id + '_video_incoming' ) . removeClass ( 'latencyUnknown latencyGood latencyMedium latencyWarn' ) . addClass ( 'latencyPoor' ) ;
}
} ) ;
webrtc . sendDirectlyToAll ( 'vroom' , 'ping' , + new Date ) ;
} , 5000 ) ;
window . onresize = function ( ) {
window . onresize = function ( ) {
$ ( '#webRTCVideo' ) . css ( 'max-height' , maxHeight ( ) ) ;
$ ( '#webRTCVideo' ) . css ( 'max-height' , maxHeight ( ) ) ;
$ ( '#mainVideo>video' ) . css ( 'max-height' , maxHeight ( ) ) ;
$ ( '#mainVideo>video' ) . css ( 'max-height' , maxHeight ( ) ) ;