0.0
No commit activity in last 3 years
No release in over 3 years
Phoenix client wrapper for opal
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0

Runtime

~> 0
 Project Readme

opal-phoenix Gem Version Code Climate

Opal wrapper for Phoenix Framework javascript library.

usage

Server side

config.ru, Rakefile, Rails, Sinatra, etc.

require 'opal-phoenix'

Gemfile

gem 'opal-phoenix'

Browser side

require 'phoenix'

# setup socket
socket = Phoenix::Socket.new('ws://localhost:4000/ws', params: {some: 'param'})

socket.on_error do
  $console.log 'socket error!'
end

socket.on_close do
  $console.log 'socket closed!'
end

# connect to socket
socket.connect

# setup channel
channel = socket.channel('lobby', other: 'param')

channel.on_error do
  $console.log 'channel error!'
end

channel.on_close do
  $console.log 'channel closed!'
end

channel.on 'msg' do |payload|
  $console.log "payload: #{payload}"
end

# join channel
channel
  .join
  .receive('ok') { $console.log 'ok' }
  .receive('failed') { $console.log 'failed' }

# push a message
channel
  .push("msg", {a: :b})
  .receive('ok') { $console.log 'ok' }
  .receive('failed') { $console.log 'failed' }

Thank you!

Become Patreon