Skip to content

Commit

Permalink
update: Customize the json field name of *Handshake, refactor the `…
Browse files Browse the repository at this point in the history
…FetchSockets(*BroadcastOptions)` interface to return `[]SocketDetails` instead of `[]any`
  • Loading branch information
zishang520 committed Jul 31, 2023
1 parent 9744f38 commit 7c47c89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion socket/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (a *adapter) SocketRooms(id SocketId) *types.Set[Room] {
}

// Returns the matching socket instances
func (a *adapter) FetchSockets(opts *BroadcastOptions) (sockets []any) {
func (a *adapter) FetchSockets(opts *BroadcastOptions) (sockets []SocketDetails) {
a.apply(opts, func(socket *Socket) {
sockets = append(sockets, socket)
})
Expand Down
18 changes: 9 additions & 9 deletions socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ var (

type Handshake struct {
// The headers sent as part of the handshake
Headers *utils.ParameterBag
Headers *utils.ParameterBag `json:"headers,omitempty"`
// The date of creation (as string)
Time string
Time string `json:"time,omitempty"`
// The ip of the client
Address string
Address string `json:"address,omitempty"`
// Whether the connection is cross-domain
Xdomain bool
Xdomain bool `json:"xdomain,omitempty"`
// Whether the connection is secure
Secure bool
Secure bool `json:"secure,omitempty"`
// The date of creation (as unix timestamp)
Issued int64
Issued int64 `json:"issued,omitempty"`
// The request URL string
Url string
Url string `json:"url,omitempty"`
// The query object
Query *utils.ParameterBag
Query *utils.ParameterBag `json:"query,omitempty"`
// The auth object
Auth any
Auth any `json:"auth,omitempty"`
}

type Socket struct {
Expand Down
2 changes: 1 addition & 1 deletion socket/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Adapter interface {
SocketRooms(SocketId) *types.Set[Room]

// Returns the matching socket instances
FetchSockets(*BroadcastOptions) []any
FetchSockets(*BroadcastOptions) []SocketDetails

// Makes the matching socket instances join the specified rooms
AddSockets(*BroadcastOptions, []Room)
Expand Down

0 comments on commit 7c47c89

Please sign in to comment.