Opal wrapper for Phoenix Framework javascript library.
Ruby
Latest commit 962b09e Mar 10, 2016 @fazibear bump version
Permalink
Failed to load latest commit information.
lib cleanup Nov 15, 2015
opal return hash Mar 10, 2016
.codeclimate.yml update codeclimate config Nov 28, 2015
.gitignore initial commit Nov 15, 2015
Gemfile initial commit Nov 15, 2015
LICENSE.md add license Nov 27, 2015
README.md fix channel params Nov 27, 2015
Rakefile move js dependencies to vendor Nov 28, 2015
opal-phoenix.gemspec bump version Mar 10, 2016

README.md

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' }