Skip to content

Commit

Permalink
room connection ids added
Browse files Browse the repository at this point in the history
  • Loading branch information
asabya committed Sep 9, 2019
1 parent 3f1229f commit 5cb9851
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# go-socket.io

[![GoDoc](http://godoc.org/github.com/googollee/go-socket.io?status.svg)](http://godoc.org/github.com/googollee/go-socket.io) [![Build Status](https://travis-ci.org/googollee/go-socket.io.svg)](https://travis-ci.org/googollee/go-socket.io)
[![GoDoc](http://godoc.org/github.com/MathCody/go-socket.io?status.svg)](http://godoc.org/github.com/MathCody/go-socket.io) [![Build Status](https://travis-ci.org/MathCody/go-socket.io.svg)](https://travis-ci.org/MathCody/go-socket.io)

go-socket.io is an implementation of [Socket.IO](http://socket.io) in Golang, which is a realtime application framework.

Currently this library supports 1.4 version of the Socket.IO client. It supports room and namespaces.

**Help wanted** This project is looking for contributors to help fix bugs and implement new features. Please check [Issue 192](https://github.com/googollee/go-socket.io/issues/192). All help is much appreciated.

* for compatibility with Socket.IO 0.9.x, please use branch 0.9.x *

## Install

Install the package with:

```bash
go get github.com/googollee/go-socket.io
go get github.com/MathCody/go-socket.io
```

Import it with:

```go
import "github.com/googollee/go-socket.io"
import "github.com/MathCody/go-socket.io"
```

and use `socketio` as the package name inside the code.
Expand Down
15 changes: 15 additions & 0 deletions broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Broadcast interface {
SendAll(event string, args ...interface{}) // SendAll will send an event with args to all the rooms
Len(room string) int // Len gives number of connections in the room
Rooms(connection Conn) []string // Gives list of all the rooms if no connection given, else list of all the rooms the connection joined
ConnectionIDs(room string) []string // Gives list of connection ids in the room
}

// broadcast gives Join, Leave & BroadcastTO server API support to socket.io along with room management
Expand Down Expand Up @@ -123,6 +124,20 @@ func (broadcast *broadcast) Len(room string) int {
return len(broadcast.rooms[room])
}

// ConnectionIDs gives list of connection ids in the room
func (broadcast *broadcast) ConnectionIDs(room string) []string {
broadcast.lock.RLock()
defer broadcast.lock.RUnlock()

connectionIDs := make([]string, 0)

for _, connection := range broadcast.rooms[room] {
connectionIDs = append(connectionIDs, connection.ID())
}

return connectionIDs
}

// Rooms gives the list of all the rooms available for broadcast in case of
// no connection is given, in case of a connection is given, it gives
// list of all the rooms the connection is joined to
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

socketio "github.com/googollee/go-socket.io"
socketio "github.com/MathCody/go-socket.io"
)

func main() {
Expand Down
5 changes: 5 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (s *Server) RoomLen(room string) int {
return s.broadcast.Len(room)
}

// RoomLen gives number of connections in the room
func (s *Server) RoomConnectionIDs(room string) []string {
return s.broadcast.ConnectionIDs(room)
}

// Rooms gives list of all the rooms
func (s *Server) Rooms() []string {
return s.broadcast.Rooms(nil)
Expand Down

0 comments on commit 5cb9851

Please sign in to comment.