[Python] Websockets - trying to convert Phython Code to Node

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to copy the features of this library https://github.com/rnbguy/pysphere/blob/master/misphere.py which connects via websockets to the Mi Sphere 360 camera.

    The important code is here

    ms_ip = '192.168.42.1'
    ms_tcp_port = 7878
    ms_uk_port = 8787
    ms_fs_port = 50422

    def init(self):
    self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    self.socket.connect((self.ms_ip, self.ms_tcp_port))
    self.socket_1 = socket.socket()
    self.recv_handle_live = True
    self.recv_thread = threading.Thread(target=self.recv_handler)
    self.recv_thread.daemon = True
    self.session = Session()
    self.session.conf = {}
    self.session.locks = {}
    self.last_send = 0


    I'm trying to do this with the ws library in Node

    const ip = '192.168.42.1'
    const port = '7878'
    const url = `ws://${ip}:${port}`
    const websocket = new WebSocket(url)


    However I'm not getting a connection to the camera. (It's connected via Wifi, but the websocket never sends a connection message)

    I'm wondering if it's to do with the protocols, which are listed in the Phython code.

    I see in the websocket documentation you can define protocols in the connection, but I can't find any documentation about what those protocols are and how you add them.

    i.e.

    self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)


    Anyone know how I add something like this in the Node websocket connection?

    Continue reading...

Compartilhe esta Página