Sha256: ac2ac290a5c5394facc6c9c96b3fd2264cf789ffab2222ddac745f9f8bde5f8c

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require_relative "realm"

module Wamp
  module Router
    # Auth
    class Authenticator
      def self.authenticate(request)
        Wampproto::Acceptor::Response.new(request.authid, "role", "secret")
      end
    end

    # Server Session
    class Client
      attr_accessor :router, :connection
      attr_reader   :acceptor, :serializer

      def initialize(serializer = Wampproto::Serializer::JSON, authenticator = Authenticator)
        @serializer = serializer
        @acceptor = Wampproto::Acceptor.new(serializer, authenticator)
      end

      def realm
        acceptor.session_details&.realm
      end

      def send_message(message)
        transmit(message)
      end

      def session_id
        acceptor.session_details&.session_id
      end

      def transmit(data)
        case data
        when Wampproto::Message::Base
          connection.on_message serializer.serialize(data)
        else
          connection.on_message data
        end
      end

      def on_message(data)
        unless acceptor.accepted?
          msg, is_welcome = acceptor.receive(data)
          transmit msg
          router.attach_client(self) if is_welcome
        end
        router.receive_message(self, serializer.deserialize(data))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xconn-0.1.2 lib/wamp/router/client.rb
xconn-0.1.1 lib/wamp/router/client.rb
xconn-0.1.0 lib/wamp/router/client.rb