Skip to content

tapocol/sarb-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket Action Ruby Chat

An example app using Socket Action Ruby (sarb) to showcase a simple chat app.

Usage

After git clone and cd to directory:

$ bundle
$ ruby app.rb

Javascript Console 1:

var ws = new WebSocket("ws://127.0.0.1:8080/")
ws.onmessage = function(message) { console.log(message) };
ws.send(JSON.stringify({ action: "chat", args: { "chat": "Hello" } })) // Should receive message stating "You must auth first"
ws.send(JSON.stringify({ action: "auth", args: { "name": "Craig" } }))
ws.send(JSON.stringify({ action: "chat", args: { "chat": "sudo Hello" } })) // No message received now. I set up app.rb to send to all users except the one sending it.

Javascript Console 2:

var ws = new WebSocket("ws://127.0.0.1:8080/")
ws.onmessage = function(message) { console.log(message) };
ws.send(JSON.stringify({ action: "auth", args: { "name": "Other Guy" } }))
ws.send(JSON.stringify({ action: "chat", args: { "chat": "Hi" } }))

Back to Javascript Console 1 (you have a message waiting, probably should reply):

// Should receive message stating "Other Guy: Hi"
ws.send(JSON.stringify({ action: "chat", args: { "chat": "Hello" } }))

Back to Javascript Console 2 (OMG, someone is talking to you):

// Should receive message stating "Craig: Hello"

Feel free to continue your dirty discussions with yourself in your own private chat sockets.

License

The MIT License - Copyright (c) 2012-2013 Craig Jackson

About

An example chat app using Socket Action Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages