henningm / express-ws Goto Github PK
View Code? Open in Web Editor NEWWebSocket endpoints for express applications
License: BSD 2-Clause "Simplified" License
WebSocket endpoints for express applications
License: BSD 2-Clause "Simplified" License
I've tried variations on the demo code, even used the exact examples listed in my app.js
, but it just doesn't seem to be creating the socket.
to try to keep everything organized I originally broke it out as seen here: https://github.com/aarobc/nodechan/blob/master/src/routes/socket.js
my app.js can be found here: https://github.com/aarobc/nodechan/blob/master/src/app.js#L35
right now I'm just trying to use the basic demo echo code, nothing fancy. Any guidance is appreciated.
I was attempting to use express-ws using my existing middlewares that authenticate and authorize users. The authorization middleware in particular wants to short-circuit the request and return 401 or 403 when appropriate. But this doesn't play nicely with express-ws:
app.ws('/mnt', authMiddleware, function(...) {
})
express provide default error handler and also user add user-defined error handler
such as below form.
function errorHandler(err, req, res, next) {
}
but, if error is occurred during processing web socket req/res
this error can not handled by express error handler
so, i wondering that how to handle error for websocket?
Hi,
I get this error, because app.mountpath is undefined in addSocketRoute.
url.js:107
throw new TypeError("Parameter 'url' must be a string, not " + typeof url)
^
TypeError: Parameter 'url' must be a string, not undefined
at Url.parse (url.js:107:11)
at urlParse (url.js:101:5)
at Object.urlResolve as resolve
at Function.addSocketRoute as ws
at Object. (/Users/d056831/Development/HomeAutomation.js/routes.js:39:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
function addSocketRoute(route, middleware, callback) {
var args = [].splice.call(arguments, 0);
var wsPath = url.resolve(app.mountpath, route);
In index.js
, it mentions:
/* By setting this fake
.url
on the request, we ensure that it will end up in the fake
*.get
handler that we defined above - where the wrapper will then unpack the.ws
* property, indicate that the WebSocket has been handled, and call the actual handler. */
What is this fake .get
handler?
So, if I need to maintain per-client state, should I just... add things to the websocket? Like:
app.ws("/endpoint", function (ws, req) {
ws.on("message", function (message) {
ws.messageCounter = (ws.messageCounter ? ws.messageCounter : 0) + 1;
console.log("%d messages received on this connection", ws.messageCounter);
});
});
Or is there some "real" way to do this that I am missing?
Looking at the documentation I don't see anything but socket.on('message', cb)
, which gives you {event: 'myEvent', data: {...data}}
, but it doesn't seem like I can do socket.on('myEvent', cb)
. Am I missing a function I should know about on the socket object, or is the second pattern there not supported?
Hi HenningM,
Thanks for this elegant library.
express-ws should support a feature to enable authorization of the client on connection event.
Currently the framework supports on message, there should be a handle for on connection event as well.
Hi there.
I've successfully been able to relay inbound MQTT websocket requests to another server using the following invocation given a direct reference to the http server, like this (with irrelevant application-details about html pages removed)...
var httpServer = http.createServer();
var app = express();
httpServer.on("request", app);
var proxy = httpProxy.createProxyServer({
ws:true,
target:"ws://localhost:3000",
});
httpServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});
However, I'm struggling to find how to satisfy the same constraints within an expressWs route. I've been attempting something like...
var httpServer = http.createServer();
var app = express();
httpServer.on("request", app);
var proxy = httpProxy.createProxyServer({
ws:true,
target:"ws://localhost:3000",
});
var expressWsConfig = expressWs(app, httpServer);
//handle requests for websocket upgrade - in the future, route according to cookies
app.ws("*", function(ws, req){
proxy.ws(req, req.connection);
});
The reason I'm trying to use expressWs is that I need to use the same authentication middleware when serving the page and proxying the connection (also through port 80).
In particular I need to proxy to different backing servers depending on the authenticated identity and session, so ideally I would be able to e.g. inspect Passport's req.isAuthenticated() and benefit from previous calls to req.login() to employ user records to route the proxied websocket request ( http://passportjs.org/docs/login ).
The example client code I am deploying for testing is like this...
var mqtt = require("mqtt"),
$ = require("jquery-browserify");
var client = mqtt.connect("ws://localhost:8080/mqtt");
$(function(){
setInterval(function(){
client.publish("hello", "world" + Date.now());
}, 1000);
})
...and it is successfully able to connect to MQTT and dispatch messages with the first example server code I shared (the on-upgrade event), but when I attempt it using the second version (the express-ws route) it results in the following in-browser error every second...
WebSocket connection to 'ws://localhost:8080/mqtt' failed: Invalid frame header
Any suggestions for how to properly replicate the proxy behaviour when embedded inside an express-ws route?
Hello there, i'm trying to use express-ws together with already existed express application, but running into some issues.
Basic info:
Node.js - v6.9.1
Express - 4.15.0
Express-ws - 3.0.0
Using express with Gulp throw nodemon:
gulp.task('express:dev', function(cb) {
var started = false;
return nodemon({
script: 'server/app.js',
watch: ['server/app.js']
}).on('start', function() {
// to avoid nodemon being started multiple times
// thanks @matthisk
if (!started) {
cb();
started = true;
}
}).on('restart', function(ev) {
gulpUtil.log('[nodemon] restarted');
gulpUtil.log('files changed:\n' + ev);
setTimeout(function() {
browserSync.notify('reloading now ...');
browserSync.reload({stream: false});
}, 1000);
})
.on('crash', function() {
gulpUtil.log('[nodemon] crashed: script crashed for some reason');
})
.on('exit', function() {
gulpUtil.log('[nodemon] exited cleanly');
});
});
app.js:
var NODE_PORT = 3000;
var express = require('express');
var expressWs = require('express-ws');
var logger = require('./config/logger');
// Setup server
var app = express();
app.server = require('http').createServer(app);
var expressWsObj = expressWs(express, app.server);
require('./config/express')(app);
require('./routes')(app);
app.ws('/', function(ws, req) {
ws.on('message', function(msg) {
console.log(msg);
});
console.log('socket', req.testing);
});
// Start express server
app.server.listen(NODE_PORT, 'localhost', function() {
'use strict';
logger.verbose('Express server serves the fake backend and listens on port', NODE_PORT);
});
// Expose app
module.exports = app;
Ends up with next error:
error: uncaughtException: app.use is not a function date=Thu Mar 02 2017 09:33:57 GMT+0100 (Romance Standard Time), pid=10052, uid=null, gid=null, cwd=src\main\webapp, execPath=C:\Program Files\nodejs\node.exe, version=v6.9.1, argv=[C:\Program Files\nodejs\node.exe, src\main\webapp\server\app.js], rss=33292288, heapTotal=21008384, heapUsed=13176632, loadavg=[0, 0, 0], uptime=1793.9372317, trace=[column=9, file=src\main\webapp\server\config\express.js, function=module.exports, line=12, method=exports, native=false, column=28, file=src\main\webapp\server\app.js, function=, line=20, method=null, native=false, column=32, file=module.js, function=Module._compile, line=570, method=_compile, native=false, column=10, file=module.js, function=Object.Module._extensions..js, line=579, method=Module._extensions..js, native=false, column=32, file=module.js, function=Module.load, line=487, method=load, native=false, column=12, file=module.js, function=tryModuleLoad, line=446, method=null, native=false, column=3, file=module.js, function=Function.Module._load, line=438, method=Module._load, native=false, column=10, file=module.js, function=Module.runMain, line=604, method=runMain, native=false, column=7, file=bootstrap_node.js, function=run, line=394, method=null, native=false, column=9, file=bootstrap_node.js, function=startup, line=149, method=null, native=false], stack=[TypeError: app.use is not a function, at module.exports (src\main\webapp\server\config\express.js:12:9), at Object. (src\main\webapp\server\app.js:20:28), at Module._compile (module.js:570:32), at Object.Module._extensions..js (module.js:579:10), at Module.load (module.js:487:32), at tryModuleLoad (module.js:446:12), at Function.Module._load (module.js:438:3), at Module.runMain (module.js:604:10), at run (bootstrap_node.js:394:7), at startup (bootstrap_node.js:149:9)]
Any idea why express use function are not visible anymore ?
I've tried folding the example code into an instance of express that was created using express-generator. I don't ever get a connection happening from the client side, and a breakpoint set with node-inspector in the app.ws callback function never gets hit.
The startup code (./bin/www) created with express-generator does some things that may have not been anticipated? It basically requires app.js and sets up a listener on a port itself.
The documentation only shows an example of ws.on(...)
and ws.send(...)
. What else exists? How do I use them?
var app = express();
//setup app;
app.listen(3000); // that way it will work
var server = http.createServer(app);
server.listen(3000); // that way not
Hi im new to express ws is there a way on how can i get the online users
var chatrooms = {};
app.ws('/send/:chatroom_id', function(ws,req,next) {
var chatroom_id = req.chatroom_id;
var room = chatrooms[chatroom_id] || {
connections : []
};
room.connections.push(ws);
chatrooms[chatroom_id] = room;
ws.on('message', function(msg) {
room.connections.forEach(function(conn) {
conn.send(msg);
});
});
next();
});
Express generator (and similar) tend to make a habit of loading detached router modules before requiring the app instance (see: https://github.com/expressjs/generator/blob/master/templates/js/app.js)
The documentation doesn't make clear that the router patching only works if you initialize express-ws before require()ing any router-specifying module. @joepie91 said he'd update it :)
Can you please try to switch ws to 2.0.0-beta.1?
Hey there,
awesome library that removes a lot of hassle, really!
I have this particular use case in which I am releasing a library which expose a Express router,
so here is the following use case:
var linkedDataProvider = require("./ldp")
var express = require("express")
var app = express();
app.use('/test', ldp({patch: true}));
Now, the implementation of ldp is as following:
module.exports = function(opts) {
var router = new express.Router();
[...]
router.post("/", postOrPatch);
router.delete("/", deleteObj);
[...]
return router;
}
Now, if I want to include
router.ws(''/", realTime);
How can make this happen?
My ideas are the following
ldp(route)(app)
Thanks a lot for your time
it seems there is no test case and code coverage?
this does not work...
app = require('express');
require('express-ws')(app);
server = require('http').createServer(app);
server.listen(3000);
it only works if you listen from express app directly as in...
app = require('express');
require('express-ws')(app);
app.listen(3000);
so how then do you allow wss:// from a secure https server?
app = require('express');
require('express-ws')(app);
server = require('https').createServer({key:keydata, cert:certdata}, app);
server.listen(3000);
The above code runs fine without exceptions but when you try to connect a websocket from the browse you get 'Firefox can't establish a connection to the server at ws://localhost:3000/.'
Also it would be nice if app.ws('route', callback); returned back the instance of app, so that it could be chained as such...
app
.use(....)
.post(...)
.ws(...)
.get(...)
I have a small app hosted on https as mentioned here http://stackoverflow.com/a/11745114/2147987
express-ws works on ws:// endpoint but not on wss://. Does express-ws work on ssl?
I'm trying to use:
router.ws(new RegExp('^/([0-9]{6})$'), function (ws, req) {
// do stuff
});
But it's throwing an error on line 18 of websocket-url.js because it's always assuming a string:
/* The following fixes HenningM/express-ws#17, correctly. */
function websocketUrl(url) {
if (url.indexOf('?') !== -1) {
var _url$split = url.split('?');
var _url$split2 = _slicedToArray(_url$split, 2);
var baseUrl = _url$split2[0];
var query = _url$split2[1];
return (0, _trailingSlash2.default)(baseUrl) + '.websocket?' + query;
}
return (0, _trailingSlash2.default)(url) + '.websocket';
}
In Express' philosophy, things are handled part by part in different middlewares. Can I partially handle a WebSocket connection in one middleware and leave it to another, or are there any work-around to achieve the same goal? For example,
app.ws('/', function(ws, req, next) {
ws.on("message", function(msg) {
// do something
next(); // call `next` here
});
});
app.ws('/', function(ws, req) {
ws.on("message", function(msg) {
// do something else
});
});
To be specify, I want to share the same user authentication mechanism with both HTTP and WebSocket, so I need to forward Cookies using WebSocket. Then, I need a middleware to place the forwarded Cookies back into the req
parameter. Is it possible?
I'm receiving this error occasionally which is causing my program to crash. I'm assuming it's because I don't handle the error event, but should this be the expected result? I would think that the error would just be ignored.
For reference here is the program: https://github.com/fletchto99/Pebble-liveconfig/blob/master/server/liveconfig.js
liveconfig-0 Error: Uncaught, unspecified "error" event. (invalid error code)
liveconfig-0 at WebSocket.emit (events.js:157:17)
liveconfig-0 at Receiver.self._receiver.onerror (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/WebSocket.js:704:10)
liveconfig-0 at Receiver.error (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/Receiver.js:295:8)
liveconfig-0 at Receiver.opcodes.8.finish (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/Receiver.js:491:14)
liveconfig-0 at Receiver.<anonymous> (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/Receiver.js:472:33)
liveconfig-0 at Receiver.add (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/Receiver.js:87:24)
liveconfig-0 at Socket.firstHandler (/usr/local/lib/node_modules/express-ws/node_modules/ws/lib/WebSocket.js:663:22)
liveconfig-0 at emitOne (events.js:90:13)
liveconfig-0 at Socket.emit (events.js:182:7)
liveconfig-0 at readableAddChunk (_stream_readable.js:147:16)
I have an express4 app and I add the following to my app...
require('express-ws')(app);
app.ws('/ws', function(ws, req) {
ws.on('message', function(msg) {
ws.send(msg);
});
});
Then I run the app. However, when I try to connect to the websocket I get the following...
at ServerResponse.OutgoingMessage._send (_http_outgoing.js:138:38)```
Hello there,
First kudos for this package - makes websockets much less painful in expressjs.
I'm having a bit of trouble making a connect to the socket. I start the server with:
app = require('express-ws')(express()).app;
then set up the route like so
app.ws('/ws/route', function (ws, req) {
console.info("connected");
ws.on('message', function (msg) {
ws.send(msg);
})
});
but testing this with
var test = new WebSocket("ws://localhost:3000/ws/route");test.onerror = function () {console.error("error");};test.onclose = function () {console.info("close");};
yields "close" in the console. Is there something obvious that I'm doing wrong?
Please provide an example of setting up a ping/pong heartbeat.
I've tried the following, but the ping is never sent.
app.ws('/', function(ws, req) {
ws.on('connection', function(conn) {
console.log('websocket connected');
setInterval(function timeout() {
ws.ping("heartbeat");
}, 500);
});
)};
Hi HenningM and thank you for putting this library together. I played around with it a bit and read your documentation about broadcasting for all clients on the server and not just a route.
Is there any way this (broadcasting to only clients on a route) could be done? If there are possibilities to consider, please let me know.
If not feasible, please let me know if there are other options (I can't use socketIO) I might consider.
Thank you!
https://github.com/HenningM/express-ws/blob/master/index.js#L55
Error handling should be configurable somehow - right now they're just swallowed. I'm somewhat new to express, so does anyone have suggestions on the proper way to handle exceptions?
I am running a browser side script which sends a message to Node.js running express hosting express-ws. I am seeing the connection form fine but when I send a message from the browser, I am not seeing any callbacks on the server side.
Here is my browser code:
$(function() {
var ws = new WebSocket("ws://raspi3:3000/test");
ws.onopen = function() {
console.log("Web Socket open!");
ws.send("Hi!");
};
ws.onerror = function(err) {
console.log("Web socket error: " + err);
};
ws.onclose = function() {
console.log("Web socket closing: ");
};
});
and here is my server code:
var express = require("express");
var app = express();
var expressWs = require("express-ws")(app);
app.ws("/test", function(s1, req) {
conosle.log("ws handler called");
s1.on("message", function(msg) {
console.log("We got a ws message!");
s1.send("Hi!");
});
});
app.use(express.static("."));
app.listen(3000, function() {
console.log("Express app started on port 3000");
});
I am anticipating the console.log messages in app.ws()
to appear ... but I am not seeing any of them.
var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
app.use(function (req, res, next) {
console.log('middleware');
req.testing = 'testing';
return next();
});
app.get('/', function(req, res, next){
console.log('get route', req.testing);
res.end();
});
app.ws('/', function(ws, req) {
ws.on('message', function(msg) {
console.log(msg);
});
console.log('socket', req.testing);
});
it is not clear to the newb what "server" variable refers to, just FYI
app.ws('/send/:chatroom_id', function(ws,req,next) {
var chatroom_id = req.chatroom_id;
var aWss = expressWs.getWss('/send/' + chatroom_id);
ws.on('message', function(msg) {
aWss.clients.forEach(function(client) {
client.send(msg);
});
});
next();
});
How can i implement different chat room by different chatroom_id paramter on the same route
I tried the example, I get no connection events, no errors. Something is going wrong and getting swallowed.
Can you publish a working example, complete with client-side code?
With regular express requests I'm using bunyan-middleware
any thoughts on how to log ws handlers similarly?
Hello,
I try to create a Websocket URL with
po_application.ws('/chat/:did', function( po_socket, po_request ) {
po_socket.on('message', function( pc_message ) {
console.log(pc_message);
});
});
with lo_application
is the express() instance.
The did parameter is defined with
po_route.param('did', function(po_request, po_resource, po_next, pc_documentid) {
pc_request.document = pc_documentid || null;
po_next();
});
Also a URL like /chat/(.+)
is not working. How I can add an URL with a parameter for a Websocket URL
When i use express-ws, the 'error' event is no more fired when there is a EADDRINUSE error for example.
let Express = require('express');
let ExpressWs = require('express-ws');
let HTTP = require('http');
// First server
let expressApp = Express();
let nodeServer = HTTP.createServer(expressApp);
nodeServer.listen(8080, ()=>console.log('started'));
// Second Server
let expressApp2 = Express();
let nodeServer2 = HTTP.createServer(expressApp2);
ExpressWs(expressApp2, nodeServer2);
nodeServer2.listen(8080, ()=>console.log('started'));
// => event catched when there is no ExpressWs
nodeServer2.on('error',(err)=>console.log('error : '+err.code));
i use node v7.5.0, express v4.15.2
Is there a close event one can react to? For instance to notify other participants in a chat that someone lost the connection?
Hi,
This might sound like noob-ist request, but being very experienced with express and REST, i'm trying to figure out from the documentation how would the client-side communication would be. If there is a repo that actually show a full stack usage, please let me know.
My goal would be to "translate" the REST call into websocket:
POST /users/123
{ pay: 'load' }
to something like:
ws = new WebSocket("/ws");
....on('click', () => {
ws.send({method: 'POST', path: '/users/123', data: {pay:'load'}});
});
Would this mean that I need to define:
router.ws('/users/:id', (ws, req) => {
ws.send({status: 200, body: {ret:'urn'});
});
Express exposes a locals
property on the response object that it meant to be used to pass data between middlewares for the current request only. I think this property should be passed on the ws
object, probably here. I'd be happy to do so and open a PR if you agree! In any case, awesome library!
Hi, I have a trouble use this lib.
// my route file
var express = require('express');
var expressWs = require('express-ws')(express());
var event = require('events').EventEmitter();
var app = expressWs.app;
/* GET users listing. */
app.get('/', function(req, res, next) {
res.send('respond with a game');
});
app.post('/result', function(req, res, next) {
console.log(req);
event.emit('update_hp', req);
});
app.ws('/hp', function(ws, req) {
console.log('connect ws');
next();
});
module.exports = app;
//my client file
var liveSocket = new WebSocket("ws://localhost:3000/hp");
liveSocket.onclose(function(){
console.log 'closed';
});
I can successfully get localhost:3000/
and post data to localhost:3000/result
but console output error:
WebSocket connection to 'ws://localhost:3000/hp' failed: Connection closed before receiving a handshake response
Can you help me?
Thanks in advance.
I am getting the exception as mentioned in the following:
stackout.txt
The source of my server file is:
server.txt
Seriously, was a breeze to incorporate into my current app - many thx for saving me the headache of gluing ws and express together.
My one suggestion would be to add the example in #50 to the README - helped me quite a bit in setting up a more advanced use case.
I am wondering if we have a recipe for setting up a secure (as in https/ssl/tls) express-ws server. I am trying permutations from googling around but am floundering. If we had a sample setup for https, that would be fantastic.
When I run the following code and access to http://localhost:3000/ with Firefox, It crashed.
const express = require('express');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const app = express();
const expressWs = require('express-ws')(app);
app.use(cookieParser());
app.use(session({ secret: 'foo' }));
app.use('/', function(req, res) {
res.send("<script>new WebSocket('ws://localhost:3000/bar');</script>");
});
app.listen(3000);
express-session deprecated undefined resave option; provide resave option app.js:8:9
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:8:9
_http_outgoing.js:144
this.outputSize += this._header.length;
^
TypeError: Cannot read property 'length' of null
at ServerResponse._send (_http_outgoing.js:144:38)
at ServerResponse.write (_http_outgoing.js:536:16)
at ServerResponse.end (_http_outgoing.js:635:10)
at writeend (/Users/sunaemon/Dropbox/myapp/node_modules/express-session/index.js:261:22)
at Immediate.onsave (/Users/sunaemon/Dropbox/myapp/node_modules/express-session/index.js:335:11)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
I'm using node v6.10.0 and following packages.
[email protected]
[email protected]
[email protected]
[email protected]
Is this a bug of express-ws? Or should I send this issue for express-session?
The error message is similar to #46, but I can not determine whether this issue is related to it or not.
need to access wss object sometimes, such as get all clients and broadcasting, like this:
https://github.com/einaros/ws#server-sending-broadcast-data
Maybe I am missing something, but I can't see how to close the sockets. I want my server to respond to SIGINT
and close gracefully, but the sockets from app.ws()
and ws.getInstance().clients
do not have a .destroy()
method. If I call server.close()
, close the browser and wait two minutes then the socket times out and the program will exit.
Any help with this would be appreciated.
This is a great idea and very handy to be able to integrate with express.
I'm trying to use it with Express 4, but I get this after a small delay from the client:
*WebSocket connection to 'ws://localhost:3000/api/event/54657830c37ba8244fb22385' failed: Connection closed before receiving a handshake response *
Server:
app.ws("/api/event/:id", function(ws, req) {
console.log("Received web socket connection");
});
Client:
var address = "ws://localhost:3000/api/event/54657830c37ba8244fb22385";
var connection = new WebSocket(address);
connection.onopen = function() { console.log("Opened web socket connection"); }
I never get any of the console output indicating that the connection was made from either side.
The rest of my routes are defined through the Express 4 router. Could this be interfering with putting this route on the "app"?
Thanks,
Mike
If you run the following test app:
var express = require('express');
var app = express();
require('express-ws')(app);
app.ws('/test', function(ws, req) {
console.log('incoming connection');
});
app.get('/*', function(req, res, next){
res.sendFile(__dirname + '/test.html');
});
app.listen(3000);
When you make a WebSocket request to ws://localhost:3000/invalidroute, the process crashes with the following exception:
http_outgoing.js:135
this.outputSize += this._header.length;
^
TypeError: Cannot read property 'length' of null
at ServerResponse.OutgoingMessage._send (_http_outgoing.js:135:38)
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:477:16)
at ReadStream.ondata (_stream_readable.js:536:20)
at emitOne (events.js:90:13)
at ReadStream.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:153:18)
at ReadStream.Readable.push (_stream_readable.js:111:10)
at onread (fs.js:1818:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:614:17)
I have posted this issue clearly in stackoverflow forum. please find the respective link
Case from examples:
var express = require('express');
var expressWs = require('..')
var expressWs = expressWs(express());
var app = expressWs.app;
app.ws('/a', function(ws, req) {
});
var aWss = expressWs.getWss('/a');
app.ws('/b', function(ws, req) {
});
setInterval(function () {
aWss.clients.forEach(function (client) {
client.send('hello');
});
}, 5000);
app.listen(3000)
aWss.clients
<-- contains all clients, '/a' and '/b', but expected only '/a' clients.
I'm using [email protected] with [email protected] successfully. Can we update package.json to get rid of npm warning:
npm WARN [email protected] requires a peer of express@^4.0.0 but none was installed.
the only required change:
"express": "^4.0.0"
to
"express": "^4.0.0 || ^5.0.0-alpha.2"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.