@@ -228,6 +228,7 @@ export class NoteScreenConnection extends CommonConnection {
228228 emittoken ( ) . catch ( ( error ) => {
229229 console . log ( 'notepad emittoken problem' , error )
230230 } )
231+ socket . emit ( 'userhash' , notepadscreenid . userhash )
231232 this . emitCryptoIdent ( socket , notepadscreenid )
232233 this . emitAVOffers ( socket , notepadscreenid )
233234 this . emitVideoquestions ( socket , notepadscreenid )
@@ -471,16 +472,47 @@ export class NoteScreenConnection extends CommonConnection {
471472
472473 socket . on ( 'startPoll' , ( cmd ) => {
473474 if (
474- cmd . poll &&
475- cmd . poll . children &&
476- cmd . poll . children . length &&
477- cmd . poll . name &&
478- / ^ [ 0 - 9 a - z A - Z ] { 9 } $ / . test ( cmd . poll . id )
475+ ! (
476+ cmd . poll &&
477+ cmd . poll . children &&
478+ cmd . poll . children . length &&
479+ cmd . poll . name &&
480+ / ^ [ 0 - 9 a - z A - Z ] { 9 } $ / . test ( cmd . poll . id )
481+ )
479482 ) {
480- this . startPoll ( notepadscreenid . lectureuuid , cmd . poll )
481- } else {
482483 console . log ( 'received corrupt poll' , cmd . poll )
484+ return
485+ }
486+ const poll = cmd . poll
487+ const limited = ! ! cmd . limited
488+ let participants
489+ if ( typeof cmd . participants !== 'undefined' ) {
490+ if ( ! Array . isArray ( cmd . participants ) ) {
491+ console . log ( 'poll participants is not an array' )
492+ return
493+ }
494+ console . log ( 'partcipants peak' , cmd . participants )
495+ if (
496+ cmd . participants . some (
497+ ( el ) => typeof el !== 'string' || ! / ^ [ 0 - 9 a - z A - Z ] + $ / . test ( el )
498+ )
499+ ) {
500+ console . log ( 'poll participant items are not userhash format' )
501+ return
502+ }
503+ participants = cmd . participants
504+ } else {
505+ if ( limited ) {
506+ console . log ( 'poll participants not set in limited poll' )
507+ return
508+ }
483509 }
510+
511+ this . startPoll ( notepadscreenid . lectureuuid , {
512+ poll,
513+ limited,
514+ participants
515+ } )
484516 } )
485517
486518 socket . on ( 'finishPoll' , ( data ) => {
@@ -1176,26 +1208,33 @@ export class NoteScreenConnection extends CommonConnection {
11761208 }
11771209 }
11781210
1179- async startPoll ( lectureuuid , poll ) {
1211+ async startPoll ( lectureuuid , { poll, limited , participants } ) {
11801212 const roomname = this . getRoomName ( lectureuuid )
11811213 // ok first thing, we have to create a salt and set it in redis!
11821214 const randBytes = promisify ( randomBytes )
11831215
11841216 try {
11851217 const pollsalt = ( await randBytes ( 16 ) ) . toString ( 'base64' ) // the salt is absolutely confidential, everyone who knows it can spoil secrecy of polling!
1186- this . redis . set (
1218+ await this . redis . set (
11871219 'pollsalt:lecture:' + lectureuuid + ':poll:' + poll . id ,
11881220 pollsalt ,
11891221 { EX : 10 * 60 /* 10 Minutes for polling */ }
11901222 ) // after the pollsalt is gone, the poll is over!
1191- this . redis . hSet ( 'lecture:' + lectureuuid + ':pollstate' , [
1223+ const pollstateCmd = [
11921224 'command' ,
11931225 'startPoll' ,
11941226 'data' ,
1195- JSON . stringify ( poll )
1196- ] )
1197- this . notepadio . to ( roomname ) . emit ( 'startPoll' , poll )
1198- this . notesio . to ( roomname ) . emit ( 'startPoll' , poll )
1227+ JSON . stringify ( poll ) ,
1228+ 'limited' ,
1229+ limited
1230+ ]
1231+ if ( limited ) {
1232+ pollstateCmd . push ( 'participants' , JSON . stringify ( participants ) )
1233+ }
1234+ this . redis . hSet ( 'lecture:' + lectureuuid + ':pollstate' , pollstateCmd )
1235+
1236+ this . notepadio . to ( roomname ) . emit ( 'startPoll' , { ...poll , participants } ) // overwrite participants
1237+ this . notesio . to ( roomname ) . emit ( 'startPoll' , { ...poll , participants } )
11991238 } catch ( err ) {
12001239 console . log ( 'error in startpoll' , err )
12011240 }
@@ -1207,13 +1246,21 @@ export class NoteScreenConnection extends CommonConnection {
12071246
12081247 try {
12091248 this . redis . del ( 'pollsalt:lecture:' + lectureuuid + ':poll:' + data . pollid ) // after the pollsalt is gone, the poll is over!
1249+ const parti = await this . redis . hGet (
1250+ 'lecture:' + lectureuuid + ':pollstate' ,
1251+ 'participants'
1252+ )
1253+ let participants
1254+ if ( ! parti ) {
1255+ participants = JSON . parse ( parti )
1256+ }
12101257 const res = data . result
12111258 . filter ( ( el ) => / ^ [ 0 - 9 a - z A - Z ] { 9 } $ / . test ( el . id ) )
12121259 . map ( ( el ) => ( { id : el . id , data : el . data , name : el . name } ) )
12131260 this . redis . del ( 'lecture:' + lectureuuid + ':pollstate' )
12141261 this . notepadio
12151262 . to ( roomname )
1216- . emit ( 'finishPoll' , { id : data . pollid , result : res } )
1263+ . emit ( 'finishPoll' , { id : data . pollid , result : res , participants } )
12171264 this . notesio
12181265 . to ( roomname )
12191266 . emit ( 'finishPoll' , { id : data . pollid , result : res } )
0 commit comments