I use in react
This is my socket instance
import { io } from 'socket.io-client'
const URL = 'wss://irc-ws.chat.twitch.tv:443'
const socket = io(URL, {
transports: ['websocket'],
autoConnect: false,
})
export default socket
This is my react code
useEffect(() => {
const onConnect = () => {
console.log('WebSocket Client Connected')
socket.send(
'CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands'
)
socket.send(`PASS oauth:token`)
socket.send(`NICK username`)
}
const onConnectError = (error: any) => {
console.log(error)
}
const onMessage = () => {
console.log('message')
}
socket.on('connect', onConnect)
socket.on('connect_error', onConnectError)
socket.on('message', onMessage)
socket.connect()
return () => {
socket.off('connect', onConnect)
socket.off('connect_error', onConnectError)
socket.off('message', onMessage)
socket.disconnect()
}
}, [status])
Failed to print WebSocket Client Connected message, only Error: timeout message
What should I do?