Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fazibear/opal-phoenix
Opal wrapper for Phoenix Framework javascript library.
https://github.com/fazibear/opal-phoenix
Last synced: 3 months ago
JSON representation
Opal wrapper for Phoenix Framework javascript library.
- Host: GitHub
- URL: https://github.com/fazibear/opal-phoenix
- Owner: fazibear
- License: mit
- Created: 2015-11-15T15:54:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-17T10:24:13.000Z (over 6 years ago)
- Last Synced: 2024-05-01T19:58:01.311Z (9 months ago)
- Language: Ruby
- Homepage:
- Size: 36.1 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-opal - Opal Phoenix - Opal wrapper for Phoenix Framework javascript library (Uncategorized / Uncategorized)
README
# opal-phoenix [![Gem Version](https://badge.fury.io/rb/opal-phoenix.svg)](http://badge.fury.io/rb/opal-phoenix) [![Code Climate](https://codeclimate.com/github/fazibear/opal-phoenix/badges/gpa.svg)](https://codeclimate.com/github/fazibear/opal-phoenix)
Opal wrapper for [Phoenix Framework](http://phoenixframework.org) javascript library.
## usage
### Server side
config.ru, Rakefile, Rails, Sinatra, etc.```ruby
require 'opal-phoenix'
```Gemfile
```ruby
gem 'opal-phoenix'
```### Browser side
```ruby
require 'phoenix'# setup socket
socket = Phoenix::Socket.new('ws://localhost:4000/ws', params: {some: 'param'})socket.on_error do
$console.log 'socket error!'
endsocket.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!'
endchannel.on_close do
$console.log 'channel closed!'
endchannel.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](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/bePatron?u=6912974)