Skip to content

Commit bd06d03

Browse files
committed
(update): Optimized comments and code.
1 parent 7951ee9 commit bd06d03

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

socket/broadcast-operator.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ type RemoteSocket struct {
398398
operator *BroadcastOperator
399399
}
400400

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+
401414
func (r *RemoteSocket) Id() SocketId {
402415
return r.id
403416
}
@@ -414,18 +427,14 @@ func (r *RemoteSocket) Data() any {
414427
return r.data
415428
}
416429

417-
func NewRemoteSocket(adapter Adapter, details SocketDetails) *RemoteSocket {
418-
r := &RemoteSocket{}
419-
430+
func (r *RemoteSocket) Construct(adapter Adapter, details SocketDetails) {
420431
r.id = details.Id()
421432
r.handshake = details.Handshake()
422433
r.rooms = types.NewSet(details.Rooms().Keys()...)
423434
r.data = details.Data()
424435
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()
426437
})
427-
428-
return r
429438
}
430439

431440
// Adds a timeout in milliseconds for the next operation.
@@ -459,16 +468,22 @@ func (r *RemoteSocket) Emit(ev string, args ...any) error {
459468
}
460469

461470
// Joins a room.
471+
//
472+
// Param: Room - a [Room], or a [Room] slice to expand
462473
func (r *RemoteSocket) Join(room ...Room) {
463474
r.operator.SocketsJoin(room...)
464475
}
465476

466477
// Leaves a room.
478+
//
479+
// Param: Room - a [Room], or a [Room] slice to expand
467480
func (r *RemoteSocket) Leave(room ...Room) {
468481
r.operator.SocketsLeave(room...)
469482
}
470483

471484
// Disconnects this client.
485+
//
486+
// Param: close - if `true`, closes the underlying connection
472487
func (r *RemoteSocket) Disconnect(status bool) *RemoteSocket {
473488
r.operator.DisconnectSockets(status)
474489
return r

0 commit comments

Comments
 (0)