Giter Site home page Giter Site logo

Help needed! about plezi HOT 1 CLOSED

boazsegev avatar boazsegev commented on May 18, 2024
Help needed!

from plezi.

Comments (1)

boazsegev avatar boazsegev commented on May 18, 2024

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:

  1. the named arguments (i.e., channel: "chat") were replaced with simple arguments (:chat or "chat" would do).

  2. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.