Sha256: 9943b638471ce5043a19ff36f9be5d497dbfa12aca8f1e1efe5064efc6f65b9f

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

#!/usr/bin/env ruby
require 'benchmark'
Dir.chdir(File.expand_path(File.join('..', '..', 'lib'), __FILE__))
require 'bundler/setup'
require 'plezi'
class WebsocketSample
  # every request that routes to this controller will create a new instance
  def initialize
  end

  # Http methods are available
  def index
    'Hello World!'
  end

  # RESTful methods are available
  def show
    "showing object with id: #{params['id']}..."
  end

  # called before the protocol is swithed from HTTP to WebSockets.
  #
  # this allows setting headers, cookies and other data (such as authentication)
  # prior to opening a WebSocket.
  #
  # if the method returns false, the connection will be refused and the remaining routes will be attempted.
  def pre_connect
    true
  end

  # called immediately after a WebSocket connection has been established.
  # it blocks all the connection's actions until the `on_open` initialization is finished.
  def on_open
  end

  # called when new data is recieved
  #
  # data is a string that contains binary or UTF8 (message dependent) data.
  def on_message(data)
    Plezi.info "Websocket got: #{data}"
  end

  # called once, AFTER the connection was closed.
  def on_close
  end

  # called once, during **server shutdown**, BEFORE the connection is closed.
  # this will only be called for connections that are open while the server is shutting down.
  def on_shutdown
  end
end
Plezi.route '/', WebsocketSample

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plezi-0.14.0 bin/hello_world