Skip to content

A Gorilla WebSocket implementation with support for rooms.

License

Notifications You must be signed in to change notification settings

joncody/wsrooms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wsrooms

A Gorilla WebSocket implementation with support for rooms.

GoDoc

Installation

go get -u github.com/joncody/wsrooms

Browser API

wsrooms(url) -> {Room}

Connects to a wsrooms WebSocket server and returns the root Room.

Parameters
Name Type Description
url String The WebSocket URL to connect to.

Room

A wsrooms communication channel.

Properties

name -> {String}

The Room name.


Methods

on(event, executable)

Adds an event listener to the Room.

Parameters
Name Type Description
event String The event to listen for.
executable Function The callback to run.

open() -> {Boolean}

Gets the Room connection status.


members() -> {Array}

Gets the Room members (a list of their uuids).


id() -> {String}

Gets the local WebSocket connection uuid.


send(event, payload, dst)

Sends a message to the server.

Parameters
Name Type Description
event String The name of the event.
payload Any The message data.
dst String (optional, default: "") The destination uuid.

join(roomname) -> {Room}

Joins a Room. If the Room does not exist, it is created.

Parameters
Name Type Description
roomname String The name of the room.

leave()

Leaves the Room.


parse(packet)

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.

Parameters
Name Type Description
packet Object The message adhering to the wsrooms protocol.

purge() *root room only

Leaves all Rooms other than the root Room.


rooms() *root room only

Returns all currently joined rooms.


Events

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.

About

A Gorilla WebSocket implementation with support for rooms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published