socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Property 'of' does not exist on type 'Socket<DefaultEventsMap, DefaultEventsMap>'.

Open ciprianmacovei opened this issue 2 years ago • 6 comments

Describe the bug

i can't find the of property to defined a namespace also cant find socket.to ... to send to specific room >.<

To Reproduce

Socket.IO client version: ^4.7.2

Client

import io from 'socket.io-client';

 const socket = io({
          transports: ['websocket'],
          autoConnect: true,
        })
       
socket.of....


Expected behavior wanted to have autocomplete on all methods like in the docs .

Platform:

  • mac

Additional context it s about typescript or idk I tried to install @types but same result ....

ciprianmacovei avatar Dec 14 '23 13:12 ciprianmacovei

Screenshot 2023-12-14 at 15 16 16 Screenshot 2023-12-14 at 15 16 22

ciprianmacovei avatar Dec 14 '23 13:12 ciprianmacovei

Hi!

socket.to() and io.of() are available on the server side, not the client side.

Reference: https://socket.io/docs/v4/server-api/

darrachequesne avatar Dec 14 '23 18:12 darrachequesne

thank u for answering :) im using python on the server side, okey so yeah from the server side I know how to do it, but from client side how can I pick a namespace and a room ? is there something I'm missing. Because I was looking at https://socket.io/docs/v4/namespaces/ and there was nothing mentioning it s server side. Am I understanding it correctly ? thank u for ur pacience

ciprianmacovei avatar Dec 14 '23 20:12 ciprianmacovei

because on python i have the emit function with kwargs and have room , namespace but in client ... i have only emit with first arg event name and second the data I'm sending :-?

ciprianmacovei avatar Dec 14 '23 20:12 ciprianmacovei

so for u to understand my flow: every time a user logs in he makes a emit on the connected event and then from the server side i join him on the notifications namespace and a specific room, somehome there must me o possibility to send data only to that specific room, and listen to that specific room, something opposite to broadcast, how can i make this ? ps: be is fully functional, I don't know how to do it from client

ciprianmacovei avatar Dec 14 '23 20:12 ciprianmacovei

i think i understand so the be is the source of truth, so when I say send it to room = x on the client when I listen it will send only to the rooms that I joined from the be

ciprianmacovei avatar Dec 15 '23 08:12 ciprianmacovei