Skip to content

Commit

Permalink
InMemory client session
Browse files Browse the repository at this point in the history
  • Loading branch information
rubyonrails3 committed May 15, 2024
1 parent cb18138 commit abe078d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
35 changes: 35 additions & 0 deletions lib/wamp/connection/session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Wamp
module Connection
# Client Session
class Session
attr_reader :joiner, :session, :store, :api
attr_accessor :executor, :stream

def initialize(joiner = Wampproto::Joiner.new("realm1"))
@joiner = joiner
@session = Wampproto::Session.new(joiner.serializer)
@api = MessageHandler::Api.new(self)
@store = {}
end

def on_join(&block)
self.executor = block
end

def on_open
stream.on_message joiner.send_hello
end

def on_message(data)
handler = MessageHandler.resolve(data, self)
handler.handle
end

def transmit(data)
stream.on_message data
end
end
end
end
26 changes: 6 additions & 20 deletions lib/wamp/connection/websocket_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ def joined?
module Wamp
module Connection
# Conn
class WebSocketConnection
attr_reader :url, :joiner, :session, :call_requests, :store, :websocket, :api
attr_accessor :executor
class WebSocketConnection < Session
attr_reader :url, :websocket

def initialize(url = "ws://localhost:8080/ws", joiner = Wampproto::Joiner.new("realm1"))
super(joiner)
@url = url
@joiner = joiner
@websocket = Wamp::Connection::WebsocketClient.new(self, protocols)
@session = Wampproto::Session.new(joiner.serializer)
@api = MessageHandler::Api.new(self)
@store = {}
@store = {}
@websocket = Wamp::Connection::WebsocketClient.new(self, protocols)
end

def run
Expand All @@ -32,19 +29,8 @@ def run
websocket.close
end

def on_join(&block)
puts "blocking is saving"
self.executor = block
end

def on_open
data = joiner.send_hello
transmit data
end

def on_message(data)
handler = MessageHandler.resolve(data, self)
handler.handle
transmit joiner.send_hello
end

def transmit(data)
Expand Down
13 changes: 0 additions & 13 deletions lib/wamp/message_handler/yield.rb

This file was deleted.

0 comments on commit abe078d

Please sign in to comment.