@@ -398,6 +398,19 @@ type RemoteSocket struct {
398
398
operator * BroadcastOperator
399
399
}
400
400
401
+ func MakeRemoteSocket () * RemoteSocket {
402
+ r := & RemoteSocket {}
403
+ return r
404
+ }
405
+
406
+ func NewRemoteSocket (adapter Adapter , details SocketDetails ) * RemoteSocket {
407
+ r := MakeRemoteSocket ()
408
+
409
+ r .Construct (adapter , details )
410
+
411
+ return r
412
+ }
413
+
401
414
func (r * RemoteSocket ) Id () SocketId {
402
415
return r .id
403
416
}
@@ -414,18 +427,14 @@ func (r *RemoteSocket) Data() any {
414
427
return r .data
415
428
}
416
429
417
- func NewRemoteSocket (adapter Adapter , details SocketDetails ) * RemoteSocket {
418
- r := & RemoteSocket {}
419
-
430
+ func (r * RemoteSocket ) Construct (adapter Adapter , details SocketDetails ) {
420
431
r .id = details .Id ()
421
432
r .handshake = details .Handshake ()
422
433
r .rooms = types .NewSet (details .Rooms ().Keys ()... )
423
434
r .data = details .Data ()
424
435
r .operator = NewBroadcastOperator (adapter , types .NewSet (Room (r .id )), types .NewSet [Room ](), & BroadcastFlags {
425
- ExpectSingleResponse : true ,
436
+ ExpectSingleResponse : true , // so that remoteSocket.Emit() with acknowledgement behaves like socket.Emit()
426
437
})
427
-
428
- return r
429
438
}
430
439
431
440
// Adds a timeout in milliseconds for the next operation.
@@ -459,16 +468,22 @@ func (r *RemoteSocket) Emit(ev string, args ...any) error {
459
468
}
460
469
461
470
// Joins a room.
471
+ //
472
+ // Param: Room - a [Room], or a [Room] slice to expand
462
473
func (r * RemoteSocket ) Join (room ... Room ) {
463
474
r .operator .SocketsJoin (room ... )
464
475
}
465
476
466
477
// Leaves a room.
478
+ //
479
+ // Param: Room - a [Room], or a [Room] slice to expand
467
480
func (r * RemoteSocket ) Leave (room ... Room ) {
468
481
r .operator .SocketsLeave (room ... )
469
482
}
470
483
471
484
// Disconnects this client.
485
+ //
486
+ // Param: close - if `true`, closes the underlying connection
472
487
func (r * RemoteSocket ) Disconnect (status bool ) * RemoteSocket {
473
488
r .operator .DisconnectSockets (status )
474
489
return r
0 commit comments