Comments (1)
Hi @khataev ,
Thank you for opening this issue.
It seems that the example code in examples/chat.rb
is outdated.
I'm not sure why the named arguments don't work or at which point (version) did the code break, but generally speaking, the updated code should look like this:
# finish with `exit` if running within `irb`
require 'plezi'
class ChatServer
def index
"Use Websockets to connect."
end
def on_open
return close unless params['id']
@name = params['id']
subscribe :chat
publish "chat", "#{@name} joind the chat."
write "Welcome, #{@name}!"
# if we have Redis
if(Iodine::PubSub.default.is_a? Iodine::PubSub::Redis)
# We'll add the name to the list of people in the chat.
# Blocks are used as event callbacks and are executed asynchronously.
Iodine::PubSub.default.send("SADD", "chat_members", @name) do
# after the name was added, we'll get all the current people in the chat
Iodine::PubSub.default.send("SMEMBERS", "chat_members") do |members|
# By now, we're outside the Websocket connection's lock.
# To safely access the connection, we'll use `defer`
write "Currently in the chatroom: #{members.join ', '}"
end
end
end
end
def on_close
publish "chat", "#{@name} joind the chat."
# if we have Redis
Iodine::PubSub.default.send("SREM", "chat_members", @name) if(Iodine::PubSub.default.is_a? Iodine::PubSub::Redis)
end
def on_message data
publish "chat", "#{@name}: #{data}"
end
end
path_to_client = File.expand_path( File.dirname(__FILE__) )
Plezi.templates = path_to_client
Plezi.route '/', ChatServer
As you can see:
-
the named arguments (i.e.,
channel: "chat"
) were replaced with simple arguments (:chat
or"chat"
would do). -
the
Iodine.default_pubsub
method (pre 0.7.x API) was replaced:Iodine::PubSub.default
As for connecting to the example server, please add a username to the path. i.e.:
ws = new WebSocket("ws://localhost:3000/Joe");
Good Luck!
Bo.
from plezi.
Related Issues (20)
- ERROR -- : uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable (NameError) HOT 10
- ERROR -- : incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError) HOT 11
- Documentation help needed. HOT 2
- WebSocket connection to 'ws://localhost:3000/ws' failed: Error during WebSocket handshake: Unexpected response code: 200 HOT 21
- JSON event length is limited HOT 10
- Server configs HOT 4
- download error with bundled client.js HOT 1
- rabbitmq HOT 1
- Finding a websocket session and send message HOT 8
- SyntaxError in generated config.ru
- Rack < 2.0 : cannot load such file -- rack/query_parser.rb HOT 1
- message_size_limit uninitialized constant Iodine::Http HOT 10
- create function is not synchronized HOT 19
- server shutdown when one or more client has a poor connection HOT 7
- Upgrade to bundler 2.0 HOT 3
- Failing at higher concurrency HOT 2
- Gap in documentation for serving static assets HOT 3
- Architectural clarification HOT 2
- There is no way to unsubscribe from Plezi::Controller.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plezi.