diff options
author | nat-goodspeed <nat@lindenlab.com> | 2024-06-21 10:00:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-21 10:00:52 -0400 |
commit | b16209f86a376cadfcc9f43604618de7fdc789e7 (patch) | |
tree | 530b30d1dde4ea274566489d42cfd07b2f882167 /indra/newview/scripts | |
parent | d7d18aaad0e7b8412e50fd82d446d31611207175 (diff) | |
parent | 22ec77c03d01a973c871ae59fd95a8397bf07fb8 (diff) |
Merge pull request #1767 from secondlife/lua-chat-listener
Add nearby chat listener
Diffstat (limited to 'indra/newview/scripts')
-rw-r--r-- | indra/newview/scripts/lua/LLChatListener.lua | 45 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_LLChatListener.lua | 28 |
2 files changed, 73 insertions, 0 deletions
diff --git a/indra/newview/scripts/lua/LLChatListener.lua b/indra/newview/scripts/lua/LLChatListener.lua new file mode 100644 index 0000000000..b4e90d272c --- /dev/null +++ b/indra/newview/scripts/lua/LLChatListener.lua @@ -0,0 +1,45 @@ +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) + 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) + if pump == "LLNearbyChat" then + return data + end + end + + fiber.launch(self.name, function() + event = waitfor:wait() + while event and self:handleMessages(event) do + event = waitfor:wait() + end + end) + + listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener +end + +function LLChatListener:stop() + leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name}) + 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..b9696e7cfc --- /dev/null +++ b/indra/newview/scripts/lua/test_LLChatListener.lua @@ -0,0 +1,28 @@ +local LLChatListener = require 'LLChatListener' +local LLChat = require 'LLChat' +local leap = require 'leap' + +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 true +end + +listener:start() |