@@ -21,13 +21,14 @@ interface Params {
2121export const TrainerContainer = ( ) => {
2222 const { token, room } = useParams < Params > ( ) ;
2323 const { log, appendToLog, setLog } = useLog ( ) ;
24- const socketDetails = { room : room , trainertoken : token } ;
25- const [ socket , setSocket , socketRef ] = useWithRef < SocketIO . Socket > ( createSocket ( socketDetails ) ) ;
24+ const [ _ , setSocket , socketRef ] = useWithRef < SocketIO . Socket > ( null ) ;
2625
2726 const [ currentTrainerUrl , setCurrentTrainerUrl ] = React . useState < string > ( '' ) ;
2827 const [ currentStudentUrl , setCurrentStudentUrl ] = React . useState < string > ( '' ) ;
2928
3029 const handleConnection = ( ) => {
30+ const socket = createSocket ( { room : room , trainertoken : token } ) ;
31+ setSocket ( socket ) ;
3132 socket . on ( SocketOuputMessageLiteral . MESSAGE , msg => {
3233 if ( msg . type ) {
3334 const { type, payload } = msg ;
@@ -45,19 +46,22 @@ export const TrainerContainer = () => {
4546 }
4647 }
4748 } ) ;
49+ getPreviousSessionContent (
50+ socket ,
51+ SocketEmitMessageTypes . TRAINER_REQUEST_FULL_CONTENT
52+ ) ;
4853 } ;
4954
5055 React . useEffect ( ( ) => {
5156 setCurrentTrainerUrl ( `${ getHostBaseUrl ( ) } #${ routes . trainer ( room , token ) } ` ) ;
5257 setCurrentStudentUrl ( `${ getHostBaseUrl ( ) } #${ routes . student ( room ) } ` ) ;
5358 handleConnection ( ) ;
54- getPreviousSessionContent ( socketRef , SocketEmitMessageTypes . TRAINER_REQUEST_FULL_CONTENT ) ;
5559 } , [ ] ) ;
5660
5761 const appendLineSeparator = ( text : string ) : string =>
5862 `${ text } ${ lineSeparator } ` ;
5963
60- const sendTrainerTextToServer = ( text : string , action :string ) : void => {
64+ const sendTrainerTextToServer = ( text : string , action : string ) : void => {
6165 socketRef . current . emit ( SocketOuputMessageLiteral . MESSAGE , {
6266 type : action ,
6367 payload : text ,
@@ -66,11 +70,18 @@ export const TrainerContainer = () => {
6670
6771 const handleAppendTrainerText = ( trainerText : string ) : void => {
6872 const finalText = appendLineSeparator ( trainerText ) ;
69- sendTrainerTextToServer ( finalText , SocketEmitMessageTypes . TRAINER_APPEND_TEXT ) ;
73+ sendTrainerTextToServer (
74+ finalText ,
75+ SocketEmitMessageTypes . TRAINER_APPEND_TEXT
76+ ) ;
7077 } ;
7178
7279 const handleSendFullContentLog = ( fullContent : string ) : void => {
73- fullContent && sendTrainerTextToServer ( fullContent , SocketEmitMessageTypes . TRAINER_SET_FULL_TEXT ) ;
80+ fullContent &&
81+ sendTrainerTextToServer (
82+ fullContent ,
83+ SocketEmitMessageTypes . TRAINER_SET_FULL_TEXT
84+ ) ;
7485 } ;
7586
7687 return (
0 commit comments