-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/WG-236: Websocket notifications (#228)
* task/WG-236: Websocket notifications * adding nginx conf file * adding toast * refactoring Create Map button to be inside ProjectListings. Adding trigger buttons for notification examples * updating unit test for main menu * Adding auth and socket event for new notification * removing create map button changes. These changes are in WG-276 instead * Add To-do for wss in socketUtils --------- Co-authored-by: Taylor Grafft <[email protected]> Co-authored-by: Taylor Grafft <[email protected]> Co-authored-by: Taylor Grafft <[email protected]> Co-authored-by: Taylor Grafft <[email protected]>
- Loading branch information
1 parent
3d5ea2b
commit 6d80b87
Showing
6 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import io from 'socket.io-client'; | ||
import { toast } from 'react-toastify'; | ||
import { getTokenFromLocalStorage } from './authUtils'; | ||
|
||
const { token } = getTokenFromLocalStorage(); | ||
|
||
// TODO: REACT Point to active backend (where nginx is running) use wss:// for secure connection | ||
export const socket = io('http://localhost:8888', { | ||
auth: { | ||
token, | ||
}, | ||
}); | ||
|
||
export const setupSocketListeners = (updateConnectionStatus) => { | ||
socket.on('connect', () => { | ||
updateConnectionStatus('Connected'); | ||
console.log('Connected'); | ||
}); | ||
|
||
socket.on('disconnect', () => { | ||
updateConnectionStatus('Disconnected'); | ||
console.log('Disconnected'); | ||
}); | ||
|
||
socket.on('connect_error', (error) => { | ||
console.error('Connection Error:', error); | ||
}); | ||
|
||
socket.on('notification', (data) => { | ||
console.log('Notification received:', data.message); | ||
toast.info(data.message); | ||
}); | ||
|
||
socket.on('new_notification', (data) => { | ||
console.log('New Notification received:', data.message); | ||
toast.info(data.message); | ||
}); | ||
|
||
socket.on('asset_success', (data) => { | ||
console.log('Notification received:', data.message); | ||
toast.success(data.message); | ||
}); | ||
|
||
socket.on('asset_failure', (data) => { | ||
console.log('Notification received:', data.message); | ||
toast.error(data.message); | ||
}); | ||
}; | ||
|
||
// Clean up function to remove all listeners | ||
export const removeSocketListeners = () => { | ||
socket.off('connect'); | ||
socket.off('disconnect'); | ||
socket.off('connect_error'); | ||
socket.off('notification'); | ||
socket.off('new_notification'); | ||
socket.off('asset_success'); | ||
socket.off('asset_failure'); | ||
}; |