Skip to content

Commit 76db3d9

Browse files
committed
Clarify documentation and argument names
Correct grammatical errors with the documentation, and change parts where the documentation and argument names will state "message" when it actually means "event".
1 parent 76e104d commit 76db3d9

File tree

8 files changed

+46
-48
lines changed

8 files changed

+46
-48
lines changed

adapter.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package socketio
22

3-
// BroadcastAdaptor is the adaptor to handle broadcast.
3+
// BroadcastAdaptor is the adaptor to handle broadcasts.
44
type BroadcastAdaptor interface {
55

6-
// Join lets socket join the t room.
6+
// Join lets the socket join a room.
77
Join(room string, socket Socket) error
88

9-
// Leave let socket leave the room.
9+
// Leave lets the socket leave a room.
1010
Leave(room string, socket Socket) error
1111

12-
// Send will send the message with args to room. If ignore is not nil, it won't send to the socket ignore.
13-
Send(ignore Socket, room, message string, args ...interface{}) error
12+
// Send will send an event with args to the room. If ignore is not nil, the event will be excluded from being sent to the socket ignore.
13+
Send(ignore Socket, room, event string, args ...interface{}) error
1414
}
1515

1616
var newBroadcast = newBroadcastDefault
@@ -45,13 +45,13 @@ func (b broadcast) Leave(room string, socket Socket) error {
4545
return nil
4646
}
4747

48-
func (b broadcast) Send(ignore Socket, room, message string, args ...interface{}) error {
48+
func (b broadcast) Send(ignore Socket, room, event string, args ...interface{}) error {
4949
sockets := b[room]
5050
for id, s := range sockets {
5151
if ignore != nil && ignore.Id() == id {
5252
continue
5353
}
54-
s.Emit(message, args...)
54+
s.Emit(event, args...)
5555
}
5656
return nil
5757
}

attachment.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"reflect"
99
)
1010

11-
// Attachment is an attachment handler used in emit args. All attachments will send as binary in transport layer. When use attachment, make sure use as pointer.
11+
// Attachment is an attachment handler used in emit args. All attachments will be sent as binary data in the transport layer. When using an attachment, make sure it is a pointer.
1212
//
1313
// For example:
1414
//
@@ -30,8 +30,6 @@ import (
3030
// b, _ := ioutil.ReadAll(arg.File.Data)
3131
// })
3232
type Attachment struct {
33-
34-
// Data is the ReadWriter of the attachment data.
3533
Data io.ReadWriter
3634
num int
3735
}

example/asset/socket.io.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ JSONPPolling.prototype.doPoll = function () {
25122512
this.script = script;
25132513

25142514
var isUAgecko = 'undefined' != typeof navigator && /gecko/i.test(navigator.userAgent);
2515-
2515+
25162516
if (isUAgecko) {
25172517
setTimeout(function () {
25182518
var iframe = document.createElement('iframe');
@@ -4548,7 +4548,7 @@ module.exports = hasBinary;
45484548

45494549
function hasBinary(data) {
45504550

4551-
function recursiveCheckForBinary(obj) {
4551+
function recursiveCheckForBinary(obj) {
45524552
if (!obj) return false;
45534553

45544554
if ( (global.Buffer && Buffer.isBuffer(obj)) ||

handler.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ func newBaseHandler(name string, broadcast BroadcastAdaptor) *baseHandler {
1919
}
2020
}
2121

22-
// On registers the function f to handle message.
23-
func (h *baseHandler) On(message string, f interface{}) error {
22+
// On registers the function f to handle an event.
23+
func (h *baseHandler) On(event string, f interface{}) error {
2424
c, err := newCaller(f)
2525
if err != nil {
2626
return err
2727
}
28-
h.events[message] = c
28+
h.events[event] = c
2929
return nil
3030
}
3131

@@ -52,7 +52,7 @@ func newSocketHandler(s *socket, base *baseHandler) *socketHandler {
5252
}
5353
}
5454

55-
func (h *socketHandler) Emit(message string, args ...interface{}) error {
55+
func (h *socketHandler) Emit(event string, args ...interface{}) error {
5656
var c *caller
5757
if l := len(args); l > 0 {
5858
fv := reflect.ValueOf(args[l-1])
@@ -65,7 +65,7 @@ func (h *socketHandler) Emit(message string, args ...interface{}) error {
6565
args = args[:l-1]
6666
}
6767
}
68-
args = append([]interface{}{message}, args...)
68+
args = append([]interface{}{event}, args...)
6969
if c != nil {
7070
id, err := h.socket.sendId(args)
7171
if err != nil {
@@ -112,12 +112,12 @@ func (h *socketHandler) LeaveAll() error {
112112
return nil
113113
}
114114

115-
func (h *baseHandler) BroadcastTo(room, message string, args ...interface{}) error {
116-
return h.broadcast.Send(nil, h.broadcastName(room), message, args...)
115+
func (h *baseHandler) BroadcastTo(room, event string, args ...interface{}) error {
116+
return h.broadcast.Send(nil, h.broadcastName(room), event, args...)
117117
}
118118

119-
func (h *socketHandler) BroadcastTo(room, message string, args ...interface{}) error {
120-
return h.baseHandler.broadcast.Send(h.socket, h.broadcastName(room), message, args...)
119+
func (h *socketHandler) BroadcastTo(room, event string, args ...interface{}) error {
120+
return h.baseHandler.broadcast.Send(h.socket, h.broadcastName(room), event, args...)
121121
}
122122

123123
func (h *baseHandler) broadcastName(room string) string {

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
go-socket.io is the implement of socket.io in golang.
2+
go-socket.io is a server implementation of socket.io in golang.
33
4-
It is compatible with node.js implement.
4+
It is compatible with the official Node.js implementation.
55
*/
66
package socketio

namespace.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package socketio
22

3-
// Namespace is the name space of socket.io handler.
3+
// Namespace is the name space of a socket.io handler.
44
type Namespace interface {
55

6-
// Name returns the name of namespace.
6+
// Name returns the name of the namespace.
77
Name() string
88

99
// Of returns the namespace with given name.
1010
Of(name string) Namespace
1111

12-
// On registers the function f to handle message.
13-
On(message string, f interface{}) error
12+
// On registers the function f to handle an event.
13+
On(event string, f interface{}) error
1414
}
1515

1616
type namespace struct {

server.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Server struct {
1313
eio *engineio.Server
1414
}
1515

16-
// NewServer returns the server supported given transports. If transports is nil, server will use ["polling", "websocket"] as default.
16+
// NewServer returns the server supported given transports. If transports is nil, the server will use ["polling", "websocket"] as default.
1717
func NewServer(transportNames []string) (*Server, error) {
1818
eio, err := engineio.NewServer(transportNames)
1919
if err != nil {
@@ -27,57 +27,57 @@ func NewServer(transportNames []string) (*Server, error) {
2727
return ret, nil
2828
}
2929

30-
// SetPingTimeout sets the timeout of ping. When time out, server will close connection. Default is 60s.
30+
// SetPingTimeout sets the timeout of a connection ping. When it times out, the server will close the connection with the client. Default is 60s.
3131
func (s *Server) SetPingTimeout(t time.Duration) {
3232
s.eio.SetPingTimeout(t)
3333
}
3434

35-
// SetPingInterval sets the interval of ping. Default is 25s.
35+
// SetPingInterval sets the interval of pings. Default is 25s.
3636
func (s *Server) SetPingInterval(t time.Duration) {
3737
s.eio.SetPingInterval(t)
3838
}
3939

40-
// SetMaxConnection sets the max connetion. Default is 1000.
40+
// SetMaxConnection sets the maximum number of connections with clients. Default is 1000.
4141
func (s *Server) SetMaxConnection(n int) {
4242
s.eio.SetMaxConnection(n)
4343
}
4444

45-
// SetAllowRequest sets the middleware function when establish connection. If it return non-nil, connection won't be established. Default will allow all request.
45+
// SetAllowRequest sets the middleware function when a connection is established. If a non-nil value is returned, the connection won't be established. Default will allow all connections.
4646
func (s *Server) SetAllowRequest(f func(*http.Request) error) {
4747
s.eio.SetAllowRequest(f)
4848
}
4949

50-
// SetAllowUpgrades sets whether server allows transport upgrade. Default is true.
50+
// SetAllowUpgrades sets whether server allows transport upgrades. Default is true.
5151
func (s *Server) SetAllowUpgrades(allow bool) {
5252
s.eio.SetAllowUpgrades(allow)
5353
}
5454

55-
// SetCookie sets the name of cookie which used by engine.io. Default is "io".
55+
// SetCookie sets the name of the cookie used by engine.io. Default is "io".
5656
func (s *Server) SetCookie(prefix string) {
5757
s.eio.SetCookie(prefix)
5858
}
5959

60-
// SetNewId sets the callback func to generate new connection id. By default, id is generated from remote addr + current time stamp
60+
// SetNewId sets the callback func to generate new connection id. By default, id is generated from remote address + current time stamp
6161
func (s *Server) SetNewId(f func(*http.Request) string) {
6262
s.eio.SetNewId(f)
6363
}
6464

65-
// SetSessionsManager sets the sessions as server's session manager. Default sessions is single process manager. You can custom it as load balance.
65+
// SetSessionsManager sets the sessions as server's session manager. Default sessions is a single process manager. You can customize it as a load balancer.
6666
func (s *Server) SetSessionManager(sessions engineio.Sessions) {
6767
s.eio.SetSessionManager(sessions)
6868
}
6969

70-
// SetAdaptor sets the adaptor of broadcast. Default is in-process broadcast implement.
70+
// SetAdaptor sets the adaptor of broadcast. Default is an in-process broadcast implementation.
7171
func (s *Server) SetAdaptor(adaptor BroadcastAdaptor) {
7272
s.namespace = newNamespace(adaptor)
7373
}
7474

75-
// ServeHTTP handles http request.
75+
// ServeHTTP handles http requests.
7676
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7777
s.eio.ServeHTTP(w, r)
7878
}
7979

80-
// Server level broadcasts function.
80+
// BroadcastTo is a server level broadcast function.
8181
func (s *Server) BroadcastTo(room, message string, args ...interface{}) {
8282
s.namespace.BroadcastTo(room, message, args...)
8383
}

socket.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ type Socket interface {
1818
// Request returns the first http request when established connection.
1919
Request() *http.Request
2020

21-
// On registers the function f to handle message.
22-
On(message string, f interface{}) error
21+
// On registers the function f to handle an event.
22+
On(event string, f interface{}) error
2323

24-
// Emit emits the message with given args.
25-
Emit(message string, args ...interface{}) error
24+
// Emit emits an event with given args.
25+
Emit(event string, args ...interface{}) error
2626

2727
// Join joins the room.
2828
Join(room string) error
2929

3030
// Leave leaves the room.
3131
Leave(room string) error
3232

33-
// BroadcastTo broadcasts the message to the room with given args.
34-
BroadcastTo(room, message string, args ...interface{}) error
33+
// BroadcastTo broadcasts an event to the room with given args.
34+
BroadcastTo(room, event string, args ...interface{}) error
3535
}
3636

3737
type socket struct {
@@ -57,11 +57,11 @@ func (s *socket) Request() *http.Request {
5757
return s.conn.Request()
5858
}
5959

60-
func (s *socket) Emit(message string, args ...interface{}) error {
61-
if err := s.socketHandler.Emit(message, args...); err != nil {
60+
func (s *socket) Emit(event string, args ...interface{}) error {
61+
if err := s.socketHandler.Emit(event, args...); err != nil {
6262
return err
6363
}
64-
if message == "disconnect" {
64+
if event == "disconnect" {
6565
s.conn.Close()
6666
}
6767
return nil

0 commit comments

Comments
 (0)