Relay.js allows you to establish a one-to-many channel of communication from the comfort of your browser. It uses Socket.IO to establish a websocket from your browser to the relay hub, and from the other users to the relay hub.
Want to skip to the juice and try it? Go here to make a whiteboard app channel (Source).
-
You open some HTML with the relay.js library and open a websocket to a relay hub. You can host your own hub, or use a public one:
<script src="http://cdn.socket.io/stable/socket.io.js"></script> <script src="https://github.com/shazow/relay.js/raw/master/src/relay.js"></script> <script type="text/javascript"> // Open a socket to a hub using socket.io var socket = new io.Socket('hub.relayjs.com', {port: 8080}); // Connect to the relay using the socket var relay = new Relay(socket); </script>
-
Create a channel on the relay hub with a client logic payload:
relay.create(function() { alert('Hello World.'); });
-
Open your HTML in your browser to execute the code. When the channel is ready, the
relay.channel
variable will contain the channel id. Now you can invite people to join your relay channel using any compatible client, or use the example one provided here:http://relayjs.com/client/#!/<channel id>
-
When somebody connects to your channel, your browser will get
joined
message with the user id. The person who joined will receive the client logic payload you defined earlier and execute it. They should see a "Hello World" alert pop up.
There is an example implementation of a Relay.js hub using node.js under examples/hubs/nodejs.
create <code>
: Create a channel.join <channel id>
: Join a channel.
msg <from> <to> <message>
: Send a message to the channel.from
is your user id andto
is either the target user id or one ofall
,op
,users
. (Note: Thefrom
field will probably go away soon.)
The authoratative client implementation lives in src/relay.js.
id <user id>
: Your user id, received upon connecting.error <message>
: Error message.code <code>
: (When joining) Client code sent by the channel operator, should be executed.destroyed
: (When joining) Channel is destroyed because the operator left.created <channel id>
: (When creating) Channel id of the created channel.joined <user id>
: (When creating) User joined your channel.leaving <user id>
: (When creating) User leaving your channel.msg <from> <to> <message>
: Received a message from the channel from user idfrom
to targetto
(one ofall
,op
,users
, or your user id).
You can build more command logic on top of the msg
command.
See the examples directory.
- Chat
- Collaborative whiteboard
- (Soon) Map-reduce cluster
- (Soon) 1v1 board game (chess?)
- (Someday) MMORPG with channel portals
- Prompt user before executing the client logic from the operator.
- Everything else.