wsrpc-aiohttp icon indicating copy to clipboard operation
wsrpc-aiohttp copied to clipboard

message from the server side?

Open atitoff opened this issue 1 year ago • 5 comments

Can I initiate a message from the server side? I didn't find it in the examples. Only if the request comes from the client side can I send a notification.

atitoff avatar Jun 10 '24 13:06 atitoff

Here it is https://github.com/wsrpc/wsrpc-aiohttp/blob/master/docs/source/examples/server.py#L58-L64

mosquito avatar Jun 10 '24 13:06 mosquito

how can I call "getJoke(self)" from another class instance? in your example they are not called anywhere...

atitoff avatar Jun 10 '24 14:06 atitoff

client calls getJoke, server calls joke on the client, after the client returns the result, that result is a placed to the getJoke left on await.

mosquito avatar Jun 10 '24 14:06 mosquito

The server cannot be the initiator of the message? Got it, I’ll write my own wrapper for the aiohttp websockets

atitoff avatar Jun 10 '24 15:06 atitoff

You have any option for trigger event on the server side.

This library provides contract and implementation of the transport.

  • You may notify all connected clients https://github.com/wsrpc/wsrpc-aiohttp/blob/master/wsrpc_aiohttp/websocket/handler.py#L176-L195
  • You may create a PubSub route
    class Route(PrefixRoute):
      SUBSCRIBERS = set()
    
      def init(self):
          self.SUBSCRIBERS.add(self.socket)
    
    
    
      @classmethod
      async def notify_all(cls, **kwargs):
          await asyncio.gather(*[
              sock.proxy.notify(**kwargs) for sock in cls.SUBSCRIBERS
          ])
    

mosquito avatar Jun 10 '24 15:06 mosquito