AmberWebsocketsExample
Version, currently master branch1 version
- master branchlatestJul 1, 2017
github.com/fridgerator/amber-websockets-example
Ambercr.io websockets example
Installation
# Add this to your shard.yml
dependencies:
AmberWebsocketsExample:
github: fridgerator/amber-websockets-example
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.22.0- License
- MIT
- Author
- Nick Franken
- Target
AmberWebsocketsExamplefrom src/AmberWebsocketsExample.cr
Dependencies
Runtime Dependencies
- amber*github: Amber-Crystal/amber, branch: master
- crecto0.6.0github: fridgerator/crecto
- sqlite3*github: Zhomart/crystal-sqlite3, branch: master
README
AmberWebsocketsExample
This is an example of Amber/Crystal using WebSockets.
Installation
$ crystal deps
$ amber r
Usage
Use to create a live app using Amber, possibly Mongo, Redis, Angular, React.js to help with your quest.
App ideas: Chat program, issue tracker, collaborative drawing, multiplayer games, collaborate music with web audio and web midi, web dj/shoutcast/radio type stuff, chat with new user of website in a popup window, multiplayer excel/word, receive a live news/blog feed from the server, etc
Development
Fork, clone, run with amber r or amber w to run or watch. Watch will reload (recompile and run) on changes.
socket_endpoint "/chat", UserSocket
Mounts the socket endpoint (the route that the server will accept WebSocket connections at.)
struct UserSocket < Amber::WebSockets::ClientSocket
channel "chat_room:*", ChatChannel
def on_connect
# do some authentication here
# return true or false, if false the socket will be closed
true
end
end
This is the User Socket with no authentication. Creates channel chat_room.
class ChatChannel < Amber::WebSockets::Channel
def handle_joined
end
def handle_message(msg)
rebroadcast!(msg)
end
end
This is the Chat Channel. It simply rebroadcasts every message that it receives (this is common for chat technologies.)
For information on how the frontend works, please see public/js/main.js. It's too long to display here in a code block but not hard to comprehend.
Contributing
- Fork it ( https://github.com/fridgerator/AmberWebsocketsExample/fork )
- Make your edits to master branch
- Commit and push to your fork
- Open and create a pull request
Contributors
- fridgerator Nick Franken - creator, maintainer
- mixflame Jon Silverman - documentation
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Jul 1, 2017
- Crystal
0.22.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/fridgerator/amber-websockets-example
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1