@@ -29,6 +29,7 @@ const CollaborationSpace = () => {
29
29
const [ output , setOutput ] = useState ( "" )
30
30
const [ messages , setMessages ] = useState ( [ ] )
31
31
const [ outputLoading , setOutputLoading ] = useState ( false )
32
+ const [ roomStartTime , setRoomStartTime ] = useState ( null ) ; // Initialize state for room start time
32
33
33
34
// use https://emkc.org/api/v2/piston/runtimes to GET other languages
34
35
const LANGUAGEVERSIONS = {
@@ -136,6 +137,10 @@ const CollaborationSpace = () => {
136
137
case 'userLeft' :
137
138
addNotif ( `User ${ data . user } has left` )
138
139
break ;
140
+ // Handle room start time message
141
+ case 'roomStartTime' :
142
+ setRoomStartTime ( data . startTime ) ;
143
+ break ;
139
144
default :
140
145
console . log ( "No messages received from room management server" ) ;
141
146
break ;
@@ -169,6 +174,8 @@ const CollaborationSpace = () => {
169
174
try {
170
175
// Filter out the current user from the usersSave array to find the matched user
171
176
const matchedUser = usersSave . filter ( user => user !== username ) [ 0 ] ; // Assuming usersSave contains objects with userId property
177
+ const startTime = new Date ( roomStartTime ) ; // Convert start time from ISO to Date object
178
+ const duration = new Date ( ) . getTime ( ) - startTime . getTime ( ) ;
172
179
173
180
if ( ! matchedUser ) {
174
181
throw new Error ( "No matched user found" ) ;
@@ -179,9 +186,11 @@ const CollaborationSpace = () => {
179
186
questionTitle : 'BFS' , // This ID should be available in context or passed down
180
187
// questionTitle: questionTitle, // This ID should be available in context or passed down
181
188
// startTime: roomCreationTime,
182
- startTime : new Date ( ) ,
189
+ // startTime: new Date(),
183
190
// duration: new Date().getTime() - new Date(roomCreationTime).getTime(),
184
- duration : 10 ,
191
+ // duration: 10,
192
+ startTime : startTime . toISOString ( ) ,
193
+ duration : Math . floor ( duration / 1000 ) ,
185
194
code : '1'
186
195
}
187
196
0 commit comments