Skip to content

Commit

Permalink
feat: add broadcast to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Baiguoshuai1 committed Nov 20, 2022
1 parent dba9427 commit dd70150
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions examples/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func createClient() {
panic(err)
}

err = c.On("/admin", func(h *shadiaosocketio.Channel, args Message) {
log.Println("--- Got admin message: ", args)
})
if err != nil {
panic(err)
}

err = c.On(shadiaosocketio.OnDisconnection, func(h *shadiaosocketio.Channel, reason websocket.CloseError) {
log.Println("Disconnected, code:", reason.Code, "text:", reason.Text)
})
Expand Down
4 changes: 4 additions & 0 deletions examples/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ socket.on('message', function(msg) {
console.log('received msg:', msg);
});

socket.on('/admin', function(msg) {
console.log('received admin msg:', msg);
});

socket.on('connect', function () {
console.log('socket connected');

Expand Down
6 changes: 4 additions & 2 deletions examples/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func main() {

c.Emit("message", Message{10, "main", "using emit"})

c.Join("admin")
c.BroadcastTo("admin", "/admin", Message{10, "main", "using broadcast"})
c.Join("room")
c.BroadcastTo("room", "/admin", Message{10, "main", "using broadcast"})

server.BroadcastTo("room", "/admin", Message{1, "boss", "hello everyone!"})
})
server.On(shadiaosocketio.OnDisconnection, func(c *shadiaosocketio.Channel) {
log.Println("received disconnect", c.Id())
Expand Down

0 comments on commit dd70150

Please sign in to comment.