Skip to content

Commit

Permalink
Merge pull request #1504 from bcgov/fix/EDX-1565
Browse files Browse the repository at this point in the history
EDX-1565 - Adds logging for debugging websocket connections
  • Loading branch information
arcshiftsolutions authored Jul 14, 2023
2 parents fc6ab20 + 001dd36 commit df05ea5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/messaging/handlers/edx-event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function broadCastMessageToWebSocketClients(msg) {
if (connectedClients && connectedClients.length > 0) {
for (const connectedClient of connectedClients) {
try {
log.debug(`Sending message to connected client ${connectedClient}`);
connectedClient.send(msg);
} catch (e) {
log.error(`Error while sending message to connected client ${connectedClient} :: ${e}`);
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/services/web-socket-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ webSocketsService.install = function (Vue, options) {
Vue.config.globalProperties.$webSocketsConnect = () => {
const token =localStorage.getItem('jwtToken');
if(!token){
console.log('No jwt, not connecting');
return;
}
if(ws && ws.readyState === WebSocket.OPEN){
console.log('Already has websocket connection');
return;
}
ws = new WebSocket(options.url);

ws.onopen = () => {
console.log('connection opened');
// Restart reconnect interval
reconnectInterval = options.reconnectInterval || 1000;
};
Expand All @@ -27,6 +30,7 @@ webSocketsService.install = function (Vue, options) {
};

ws.onclose = (event) => {
console.log('connection closed');
if (event) {
// Event.code 1000 is our normal close event
if (event.code !== 1000) {
Expand Down Expand Up @@ -61,6 +65,7 @@ webSocketsService.install = function (Vue, options) {
Here we write our custom functions to not make a mess in one function
*/
function handleNotification (params) {
console.log('Received websocket event');
const noteStore = notificationsStore();
noteStore.setNotification(params.data);
}
Expand Down

0 comments on commit df05ea5

Please sign in to comment.