Sha256: 7c54d586ac9c4e8ddf053bc7f2922d43e77027240736b4327ca1db16c7f0d262

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

module Phoenix
  class Socket
    include Native

    alias_native :connect

    def initialize(url, params = {})
      super(`new Phoenix.Socket(#{url.to_s}, #{params.to_n})`)
    end

    def channel(topic, *params)
      chan = Channel.new(topic, params, @native)
      `#{@native}.channels.push(#{chan.to_n})`
      chan
    end

    def on_error(&block)
      `#{@native}.onError(#{callback(block)})`
    end

    def on_close(&block)
      `#{@native}.onClose(#{callback(block)})`
    end

    def callback(block)
      proc do |e|
        block.call(Native(e))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-phoenix-0.0.3 opal/phoenix/socket.rb