From 81a153da87f56e4db0a38ebb94a9c72471e0b002 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 14 Jun 2024 15:39:35 +0300 Subject: Add nearby chat listener --- indra/newview/scripts/lua/LLChatListener.lua | 41 +++++++++++++++++++++++ indra/newview/scripts/lua/test_LLChatListener.lua | 27 +++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 indra/newview/scripts/lua/LLChatListener.lua create mode 100644 indra/newview/scripts/lua/test_LLChatListener.lua (limited to 'indra/newview/scripts/lua') diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua new file mode 100644 index 0000000000..d615ae5dbc --- /dev/null +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -0,0 +1,41 @@ +local fiber = require 'fiber' +local inspect = require 'inspect' + +local LLChatListener = {} +local waitfor = {} + +function LLChatListener:new() + local obj = setmetatable({}, self) + self.__index = self + obj.name = 'Chat_listener' + + return obj +end + +function LLChatListener:handleMessages(event_data) + --print(inspect(event_data)) + return true +end + +function LLChatListener:start() + waitfor = leap.WaitFor:new(-1, self.name) + function waitfor:filter(pump, data) + return data + end + + fiber.launch(self.name, function() + event = waitfor:wait() + while event and self:handleMessages(event) do + event = waitfor:wait() + end + end) + + leap.send('LLChatBar', {op='listen'}) +end + +function LLChatListener:stop() + leap.send('LLChatBar', {op='stopListening'}) + waitfor:close() +end + +return LLChatListener diff --git a/indra/newview/scripts/lua/test_LLChatListener.lua b/indra/newview/scripts/lua/test_LLChatListener.lua new file mode 100644 index 0000000000..2c7b1dc3e5 --- /dev/null +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -0,0 +1,27 @@ +local LLChatListener = require 'LLChatListener' +local LLChat = require 'LLChat' + +function openOrEcho(message) + local floater_name = string.match(message, "^open%s+(%w+)") + if floater_name then + leap.send("LLFloaterReg", {name = floater_name, op = "showInstance"}) + else + LLChat.sendNearby('Echo: ' .. message) + end +end + +local listener = LLChatListener:new() + +function listener:handleMessages(event_data) + if string.find(event_data.message, '[LUA]') then + return true + elseif event_data.message == 'stop' then + LLChat.sendNearby('Closing echo script.') + return false + else + openOrEcho(event_data.message) + end + return LLChatListener.handleMessages(self, event_data) +end + +listener:start() -- cgit v1.2.3 From 09b814a2dc6d3a647d75bcf0a310eba2678a0228 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Thu, 20 Jun 2024 00:42:25 +0300 Subject: Use LLLeapListener to listen to LLNearbyChat pump --- indra/newview/scripts/lua/LLChatListener.lua | 12 ++++++++---- indra/newview/scripts/lua/test_LLChatListener.lua | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'indra/newview/scripts/lua') diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua index d615ae5dbc..b4e90d272c 100644 --- a/indra/newview/scripts/lua/LLChatListener.lua +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -1,8 +1,10 @@ local fiber = require 'fiber' local inspect = require 'inspect' +local leap = require 'leap' local LLChatListener = {} local waitfor = {} +local listener_name = {} function LLChatListener:new() local obj = setmetatable({}, self) @@ -13,14 +15,16 @@ function LLChatListener:new() end function LLChatListener:handleMessages(event_data) - --print(inspect(event_data)) + print(inspect(event_data)) return true end function LLChatListener:start() waitfor = leap.WaitFor:new(-1, self.name) function waitfor:filter(pump, data) - return data + if pump == "LLNearbyChat" then + return data + end end fiber.launch(self.name, function() @@ -30,11 +34,11 @@ function LLChatListener:start() end end) - leap.send('LLChatBar', {op='listen'}) + listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener end function LLChatListener:stop() - leap.send('LLChatBar', {op='stopListening'}) + leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name}) waitfor:close() end diff --git a/indra/newview/scripts/lua/test_LLChatListener.lua b/indra/newview/scripts/lua/test_LLChatListener.lua index 2c7b1dc3e5..b9696e7cfc 100644 --- a/indra/newview/scripts/lua/test_LLChatListener.lua +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -1,5 +1,6 @@ local LLChatListener = require 'LLChatListener' local LLChat = require 'LLChat' +local leap = require 'leap' function openOrEcho(message) local floater_name = string.match(message, "^open%s+(%w+)") @@ -21,7 +22,7 @@ function listener:handleMessages(event_data) else openOrEcho(event_data.message) end - return LLChatListener.handleMessages(self, event_data) + return true end listener:start() -- cgit v1.2.3