Created
February 11, 2022 02:15
-
-
Save toshvelaga/dd3656101102c048da44133d8e6af2cd to your computer and use it in GitHub Desktop.
Socket.io implementation in useEffect hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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