You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @mikuso,
I'm not sure if it is related to this bug but when I connect to the RPC Server with a subprotocol that is not allowed, the event 'client' is fired and some of my server logic is executed. Should it not be 'upgradeAborted' directly instead ?
Also, the server answers with a HTTP response that has no Sec-WebSocket-Protocol header but there is a Sec-WebSocket-Accept.
Server code :
const { RPCServer, createRPCError } = require('ocpp-rpc');
const express = require('express')
const app = express();
app.get("/charge_stations", getChargeStations);
const httpServer = app.listen(3000, 'localhost');
const rpcServer = new RPCServer({
protocols: ['ocpp1.6', 'ocpp2.0.1'], // rpcServer accepts ocpp1.6 and ocpp2.0.1 subprotocols
strictMode: true, // enable strict validation of requests & responses
});
httpServer.on('upgrade', rpcServer.handleUpgrade);
rpcServer.auth((accept, reject, handshake) => {
if (handshake.endpoint === '/ocpp') {
accept();
} else {
console.log("Wrong OCPP endpoint")
reject(400, "Wrong OCPP endpoint");
}
});
rpcServer.on('client', async (client) => {
console.log(`${client.identity} connected!`);
// create a specific handler for handling BootNotification requests
client.handle('BootNotification', ({params}) => {
console.log(`rpcServer got BootNotification from ${client.identity}:`, params);
// respond to accept the client
return {
status: "Accepted",
interval: 300,
currentTime: new Date().toISOString()
};
});
// create a specific handler for handling Heartbeat requests
client.handle('Heartbeat', ({params}) => {
console.log(`rpcServer got Heartbeat from ${client.identity}:`, params);
// respond with the rpcServer's current time.
return {
currentTime: new Date().toISOString()
};
});
// create a specific handler for handling StatusNotification requests
client.handle('StatusNotification', ({params}) => {
console.log(`rpcServer got StatusNotification from ${client.identity}:`, params);
return {};
});
// create a wildcard handler to handle any RPC method
client.handle(({method, params}) => {
// This handler will be called if the incoming method cannot be handled elsewhere.
console.log(`rpcServer got ${method} from ${client.identity}:`, params);
// throw an RPC error to inform the rpcServer that we don't understand the request.
throw createRPCError("NotImplemented");
});
});
function getChargeStations(req, res){
res.send('Hello !')
}
As per title, the RPCServer's 'upgradeAborted' event can fire after websocket upgrade was successful.
The text was updated successfully, but these errors were encountered: