@@ -23,7 +23,7 @@ const (
23
23
AUTH_FAIL = "auth_fail"
24
24
CLOSE_SESSION = "close_session"
25
25
CONTENT_CHANGE = "content_change"
26
- PING = "ping"
26
+ PING = "ping"
27
27
)
28
28
29
29
var upgrader = websocket.Upgrader {
@@ -140,7 +140,9 @@ func (h *Hub) Run() {
140
140
case message := <- h .broadcast :
141
141
h .mutex .Lock ()
142
142
// Update the current workspace for this RoomID
143
- h .workspaces [message .RoomID ] = message .Content
143
+ if message .Content != "" {
144
+ h .workspaces [message .RoomID ] = message .Content
145
+ }
144
146
for client := range h .clients {
145
147
if client .roomID == message .RoomID {
146
148
@@ -163,8 +165,6 @@ func (h *Hub) Run() {
163
165
h .mutex .Unlock ()
164
166
}
165
167
166
-
167
-
168
168
}
169
169
}
170
170
@@ -306,14 +306,14 @@ func handleMessages(
306
306
// if msgData["type"] == "ping" {
307
307
// //receives ping from client1, need to send a ping to client2
308
308
// //eventually, if present, client2 will send the ping back, which will be broadcasted back to client1.
309
-
309
+
310
310
// userID, _ := msgData["userId"].(string)
311
311
// request := Message {
312
312
// RoomID: client.roomID,
313
313
// UserID: userID,
314
314
// Content: []byte("ping request"),
315
315
// }
316
-
316
+
317
317
// hub.broadcast <- request
318
318
// }
319
319
@@ -348,29 +348,28 @@ func handleMessages(
348
348
} else if msgData .Type == PING {
349
349
// Broadcast the message to other clients
350
350
hub .broadcast <- Message {
351
- RoomID : client .roomID ,
352
- Type : msgData .Type ,
353
- UserID : msgData .UserID ,
351
+ RoomID : client .roomID ,
352
+ Type : msgData .Type ,
353
+ UserID : msgData .UserID ,
354
354
}
355
355
356
356
extendExpiryTime (msgData .UserID , persistMappings )
357
357
} else {
358
358
log .Printf ("Unknown message type: %s" , msgData .Type )
359
- }
359
+ }
360
360
}
361
361
}
362
362
363
363
func extendExpiryTime (userId string , persistMappings * verify.PersistMappings ) {
364
-
364
+
365
365
ctx := context .Background ()
366
- if err := persistMappings .Conn .Expire (ctx , userId , time .Minute * 10 ).Err (); err != nil {
366
+ if err := persistMappings .Conn .Expire (ctx , userId , time .Minute * 10 ).Err (); err != nil {
367
367
log .Println ("Error extending room time on ping: " , err .Error ())
368
368
} else {
369
-
369
+
370
370
log .Printf ("expiration reset for 10 minutes for user %s: " , userId )
371
371
}
372
-
373
-
372
+
374
373
}
375
374
376
375
type ClientWorkspace struct {
0 commit comments