How to send socktio events to an Odoo class method

37 views Asked by At

I have an implementation of a Socket.io client that connects to a WebSocket server and receives events sent by it. Now, I'm trying to capture these events and send them to the handleEvent() method in another class named linhafala.asterisk in Odoo. I tried using self.env['linhafala.asterisk'].handleEvent(data), but I haven't been successful. Does anyone have an alternative idea that could assist me?

import socketio

sio = socketio.Client()

@sio.on('connect')
def on_connect():
    print('Conectado ao servidor websocket na porta 3001')

@sio.on('disconnect')
def on_disconnect():
    print('Desconectado do websocket!')

@sio.on('message')
def on_event(data):
    print(f'Eventos do servidor: {data}')
    self.env['linhafala.asterisk'].handleEvent(data)



if __name__ == "__main__":
    server_url = "http://localhost:3001" 
    sio.connect(server_url)

    sio.wait() 

0

There are 0 answers