@ -51,9 +51,12 @@ var locale = {
s _IS _SUSPENDING _s : '' ,
s _IS _RESUMING _YOU : '' ,
s _IS _RESUMING _s : '' ,
s _IS _PROMOTING _YOU : '' ,
s _IS _PROMOTING _s : '' ,
s _IS _KICKING _s : '' ,
MUTE _PEER : '' ,
SUSPEND _PEER : '' ,
PROMOTE _PEER : '' ,
KICK _PEER : '' ,
YOU _HAVE _MUTED _s : '' ,
YOU _HAVE _UNMUTED _s : '' ,
@ -61,6 +64,7 @@ var locale = {
YOU _HAVE _SUSPENDED _s : '' ,
YOU _HAVE _RESUMED _s : '' ,
CANT _SUSPEND _OWNER : '' ,
CANT _PROMOTE _OWNER : '' ,
YOU _HAVE _KICKED _s : '' ,
CANT _KICK _OWNER : '' ,
REMOVE _THIS _ADDRESS : '' ,
@ -539,6 +543,11 @@ function initVroom(room) {
click : function ( ) { pausePeer ( id ) } ,
} ) . prop ( 'title' , locale . SUSPEND _PEER ) )
. append ( $ ( '<button></button>' , {
class : 'actionPromote btn btn-default btn-sm' ,
id : 'actionPromote_' + id ,
click : function ( ) { promotePeer ( id ) } ,
} ) . prop ( 'title' , locale . PROMOTE _PEER ) )
. append ( $ ( '<button></button>' , {
class : 'actionKick btn btn-default btn-sm' ,
id : 'actionKick_' + id ,
click : function ( ) { kickPeer ( id ) } ,
@ -723,6 +732,34 @@ function initVroom(room) {
$ . notify ( locale . CANT _SUSPEND _OWNER , 'error' ) ;
}
}
// Promote a peer (he will be owner)
function promotePeer ( id ) {
if ( peers [ id ] && peers [ id ] . role != 'owner' ) {
$ . ajax ( {
data : {
action : 'promote' ,
room : roomName ,
peer : id
} ,
error : function ( data ) {
$ . notify ( locale . ERROR _OCCURRED , 'error' ) ;
} ,
success : function ( data ) {
if ( data . status == 'success' && data . msg ) {
webrtc . sendToAll ( 'owner_promoted' , { peer : id } ) ;
$ . notify ( data . msg , 'success' ) ;
}
else if ( data . msg ) {
$ . notify ( data . msg , 'error' ) ;
}
}
} ) ;
suspendButton ( $ ( '#actionPromote_' + id ) ) ;
}
else if ( peers [ id ] ) {
$ . notify ( locale . CANT _PROMOTE _OWNER , 'error' ) ;
}
}
// Kick a peer
function kickPeer ( id ) {
if ( peers [ id ] && peers [ id ] . role != 'owner' ) {
@ -848,6 +885,24 @@ function initVroom(room) {
}
}
} ) ;
// An owner has just promoted a participant of the room to the owner role
webrtc . on ( 'owner_promoted' , function ( data ) {
if ( peers [ data . id ] . role != 'owner' || data . roomType == 'screen' ) {
return ;
}
if ( data . payload . peer && data . payload . peer == peers . local . id && peers . local . role != 'owner' ) {
var who = ( peers [ data . id ] . hasName ) ? peers [ data . id ] . displayName : locale . A _ROOM _ADMIN ;
$ . notify ( sprintf ( locale . s _IS _PROMOTING _YOU , who ) , 'success' ) ;
getRoomInfo ( ) ;
}
else if ( data . payload . peer != peers . local . id && peers [ data . payload . peer ] ) {
var who = ( peers [ data . id ] . hasName ) ? peers [ data . id ] . displayName : locale . A _ROOM _ADMIN ;
var target = ( peers [ data . payload . peer ] . hasName ) ? peers [ data . payload . peer ] . displayName : locale . A _PARTICIPANT ;
$ . notify ( sprintf ( locale . s _IS _PROMOTING _s , who , target ) , 'info' ) ;
}
} ) ;
// An owner is kicking someone out of the room
webrtc . on ( 'owner_kick' , function ( data ) {
if ( peers [ data . id ] . role != 'owner' || data . roomType == 'screen' ) {