@@ -1959,6 +1959,60 @@ function stringCompare(a, b) {
19591959 return 0
19601960}
19611961
1962+ /**
1963+ * @param {HTMLElement } elt
1964+ */
1965+ function userMenu ( elt ) {
1966+ if ( ! elt . id . startsWith ( 'user-' ) )
1967+ throw new Error ( 'Unexpected id for user menu' ) ;
1968+ let id = elt . id . slice ( 'user-' . length ) ;
1969+ let user = serverConnection . users [ id ] ;
1970+ if ( ! user )
1971+ throw new Error ( "Couldn't find user" )
1972+ let items = [ ] ;
1973+ if ( id === serverConnection . id ) {
1974+ let mydata = serverConnection . users [ serverConnection . id ] . data ;
1975+ if ( mydata [ 'raisehand' ] )
1976+ items . push ( { label : 'Lower hand' , onClick : ( ) => {
1977+ serverConnection . userAction (
1978+ 'setdata' , serverConnection . id , { 'raisehand' : null } ,
1979+ ) ;
1980+ } } ) ;
1981+ else
1982+ items . push ( { label : 'Raise hand' , onClick : ( ) => {
1983+ serverConnection . userAction (
1984+ 'setdata' , serverConnection . id , { 'raisehand' : true } ,
1985+ ) ;
1986+ } } ) ;
1987+ items . push ( { label : 'Restart media' , onClick : renegotiateStreams } ) ;
1988+ } else {
1989+ items . push ( { label : 'Send file' , onClick : ( ) => {
1990+ sendFile ( id ) ;
1991+ } } ) ;
1992+ if ( serverConnection . permissions . op ) {
1993+ items . push ( { type : 'seperator' } ) ; // sic
1994+ if ( user . permissions . present )
1995+ items . push ( { label : 'Forbid presenting' , onClick : ( ) => {
1996+ serverConnection . userAction ( 'unpresent' , id ) ;
1997+ } } ) ;
1998+ else
1999+ items . push ( { label : 'Allow presenting' , onClick : ( ) => {
2000+ serverConnection . userAction ( 'present' , id ) ;
2001+ } } ) ;
2002+ items . push ( { label : 'Mute' , onClick : ( ) => {
2003+ serverConnection . userAction ( 'mute' , id ) ;
2004+ } } ) ;
2005+ items . push ( { label : 'Kick out' , onClick : ( ) => {
2006+ serverConnection . userAction ( 'kick' , id ) ;
2007+ } } ) ;
2008+ }
2009+ }
2010+ /** @ts -ignore */
2011+ new Contextual ( {
2012+ items : items ,
2013+ } ) ;
2014+ }
2015+
19622016/**
19632017 * @param {string } id
19642018 * @param {user } userinfo
@@ -1974,6 +2028,13 @@ function addUser(id, userinfo) {
19742028 else
19752029 user . classList . remove ( 'user-status-raisehand' ) ;
19762030
2031+ user . addEventListener ( 'click' , function ( e ) {
2032+ let elt = e . target ;
2033+ if ( ! elt || ! ( elt instanceof HTMLElement ) )
2034+ throw new Error ( "Couldn't find user div" ) ;
2035+ userMenu ( elt ) ;
2036+ } ) ;
2037+
19772038 let us = div . children ;
19782039
19792040 if ( id === serverConnection . id ) {
@@ -2342,12 +2403,12 @@ function failFile(f, message) {
23422403}
23432404
23442405/**
2345- * @param {string } username
23462406 * @param {string } id
23472407 * @param {File } file
23482408 */
2349- function offerFile ( username , id , file ) {
2409+ function offerFile ( id , file ) {
23502410 let fileid = newRandomId ( ) ;
2411+ let username = serverConnection . users [ id ] . username ;
23512412 let f = new TransferredFile (
23522413 fileid , id , true , username , file . name , file . type , file . size ,
23532414 ) ;
@@ -3089,13 +3150,17 @@ commands.subgroups = {
30893150 }
30903151} ;
30913152
3153+ function renegotiateStreams ( ) {
3154+ for ( let id in serverConnection . up )
3155+ serverConnection . up [ id ] . restartIce ( ) ;
3156+ for ( let id in serverConnection . down )
3157+ serverConnection . down [ id ] . restartIce ( ) ;
3158+ }
3159+
30923160commands . renegotiate = {
30933161 description : 'renegotiate media streams' ,
30943162 f : ( c , r ) => {
3095- for ( let id in serverConnection . up )
3096- serverConnection . up [ id ] . restartIce ( ) ;
3097- for ( let id in serverConnection . down )
3098- serverConnection . down [ id ] . restartIce ( ) ;
3163+ renegotiateStreams ( ) ;
30993164 }
31003165} ;
31013166
@@ -3283,6 +3348,28 @@ commands.unraise = {
32833348 }
32843349}
32853350
3351+ /**
3352+ * @param {string } id
3353+ */
3354+ function sendFile ( id ) {
3355+ let input = document . createElement ( 'input' ) ;
3356+ input . type = 'file' ;
3357+ input . onchange = function ( e ) {
3358+ if ( ! ( this instanceof HTMLInputElement ) )
3359+ throw new Error ( 'Unexpected type for this' ) ;
3360+ let files = input . files ;
3361+ for ( let i = 0 ; i < files . length ; i ++ ) {
3362+ try {
3363+ offerFile ( id , files [ i ] ) ;
3364+ } catch ( e ) {
3365+ console . error ( e ) ;
3366+ displayError ( e ) ;
3367+ }
3368+ }
3369+ } ;
3370+ input . click ( ) ;
3371+ }
3372+
32863373commands . sendfile = {
32873374 parameters : 'user' ,
32883375 description : 'send a file (this will disclose your IP address)' ,
@@ -3293,23 +3380,8 @@ commands.sendfile = {
32933380 let id = findUserId ( p [ 0 ] ) ;
32943381 if ( ! id )
32953382 throw new Error ( `Unknown user ${ p [ 0 ] } ` ) ;
3296- let input = document . createElement ( 'input' ) ;
3297- input . type = 'file' ;
3298- input . onchange = function ( e ) {
3299- if ( ! ( this instanceof HTMLInputElement ) )
3300- throw new Error ( 'Unexpected type for this' ) ;
3301- let files = input . files ;
3302- for ( let i = 0 ; i < files . length ; i ++ ) {
3303- try {
3304- offerFile ( p [ i ] , id , files [ i ] ) ;
3305- } catch ( e ) {
3306- console . error ( e ) ;
3307- displayError ( e ) ;
3308- }
3309- } ;
3310- } ;
3311- input . click ( ) ;
3312- }
3383+ sendFile ( id ) ;
3384+ } ,
33133385} ;
33143386
33153387/**
0 commit comments