From 2f6cf12ddd10a2b6b80d764c0595999422d8dfe0 Mon Sep 17 00:00:00 2001 From: "G. Gibson" Date: Sat, 30 Aug 2025 17:35:52 -0700 Subject: [PATCH] misc. fixes -- messaging --- gxg/web/gxg_comm.rb | 15 +++++++++++++++ gxg/web/gxg_events.rb | 7 +++++-- update_web.sh | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gxg/web/gxg_comm.rb b/gxg/web/gxg_comm.rb index 08d0034..d4b3690 100644 --- a/gxg/web/gxg_comm.rb +++ b/gxg/web/gxg_comm.rb @@ -1152,6 +1152,21 @@ module GxG GxG::CONNECTION.push(the_message) end end + # Normally encrypts socket traffic + # Send format: channel.socket.send({ :payload => the_message.export.to_s.encrypt(channel.secret).encode64 }.to_json.encode64, :text) + ::GxG::SOCKET_MONITOR.on(:payload) do |the_data| + the_message = ::GxG::Events::Message::import(the_data.to_s.decode64.decrypt(@csrf)) + if the_message.is_a?(::GxG::Events::Message) + the_channel = ::GxG::CHANNELS.fetch_channel(the_message[:to]) + unless the_channel + ::GxG::CHANNELS.create_channel(the_message[:to]) + the_channel = ::GxG::CHANNELS.fetch_channel(the_message[:to]) + end + if the_channel + the_channel.write(the_message) + end + end + end ::GxG::DISPATCHER.add_periodic_timer({:interval => 0.333}) do ::GxG::SOCKET_MONITOR.follow_up end diff --git a/gxg/web/gxg_events.rb b/gxg/web/gxg_events.rb index 4f3d504..8cc0c0b 100644 --- a/gxg/web/gxg_events.rb +++ b/gxg/web/gxg_events.rb @@ -33,8 +33,11 @@ module GxG channel = self.fetch_channel(destination.to_s.to_sym) if channel channel.write(the_message) - result = true + else + # Send format: channel.socket.send({ :payload => the_message.export.to_s.encrypt(channel.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 end # email address -- TODO end @@ -100,7 +103,7 @@ module GxG unless args[0].is_a?(::Hash) raise ArgumentError, "you must pass a Hash to create the message" end - @data = {:sender => nil, :id => (::GxG.uuid_generate().to_s.to_sym), :subject => args[1], :body => nil, :on_success => nil, :on_fail => nil}.merge(args[0]) + @data = {:sender => nil. :id => GxG::uuid_generate().to_s.to_sym, :subject => args[1], :body => nil, :on_success => nil, :on_fail => nil}.merge(args[0]) unless @data[:sender] raise ArgumentError, "you must set the :sender key in the argument Hash" end diff --git a/update_web.sh b/update_web.sh index 0b3b905..c543dec 100755 --- a/update_web.sh +++ b/update_web.sh @@ -1,5 +1,6 @@ #!/bin/bash source /etc/profile rm ./gxg.js +#opal -I ./gxg -I ./gxg/deps -I ./gxg/standard --compile gxg_web.rb > gxg.js opal -I ./gxg -I ./gxg/deps -I ./gxg/standard --compile gxg_web.rb > gxg.js # minify ./gxg.js > ../src/main/gxg.js