@cubetiq/hws
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -9,5 +9,5 @@ "use strict"; | ||
const socket_io_1 = require("socket.io"); | ||
const express_1 = __importDefault(require("express")); | ||
const body_parser_1 = __importDefault(require("body-parser")); | ||
const cors_1 = __importDefault(require("cors")); | ||
const express_1 = __importDefault(require("express")); | ||
const emitter_1 = require("./emitter"); | ||
@@ -66,4 +66,4 @@ const serverio_1 = __importDefault(require("./serverio")); | ||
}); | ||
socket.on("random", (data) => { | ||
console.log(`random data: ${data}`); | ||
socket.on("message", (data) => { | ||
socket.broadcast.emit("message", data); | ||
}); | ||
@@ -77,3 +77,3 @@ }); | ||
}); | ||
// dynamic namespace startsWith (nsp-*) for receive events | ||
// dynamic namespace startsWith (*) for receive events | ||
io.of(/^\/.+$/).on("connection", async (socket) => { | ||
@@ -121,2 +121,8 @@ const nsp = socket.nsp; | ||
}); | ||
app.get("/:event", (req, res) => { | ||
sendEvent(req, res); | ||
}); | ||
app.post("/:event", (req, res) => { | ||
sendEvent(req, res); | ||
}); | ||
app.get("/:namespace/:event", (req, res) => { | ||
@@ -131,10 +137,3 @@ sendEvent(req, res); | ||
const suffixNs = req?.params?.namespace?.trim(); | ||
const namespace = `${suffixNs}`; | ||
if (!suffixNs) { | ||
res.type("json"); | ||
res.send({ | ||
message: "Namespace is required", | ||
status: "ERROR", | ||
}); | ||
} | ||
const namespace = suffixNs; | ||
let body = req?.body; | ||
@@ -147,5 +146,10 @@ if (Object.keys(body).length === 0) { | ||
// Emit event to namespace | ||
(0, emitter_1.IOEmitterOf)(namespace, event, body); | ||
if (namespace) { | ||
(0, emitter_1.IOEmitterOf)(namespace, event, body); | ||
} | ||
else { | ||
(0, emitter_1.IOEmitter)(event, body); | ||
} | ||
const r = { | ||
namespace: namespace, | ||
namespace: namespace || null, | ||
event: event, | ||
@@ -152,0 +156,0 @@ body: body, |
{ | ||
"name": "@cubetiq/hws", | ||
"version": "0.0.2", | ||
"description": "CUBETIQ HTTP WebSocket Server using Socket.IO", | ||
"version": "0.0.3", | ||
"description": "CUBETIQ HTTP WebSocket Server and Client using Socket.IO", | ||
"main": "dist/app.js", | ||
@@ -20,3 +20,4 @@ "bin": { | ||
"socket.io", | ||
"websocket" | ||
"websocket", | ||
"sockcet.io-client" | ||
], | ||
@@ -26,2 +27,3 @@ "author": "Sambo Chea <sombochea@cubetiqs.com>", | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"body-parser": "^1.20.0", | ||
@@ -31,3 +33,4 @@ "commander": "^9.3.0", | ||
"express": "^4.17.1", | ||
"socket.io": "^4.2.0" | ||
"socket.io": "^4.2.0", | ||
"socket.io-client": "^4.5.1" | ||
}, | ||
@@ -34,0 +37,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16337
13
448
7
+ Addedaxios@^0.27.2
+ Addedsocket.io-client@^4.5.1
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@0.27.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedengine.io-client@6.6.2(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedsocket.io-client@4.8.1(transitive)
+ Addedxmlhttprequest-ssl@2.1.2(transitive)