@@ -1959,6 +1959,60 @@ function stringCompare(a, b) {
1959
1959
return 0
1960
1960
}
1961
1961
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
+
1962
2016
/**
1963
2017
* @param {string } id
1964
2018
* @param {user } userinfo
@@ -1974,6 +2028,13 @@ function addUser(id, userinfo) {
1974
2028
else
1975
2029
user . classList . remove ( 'user-status-raisehand' ) ;
1976
2030
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
+
1977
2038
let us = div . children ;
1978
2039
1979
2040
if ( id === serverConnection . id ) {
@@ -2342,12 +2403,12 @@ function failFile(f, message) {
2342
2403
}
2343
2404
2344
2405
/**
2345
- * @param {string } username
2346
2406
* @param {string } id
2347
2407
* @param {File } file
2348
2408
*/
2349
- function offerFile ( username , id , file ) {
2409
+ function offerFile ( id , file ) {
2350
2410
let fileid = newRandomId ( ) ;
2411
+ let username = serverConnection . users [ id ] . username ;
2351
2412
let f = new TransferredFile (
2352
2413
fileid , id , true , username , file . name , file . type , file . size ,
2353
2414
) ;
@@ -3089,13 +3150,17 @@ commands.subgroups = {
3089
3150
}
3090
3151
} ;
3091
3152
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
+
3092
3160
commands . renegotiate = {
3093
3161
description : 'renegotiate media streams' ,
3094
3162
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 ( ) ;
3099
3164
}
3100
3165
} ;
3101
3166
@@ -3283,6 +3348,28 @@ commands.unraise = {
3283
3348
}
3284
3349
}
3285
3350
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
+
3286
3373
commands . sendfile = {
3287
3374
parameters : 'user' ,
3288
3375
description : 'send a file (this will disclose your IP address)' ,
@@ -3293,23 +3380,8 @@ commands.sendfile = {
3293
3380
let id = findUserId ( p [ 0 ] ) ;
3294
3381
if ( ! id )
3295
3382
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
+ } ,
3313
3385
} ;
3314
3386
3315
3387
/**
0 commit comments