mirror of
https://github.com/mistergibson/gxg-web-client.git
synced 2026-08-15 03:26:00 -07:00
federation fixes
This commit is contained in:
parent
ecc5c7257e
commit
2052ad7cef
4 changed files with 113 additions and 16 deletions
|
|
@ -10,6 +10,10 @@ $object_space = {:registry => {}}
|
||||||
class Object
|
class Object
|
||||||
private
|
private
|
||||||
#
|
#
|
||||||
|
def logged_in?()
|
||||||
|
GxG::DISPLAY_DETAILS[:logged_in]
|
||||||
|
end
|
||||||
|
#
|
||||||
def bytes(*args)
|
def bytes(*args)
|
||||||
GxG::ByteArray::try_convert(args)
|
GxG::ByteArray::try_convert(args)
|
||||||
end
|
end
|
||||||
|
|
@ -17,7 +21,7 @@ class Object
|
||||||
def new_message(*args)
|
def new_message(*args)
|
||||||
unless @uuid
|
unless @uuid
|
||||||
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
||||||
::GxG::CHANNELS.create_channel(@uuid)
|
::GxG::CHANNELS.create_channel(@uuid,self)
|
||||||
end
|
end
|
||||||
::GxG::Events::Message.new({:sender => @uuid, :subject => args[1], :body => args[0]})
|
::GxG::Events::Message.new({:sender => @uuid, :subject => args[1], :body => args[0]})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,6 @@ module GxG
|
||||||
end
|
end
|
||||||
# XHR Connector:
|
# XHR Connector:
|
||||||
module Networking
|
module Networking
|
||||||
class Channel
|
|
||||||
#
|
|
||||||
end
|
|
||||||
#
|
#
|
||||||
class Connector
|
class Connector
|
||||||
#
|
#
|
||||||
|
|
@ -973,6 +970,10 @@ module GxG
|
||||||
if the_response.is_a?(::Hash)
|
if the_response.is_a?(::Hash)
|
||||||
if the_response[:status] == "credentialed"
|
if the_response[:status] == "credentialed"
|
||||||
GxG::DISPLAY_DETAILS[:logged_in] = true
|
GxG::DISPLAY_DETAILS[:logged_in] = true
|
||||||
|
GXG_FEDERATION[:connections].keys.each do |the_uuid|
|
||||||
|
socket.send({ :open_channel => the_uuid.to_s }.to_json.encode64, :text)
|
||||||
|
end
|
||||||
|
#
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
the_handler.call(the_response)
|
the_handler.call(the_response)
|
||||||
|
|
@ -999,6 +1000,9 @@ module GxG
|
||||||
if response.is_a?(::Hash)
|
if response.is_a?(::Hash)
|
||||||
# FIXME: possible conflict with proper credential setting.
|
# FIXME: possible conflict with proper credential setting.
|
||||||
if response[:status] == "uncredentialed"
|
if response[:status] == "uncredentialed"
|
||||||
|
GXG_FEDERATION[:connections].keys.each do |the_uuid|
|
||||||
|
socket.send({ :close_channel => the_uuid.to_s }.to_json.encode64, :text)
|
||||||
|
end
|
||||||
GxG::DISPLAY_DETAILS[:logged_in] = false
|
GxG::DISPLAY_DETAILS[:logged_in] = false
|
||||||
if the_handler.respond_to?(:call)
|
if the_handler.respond_to?(:call)
|
||||||
the_handler.call(response)
|
the_handler.call(response)
|
||||||
|
|
@ -1087,7 +1091,6 @@ module GxG
|
||||||
@csrf = nil
|
@csrf = nil
|
||||||
@the_connector = self
|
@the_connector = self
|
||||||
# Make introduction to host and aquire csrf token
|
# Make introduction to host and aquire csrf token
|
||||||
::GxG::CHANNELS.create_channel(@uuid)
|
|
||||||
the_introduction = new_message({:introduction => @uuid.to_s})
|
the_introduction = new_message({:introduction => @uuid.to_s})
|
||||||
the_introduction[:sender] = @uuid.to_s
|
the_introduction[:sender] = @uuid.to_s
|
||||||
the_introduction[:to] = @host_prefix.to_s
|
the_introduction[:to] = @host_prefix.to_s
|
||||||
|
|
@ -1150,6 +1153,10 @@ module GxG
|
||||||
the_message[:sender] = @uuid
|
the_message[:sender] = @uuid
|
||||||
the_message[:to] = @remote_uuid
|
the_message[:to] = @remote_uuid
|
||||||
# Review : add fail/succeed code blocks??
|
# Review : add fail/succeed code blocks??
|
||||||
|
# if succeed do this: ::GxG::CHANNELS.create_channel(@uuid)
|
||||||
|
the_message.on(:success) do |response|
|
||||||
|
::GxG::CHANNELS.create_channel(@uuid)
|
||||||
|
end
|
||||||
GxG::CONNECTION.push(the_message)
|
GxG::CONNECTION.push(the_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,77 @@ module GxG
|
||||||
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :available => {}, :connections => {}}
|
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :available => {}, :connections => {}}
|
||||||
# ::GxG::SOCKET_MONITOR
|
# ::GxG::SOCKET_MONITOR
|
||||||
module Messages
|
module Messages
|
||||||
|
class Channel
|
||||||
|
#
|
||||||
|
def initialize(the_uuid=nil, the_object=nil)
|
||||||
|
@uuid = the_uuid
|
||||||
|
@inbox = []
|
||||||
|
@outbox = []
|
||||||
|
@socket = nil
|
||||||
|
@remote = nil
|
||||||
|
@channel_secret = nil
|
||||||
|
@object = the_object
|
||||||
|
self
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def uuid()
|
||||||
|
@uuid
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def object()
|
||||||
|
@object
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def socket()
|
||||||
|
@socket
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def socket=(the_socket=nil)
|
||||||
|
@socket = the_socket
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def remote()
|
||||||
|
@remote
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def remote=(the_remote=nil)
|
||||||
|
@remote = the_remote
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def secret()
|
||||||
|
@channel_secret
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def secret=(the_secret=nil)
|
||||||
|
@channel_secret = the_secret
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def inbox_size()
|
||||||
|
@inbox.size
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def next_message()
|
||||||
|
@inbox.unshift
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def outbox_size()
|
||||||
|
@outbox.size
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def send_message(the_message)
|
||||||
|
@outbox << the_message
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def read()
|
||||||
|
@outbox.unshift
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def write(the_message)
|
||||||
|
@inbox << the_message
|
||||||
|
end
|
||||||
|
#
|
||||||
|
end
|
||||||
|
#
|
||||||
class ChannelManager
|
class ChannelManager
|
||||||
#
|
#
|
||||||
def update_channels
|
def update_channels
|
||||||
|
|
@ -33,11 +104,17 @@ module GxG
|
||||||
channel = self.fetch_channel(destination.to_s.to_sym)
|
channel = self.fetch_channel(destination.to_s.to_sym)
|
||||||
if channel
|
if channel
|
||||||
channel.write(the_message)
|
channel.write(the_message)
|
||||||
|
result = true
|
||||||
else
|
else
|
||||||
# Send format: channel.socket.send({ :payload => the_message.export.to_s.encrypt(channel.secret).encode64 }.to_json.encode64, :text)
|
# Send format: channel.socket.send({ :payload => the_message.export.to_s.encrypt(channel.secret).encode64 }.to_json.encode64, :text)
|
||||||
|
if GxG::DISPLAY_DETAILS[:logged_in]
|
||||||
socket.send({ :payload => the_message.export.to_s.encrypt(connector.secret).encode64 }.to_json.encode64, :text)
|
socket.send({ :payload => the_message.export.to_s.encrypt(connector.secret).encode64 }.to_json.encode64, :text)
|
||||||
end
|
|
||||||
result = true
|
result = true
|
||||||
|
else
|
||||||
|
log_warn("Message dropped --> login and resend")
|
||||||
|
result = false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# email address -- TODO
|
# email address -- TODO
|
||||||
end
|
end
|
||||||
|
|
@ -48,19 +125,26 @@ module GxG
|
||||||
GXG_FEDERATION[:connections][(the_uuid)]
|
GXG_FEDERATION[:connections][(the_uuid)]
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def create_channel(the_uuid)
|
def create_channel(the_uuid=nil,the_object=nil)
|
||||||
GXG_FEDERATION[:connections][(the_uuid)] = ::GxG::Messages::Channel.new(the_uuid)
|
GXG_FEDERATION[:connections][(the_uuid)] = ::GxG::Messages::Channel.new(the_uuid,the_object)
|
||||||
|
if GxG::DISPLAY_DETAILS[:logged_in]
|
||||||
|
socket.send({ :open_channel => the_uuid }.to_json.encode64, :text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def destroy_channel(the_uuid)
|
def destroy_channel(the_uuid)
|
||||||
channel = self.fetch_channel(the_uuid)
|
channel = self.fetch_channel(the_uuid)
|
||||||
if channel
|
if channel
|
||||||
|
|
||||||
channel.outbox_size.times do |indexer|
|
channel.outbox_size.times do |indexer|
|
||||||
the_message = channel.read()
|
the_message = channel.read()
|
||||||
if the_message
|
if the_message
|
||||||
self.dispatch_message(the_message)
|
self.dispatch_message(the_message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if GxG::DISPLAY_DETAILS[:logged_in]
|
||||||
|
socket.send({ :close_channel => the_uuid }.to_json.encode64, :text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
GXG_FEDERATION[:connections].delete(the_uuid)
|
GXG_FEDERATION[:connections].delete(the_uuid)
|
||||||
end
|
end
|
||||||
|
|
@ -694,7 +778,7 @@ class Object
|
||||||
def send_message(the_message)
|
def send_message(the_message)
|
||||||
unless @uuid
|
unless @uuid
|
||||||
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
||||||
::GxG::CHANNELS.create_channel(@uuid)
|
::GxG::CHANNELS.create_channel(@uuid,self)
|
||||||
end
|
end
|
||||||
::GxG::CHANNELS.send_message(@uuid, the_message)
|
::GxG::CHANNELS.send_message(@uuid, the_message)
|
||||||
true
|
true
|
||||||
|
|
@ -703,7 +787,7 @@ class Object
|
||||||
def next_message()
|
def next_message()
|
||||||
unless @uuid
|
unless @uuid
|
||||||
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
||||||
::GxG::CHANNELS.create_channel(@uuid)
|
::GxG::CHANNELS.create_channel(@uuid,self)
|
||||||
end
|
end
|
||||||
::GxG::CHANNELS.next_message(@uuid)
|
::GxG::CHANNELS.next_message(@uuid)
|
||||||
end
|
end
|
||||||
|
|
@ -711,7 +795,7 @@ class Object
|
||||||
def post(the_message)
|
def post(the_message)
|
||||||
unless @uuid
|
unless @uuid
|
||||||
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
@uuid = ::GxG::uuid_generate.to_s.to_sym
|
||||||
::GxG::CHANNELS.create_channel(@uuid)
|
::GxG::CHANNELS.create_channel(@uuid,self)
|
||||||
end
|
end
|
||||||
channel = ::GxG::CHANNELS.fetch_channel(@uuid)
|
channel = ::GxG::CHANNELS.fetch_channel(@uuid)
|
||||||
if channel
|
if channel
|
||||||
|
|
@ -719,3 +803,8 @@ class Object
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
#
|
||||||
|
def process_message(the_message=nil, options = {})
|
||||||
|
# override to use
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
#
|
#
|
||||||
module GxG
|
module GxG
|
||||||
module Networking
|
module Networking
|
||||||
class Channel
|
|
||||||
#
|
|
||||||
end
|
|
||||||
#
|
#
|
||||||
class Connector
|
class Connector
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue