A Gorilla WebSocket implementation with support for rooms.
go get -u github.com/joncody/wsrooms
Connects to a wsrooms WebSocket server and returns the root Room.
Name | Type | Description |
---|---|---|
url | String | The WebSocket URL to connect to. |
A wsrooms communication channel.
The Room name.
Adds an event listener to the Room.
Name | Type | Description |
---|---|---|
event | String | The event to listen for. |
executable | Function | The callback to run. |
Gets the Room connection status.
Gets the Room members (a list of their uuids).
Gets the local WebSocket connection uuid.
Sends a message to the server.
Name | Type | Description |
---|---|---|
event | String | The name of the event. |
payload | Any | The message data. |
dst | String (optional, default: "") | The destination uuid. |
Joins a Room. If the Room does not exist, it is created.
Name | Type | Description |
---|---|---|
roomname | String | The name of the room. |
Leaves the Room.
Handles received messages after they have been converted to an object. The Room emits the event, payload, and source of the message if the event name is not reserved.
Name | Type | Description |
---|---|---|
packet | Object | The message adhering to the wsrooms protocol. |
Leaves all Rooms other than the root Room.
Returns all currently joined rooms.
Name | Parameters | Description |
---|---|---|
open | Fired when the Room has been successfully joined. | |
joined | id (String) | Fired when another connection is made to the Room. |
left | id (String) | Fired when another member disconnects from the Room. |
close | Fired when the Room has been successfully left. |