• Stars
    star
    26
  • Rank 900,985 (Top 19 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Phoenix Channels client for Crystal

phoenix.cr

Phoenix Channels client for Crystal

Installation

Add this to your application's shard.yml:

dependencies:
  phoenix:
    github: dtcristo/phoenix.cr

Usage

The example below shows basic usage; connecting to a socket, joining a channel, binding to an event and sending messages.

require "phoenix"

# Create socket and connect to it
socket = Phoenix::Socket.new("http://example.com/socket")
socket.connect

# Initiate a channel, bind to an event and join
channel = socket.channel("topic:subtopic")
channel.on "event" do |payload|
  # do stuff with payload
end
channel.join

# Start a loop and send a message down the channel every second
loop do
  sleep 1
  channel.push("new_msg", JSON::Any.new({"text" => JSON::Any.new("Hello world!")}))
end

The Phoenix Channels docs provide details on implementing sockets and channels on the server side. The phoenix.cr docs detail the client side API available for use in your Crystal application.

Chat example

examples/chat.cr demonstates an example chat client.

Start the phoenix-chat server example:

git clone https://github.com/dtcristo/phoenix-chat
cd phoenix-chat
mix deps.get
mix phx.server

Run the chat client:

crystal examples/chat.cr

Follow the prompts to enter your name and chat away.

Todo

  • Improve test coverage
  • Implement Presence
  • Build larger example application

Contributors

  • dtcristo David Cristofaro - creator, maintainer

Credits

More Repositories

1

bevy_pixels

Bevy plugin that uses Pixels (a tiny pixel buffer) for rendering
Rust
83
star
2

wasmtime-ruby

Ruby bindings for Wasmtime, a WebAssembly runtime
Ruby
29
star
3

middleman-cactus

🌵 Cactus theme for Middleman
SCSS
9
star
4

raycaster

🔆 Experimental ray casting renderer
Ruby
7
star
5

tap-racer

Tap your way to victory
Elixir
7
star
6

microbit-demos

Rust demos running on the BBC micro:bit
Rust
7
star
7

mandelbrot

🔮 Mandelbrot set in Rust
TypeScript
7
star
8

gomoku

The classic five-in-a-row board game
Ruby
5
star
9

intro-to-wasm-in-rust

Examples from "Intro to WASM in Rust" talk
HTML
5
star
10

raylib-rust

Rust bindings for raylib, a simple and easy-to-use library to learn videogames programming
Rust
5
star
11

middleman-rackspace

☁️ Deploy your Middleman site to Rackspace Cloud Files
Ruby
4
star
12

musiquely

🎶 Micromanage your playlists
Ruby
4
star
13

sweet-talk

💬 Simple chatroom
Ruby
4
star
14

nwb-elm-app

🚧 Elm app template for nwb
Elm
3
star
15

virtucane

👓 Assistive technology for the visually impaired
C++
3
star
16

high-score

🏆 High scores for Ballout
Elixir
3
star
17

gpt-html

GPT website generator
Rust
3
star
18

stimulus-turbolinks-demo

Example usage of Stimulus with Turbolinks
Ruby
2
star
19

metacoin-ui

🔶 Ethereum MetaCoin Ðapp
JavaScript
2
star
20

poxels

Interactive polygon builder
TypeScript
2
star
21

dtcristo.com

🖊 Personal homepage and blog
SCSS
2
star
22

webgl-demos

Adventures in WebGL
JavaScript
2
star
23

cray-examples

🦞 raylib examples ported to Crystal
1
star
24

gke-builder

🛠️ Google Kubernetes Engine image builder
Dockerfile
1
star
25

read_text

📢 Command line tool for speaking text in an image
C++
1
star
26

exercism

😈 My solutions to exercism.io
Elm
1
star
27

phoenix-chat

💬 Phoenix Channels chat example
JavaScript
1
star
28

advent-of-code

⭐ My solutions to Advent of Code
Rust
1
star