@ -117,13 +117,18 @@ function initVroom(room) {
function updateRole ( ) {
function updateRole ( ) {
$ . ajax ( {
$ . ajax ( {
data : {
data : {
action : 'getRole' ,
action : 'getRoomInfo' ,
room : roomName
room : roomName ,
id : peers . local . id
} ,
} ,
error : function ( data ) {
error : function ( data ) {
$ . notify ( locale . ERROR _OCCURED , 'error' ) ;
$ . notify ( locale . ERROR _OCCURED , 'error' ) ;
} ,
} ,
success : function ( data ) {
success : function ( data ) {
// Notify others if our role changed
if ( data . role != peers . local . role ) {
webrtc . sendToAll ( 'role_change' , { } ) ;
}
peers . local . role = data . role ;
peers . local . role = data . role ;
// Enable owner reserved menu
// Enable owner reserved menu
if ( data . role == 'owner' ) {
if ( data . role == 'owner' ) {
@ -144,6 +149,29 @@ function initVroom(room) {
} ) ;
} ) ;
}
}
// Get the role of a peer
function getPeerRole ( id ) {
$ . ajax ( {
data : {
action : 'getPeerRole' ,
room : roomName ,
id : id
} ,
error : function ( data ) {
$ . notify ( locale . ERROR _OCCURED , 'error' ) ;
} ,
success : function ( data ) {
peers [ id ] . role = data . role ;
if ( data . role == 'owner' ) {
$ ( "#overlay_" + id ) . append ( '<div id="owner_' + id + '" class="owner"></div>' ) ;
}
else {
$ ( '#owner_' + id ) . remove ( ) ;
}
}
} ) ;
}
// Select a color (randomly) from this list, used for text chat
// Select a color (randomly) from this list, used for text chat
function chooseColor ( ) {
function chooseColor ( ) {
// Shamelessly taken from http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
// Shamelessly taken from http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
@ -233,6 +261,8 @@ function initVroom(room) {
if ( ! peers . local . hasHistory && chatIndex == 0 ) {
if ( ! peers . local . hasHistory && chatIndex == 0 ) {
peer . sendDirectly ( 'vroom' , 'getHistory' , '' ) ;
peer . sendDirectly ( 'vroom' , 'getHistory' , '' ) ;
}
}
// Get the role of this peer
getPeerRole ( peer . id ) ;
} , 3500 ) ;
} , 3500 ) ;
}
}
$ ( div ) . attr ( 'id' , 'peer_' + id ) ;
$ ( div ) . attr ( 'id' , 'peer_' + id ) ;
@ -446,6 +476,12 @@ function initVroom(room) {
$ ( "#overlay_" + data . id ) . append ( '<div id="' + div + '" class="' + cl + '"></div>' ) ;
$ ( "#overlay_" + data . id ) . append ( '<div id="' + div + '" class="' + cl + '"></div>' ) ;
} ) ;
} ) ;
// This peer claims he changed its role (usually from participant to owner)
// Lets check this
webrtc . on ( 'role_change' , function ( data ) {
getPeerRole ( data . id ) ;
} ) ;
// Handle unmute/resume
// Handle unmute/resume
webrtc . on ( 'unmute' , function ( data ) {
webrtc . on ( 'unmute' , function ( data ) {
if ( data . name === 'audio' ) {
if ( data . name === 'audio' ) {
@ -494,6 +530,7 @@ function initVroom(room) {
// Handle the readyToCall event: join the room
// Handle the readyToCall event: join the room
webrtc . once ( 'readyToCall' , function ( ) {
webrtc . once ( 'readyToCall' , function ( ) {
peers . local . id = webrtc . connection . socket . sessionid ;
peers . local . id = webrtc . connection . socket . sessionid ;
updateRole ( ) ;
webrtc . joinRoom ( room ) ;
webrtc . joinRoom ( room ) ;
} ) ;
} ) ;
@ -940,9 +977,6 @@ function initVroom(room) {
}
}
} ) ;
} ) ;
// Check if we are the owner of the room
updateRole ( ) ;
// Ping the room every minutes
// Ping the room every minutes
// Used to detect inactive rooms
// Used to detect inactive rooms
setInterval ( function pingRoom ( ) {
setInterval ( function pingRoom ( ) {