Skip to content

Commit

Permalink
added eventName property
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikroongta8 committed Mar 31, 2024
1 parent 7d21946 commit 6dc8703
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions controllers/khokhaEntryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.addNewEntry = async (req, res, next) => {
if(ws.isConnected(req.body.connectionId)===false){
return res.json({
success: false,
eventName: "ERROR",
message: "Socket is not connected"
});
}
Expand All @@ -26,6 +27,7 @@ exports.addNewEntry = async (req, res, next) => {

ws.sendMessageToSocket(req.body.connectionId, {
success: true,
eventName: "ENTRY_ADDED",
message: "Entry Added to database!",
data: entry
});
Expand All @@ -46,6 +48,7 @@ exports.closeEntry = async (req, res, next) => {
if(ws.isConnected(req.body.connectionId)===false){
return res.json({
success: false,
eventName: "ERROR",
message: "Socket is not connected"
});
}
Expand All @@ -55,6 +58,7 @@ exports.closeEntry = async (req, res, next) => {
if (!entry) {
ws.sendMessageToSocket(req.body.connectionId, {
success: false,
eventName: "ERROR",
message: "Entry not found!"
});
ws.closeConnection(req.body.connectionId);
Expand All @@ -67,6 +71,7 @@ exports.closeEntry = async (req, res, next) => {
if(entry.isClosed){
ws.sendMessageToSocket(req.body.connectionId, {
success: false,
eventName: "ERROR",
message: "Entry Already Closed!",
});
ws.closeConnection(req.body.connectionId);
Expand All @@ -84,6 +89,7 @@ exports.closeEntry = async (req, res, next) => {

ws.sendMessageToSocket(req.body.connectionId, {
success: true,
eventName: "ENTRY_CLOSED",
message: "Entry Closed Successfully!",
data: newEntry
});
Expand Down
4 changes: 4 additions & 0 deletions handlers/websocketHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports.connectionHandler = async(socket, req) => {
socket.send(JSON.stringify({connectionId: socket.connectionId}));
setTimeout(() => {
socket.send(JSON.stringify({
eventName: "TIMEOUT",
message: 'Timeout'
}));
socket.close();
Expand All @@ -23,13 +24,15 @@ exports.connectionHandler = async(socket, req) => {
if(err.response !== undefined){
socket.send(JSON.stringify({
success: false,
eventName: "ERROR",
statusCode: err.response.status,
error: err.response.data.error,
message: err.response.data.message
}));
}else{
socket.send(JSON.stringify({
success: false,
eventName: "ERROR",
statusCode: 500,
error: 'Internal Server Error',
message: err.message
Expand All @@ -38,6 +41,7 @@ exports.connectionHandler = async(socket, req) => {
}else{
socket.send(JSON.stringify({
success: false,
eventName: "ERROR",
statusCode: err.statusCode,
error: err.name,
message: err.message
Expand Down
2 changes: 0 additions & 2 deletions helpers/onestopUserHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const { onestopUserEndpoint } = require("../shared/constants");
exports.getOnestopUser = async(authHeader, onestopSecurityKey) => {
const res = await axios.get(onestopUserEndpoint, {
headers: {
// "authorization": "Bearer ",
"authorization": authHeader,
// "security-key": "OneStop-Test"
"security-key": onestopSecurityKey,
},
});
Expand Down
Empty file removed helpers/websocketsHelper.js
Empty file.

0 comments on commit 6dc8703

Please sign in to comment.