Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Created February 11, 2022 02:15
Show Gist options
  • Select an option

  • Save toshvelaga/dd3656101102c048da44133d8e6af2cd to your computer and use it in GitHub Desktop.

Select an option

Save toshvelaga/dd3656101102c048da44133d8e6af2cd to your computer and use it in GitHub Desktop.
Socket.io implementation in useEffect hook
useEffect(() => {
socket.current =
process.env.NODE_ENV === 'production'
? io(productionWsUrl + streamUrlParams, { transports: ['websocket'] })
: io(developmentWsUrl + streamUrlParams, { transports: ['websocket'] })
socket.current.on('connect', () => {
// either with send()
console.log('WebSocket Open')
})
return () => {
socket.current.on('disconnect', () => {
console.log('close the socket') // undefined
})
}
}, [
facebookUrl,
youtubeUrl,
twitchStreamKey,
customRtmpServer,
customRtmpStreamKey,
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment