diff --git a/metaverse/viewer/capability.py b/metaverse/viewer/capability.py index 18dae1d..1b55883 100644 --- a/metaverse/viewer/capability.py +++ b/metaverse/viewer/capability.py @@ -28,6 +28,87 @@ class BaseCapability: # Please keep these in alphabetical order! :) +@Capabilities.register("ChatSessionRequest") +class ChatSessionRequest(BaseCapability): + async def acceptInvitation(self, sessionId): + async with httpclient.HttpClient() as session: + async with await session.post(self.url, + data = llsd.llsdEncode({ + "method": "accept invitation", + "session-id": sessionId + }), + headers = { + "Content-Type": "application/llsd+xml" + } + ) as response: + if response.status == 200: + return True + + return False + + async def fetchHistory(self, sessionId): + """ + This returns a array in this format: + [{"from": ..., "from_id": ..., "message": ..., "num": ..., "time": ...}, ...] + """ + async with httpclient.HttpClient() as session: + async with await session.post(self.url, + data = llsd.llsdEncode({ + "method": "fetch history", + "session-id": sessionId + }), + headers = { + "Content-Type": "application/llsd+xml" + } + ) as response: + if response.status != 200: + return [] + + data = await response.read() + result = llsd.llsdDecode(data, format="xml") + return result + + async def startP2PVoice(self, sessionId, otherParticipantId): + async with httpclient.HttpClient() as session: + async with await session.post(self.url, + data = llsd.llsdEncode({ + "method": "start p2p voice", + "session-id": sessionId, + "params": otherParticipantId, + "alt-params": { + "voice_server_type": "webrtc" + } + }), + headers = { + "Content-Type": "application/llsd+xml" + } + ) as response: + if response.status == 200: + return True + + return False + + async def startConference(self, sessionId, agents): + async with httpclient.HttpClient() as session: + async with await session.post(self.url, + data = llsd.llsdEncode({ + "method": "start conference", + "session-id": sessionId, + "params": agents, + "alt-params": { + "voice_server_type": "webrtc" + } + }), + headers = { + "Content-Type": "application/llsd+xml" + } + ) as response: + if response.status == 200: + return True + + return False + + @Capabilities.register("EventQueueGet") class EventQueueGet(BaseCapability): async def poll(self, ack, done = False): @@ -69,4 +150,4 @@ class Seed(BaseCapability): if name in caps: result[name] = caps.get(name, url) - return result + return result \ No newline at end of file