javascript - What Express websocket events exist? -
i wondering web socket events exist? far have been using ws.on('message')
event, use event triggered when connection established , closed. tried adding ws.on('connection')
, didn't triggered.
why isin't there list of events in websocket modules documentation? https://www.npmjs.com/package/express-ws
my code:
app.ws('/', function (ws, req) { ws.on('message', function (textchunk) { //do stuff } }); });
do need client side programming this?
edit: tried adding this, didn't trigger when connected client.
ws.on('request', function () { console.log("request"); });
after looking @ source code express-ws
looks can following.
var express = require('express'); var app = express(); var expressws = require('express-ws')(app); // websocketserver instance getwss() // https://github.com/henningm/express-ws/blob/5b5cf93bb378a0e6dbe6ab33313bb442b0c25868/index.js#l72-l74 expressws.getwss().on('connection', function(ws) { console.log('connection open'); }); // ... express middleware // ... websocket middle ware app.ws('/', function(ws, req) { ws.on('message', function(msg) { console.log(msg); }); }); app.listen(3000);
old response
there following:
close error message open
https://developer.mozilla.org/en-us/docs/web/api/websocket#attributes
Comments
Post a Comment