@@ -40,8 +40,8 @@ export const processOuputMessage = (socketInfo: SocketInfo, action: Action) => {
4040 case OutputMessageTypes . APPEND_TEXT :
4141 handleAppendText ( socketInfo , action . payload ) ;
4242 break ;
43- case OutputMessageTypes . REPLACE_FULL_TEXT :
44- handleReplaceFullText ( socketInfo , action . payload ) ;
43+ case OutputMessageTypes . UPDATE_FULL_CONTENT :
44+ handleUpdateFullContent ( socketInfo ) ;
4545 break ;
4646 case OutputMessageTypes . STUDENT_SEND_FULL_CONTENT :
4747 handleSingleStudentSendFullContent ( socketInfo ) ;
@@ -55,32 +55,23 @@ export const processOuputMessage = (socketInfo: SocketInfo, action: Action) => {
5555} ;
5656
5757const handleSingleStudentSendFullContent = ( socketInfo : SocketInfo ) => {
58- handleSendFullContent ( socketInfo , responseType . STUDENT_GET_FULL_CONTENT ) ;
58+ handleSendFullContent ( socketInfo , responseType . STUDENT_GET_FULL_CONTENT , false ) ;
5959}
6060
6161const handleTrainerSendFullContent = ( socketInfo : SocketInfo ) => {
62- handleSendFullContent ( socketInfo , responseType . TRAINER_GET_FULL_CONTENT ) ;
62+ handleSendFullContent ( socketInfo , responseType . TRAINER_GET_FULL_CONTENT , false ) ;
6363}
6464
65- const handleSendFullContent = ( socketInfo : SocketInfo , responseType : string ) => {
66- const room = getRoomFromConnectionId ( socketInfo . connectionId ) ;
67- const content = getRoomContent ( room ) ;
68- socketInfo . socket . emit ( SocketOuputMessageLiteral . MESSAGE , {
69- type : responseType ,
70- payload : content ,
71- } ) ;
72- } ;
65+ const handleUpdateFullContent = ( socketInfo : SocketInfo ) => {
66+ handleSendFullContent ( socketInfo , responseType . UPDATE_FULL_CONTENT , true ) ;
67+ }
7368
74- // TODO: replace with handleSingleStudentSendFullContent code
75- // but instead of using socketInfo.socket.emit use
76- // socketInfo.io.in(room)
77- const handleReplaceFullText = ( socketInfo : SocketInfo , text : string ) => {
69+ const handleSendFullContent = ( socketInfo : SocketInfo , responseType : string , sendToAll : boolean ) => {
7870 const room = getRoomFromConnectionId ( socketInfo . connectionId ) ;
79- socketInfo . io . in ( room ) . emit ( SocketOuputMessageLiteral . MESSAGE , {
80- // TODO: remove from const list REPLACE_FULL_TEXT
81- type : responseType . REPLACE_FULL_TEXT , //STUDENT_GET_FULL_CONTENT
82- payload : text ,
83- } ) ;
71+ const content = getRoomContent ( room ) ;
72+ const msg = { type : responseType , payload : content } ;
73+ sendToAll ? socketInfo . io . in ( room ) . emit ( SocketOuputMessageLiteral . MESSAGE , msg ) :
74+ socketInfo . socket . emit ( SocketOuputMessageLiteral . MESSAGE , msg ) ;
8475} ;
8576
8677const handleAppendText = ( socketInfo : SocketInfo , text : string ) => {
0 commit comments