diff --git a/package.json b/package.json index bff4af7..2f542b0 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "pigpio": "^3.3.1", "rpio": "^2.4.2", "socket.io": "^4.7.5", + "socket.io-client": "^4.7.5", "telegraf": "^4.16.3", "winston": "^3.12.0" } diff --git a/src/manager.js b/src/manager.js index 8dbb91d..254e3d4 100644 --- a/src/manager.js +++ b/src/manager.js @@ -54,7 +54,7 @@ const buttonShutDown = new Gpio(pinShutDown, { // SHARE const server = http.createServer(); const io = new Server(server); -io.on("connection", () => {}); +server.listen(3000, () => {}); const share = async () => { pwmShare.hardwarePwmWrite(frequency, 20000); diff --git a/tests/socket.js b/tests/socket.js new file mode 100644 index 0000000..9843507 --- /dev/null +++ b/tests/socket.js @@ -0,0 +1,19 @@ +const http = require("http"); +const { Server } = require("socket.io"); +const server = http.createServer(); +const io = new Server(server); + +const ioc = require("socket.io-client"); + +server.listen(3000, () => {}); +setTimeout(() => io.emit("test", 12), 2000); + +const socket = ioc("http://localhost:3000"); + +socket.on("connect", () => { + console.log("connected!"); +}); + +socket.on("test", (msg) => { + console.log("Received:", msg); +}); diff --git a/yarn.lock b/yarn.lock index c45911d..e6aec6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -440,6 +440,17 @@ enabled@2.0.x: resolved "https://registry.yarnpkg.com/enabled/-/enabled-2.0.0.tgz#f9dd92ec2d6f4bbc0d5d1e64e21d61cd4665e7c2" integrity sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ== +engine.io-client@~6.5.2: + version "6.5.4" + resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-6.5.4.tgz#b8bc71ed3f25d0d51d587729262486b4b33bd0d0" + integrity sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ== + dependencies: + "@socket.io/component-emitter" "~3.1.0" + debug "~4.3.1" + engine.io-parser "~5.2.1" + ws "~8.17.1" + xmlhttprequest-ssl "~2.0.0" + engine.io-parser@~5.2.1: version "5.2.3" resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-5.2.3.tgz#00dc5b97b1f233a23c9398d0209504cf5f94d92f" @@ -1408,6 +1419,16 @@ socket.io-adapter@~2.5.2: debug "~4.3.4" ws "~8.17.1" +socket.io-client@^4.7.5: + version "4.7.5" + resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-4.7.5.tgz#919be76916989758bdc20eec63f7ee0ae45c05b7" + integrity sha512-sJ/tqHOCe7Z50JCBCXrsY3I2k03iOiUe+tj1OmKeD2lXPiGH/RUCdTZFoqVyN7l1MnpIzPrGtLcijffmeouNlQ== + dependencies: + "@socket.io/component-emitter" "~3.1.0" + debug "~4.3.2" + engine.io-client "~6.5.2" + socket.io-parser "~4.2.4" + socket.io-parser@~4.2.4: version "4.2.4" resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.2.4.tgz#c806966cf7270601e47469ddeec30fbdfda44c83" @@ -1697,3 +1718,8 @@ ws@~8.17.1: version "8.17.1" resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b" integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ== + +xmlhttprequest-ssl@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67" + integrity sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==