I have a node implementation of cometD, what I am trying to do is have an end point that can send a GET to, and then have it publish a message in the cometD channel.
The handshakes keep failing and I'm not really sure why.
How do I enable more verbose logging on either side to get to the bottom of this ? Or if there's something obvious I'm missing please let me know.
Server code
const fs = require("fs");
const express = require("express");
const app = express();
const httpPort = 3000;
const cometdPort = 3001;
const sslCfg = {
"keyPath": "/path/to/key.pem",
"certPath": "/path/to/bundle.crt"
}
// commetD stuff
const https = require('https');
const sslConfig = {
key: fs.readFileSync(sslCfg.keyPath),
cert: fs.readFileSync(sslCfg.certPath)
}
const cometd = require('cometd-nodejs-server');
const cometdServer = cometd.createCometDServer(sslConfig);
const cometdServer = https.createServer(cometdServer.handle);
cometdServer.listen(cometdPort, function() {
// Your application code here.
console.log(`CometD server set up `);
});
const demoChannel = cometdServer.createServerChannel('/techDemo');
demoChannel.addListener('message', function(session, channel, message, callback) {
callback();
});
const myIDs = JSON.parse(fs.readFileSync('./idMap.json'));
app.get("/:myId", (req, res) => {
const id = req.params.myId;
const respObject = {
"selectionId": myIDs[id]
}
res.send(respObject);
demoChannel.publish(false, JSON.stringify(respObject));
})
https.createServer(sslConfig, app).listen(httpPort);
Client code
require('cometd-nodejs-client').adapt();
// Your normal CometD client application here.
var lib = require('cometd');
var cometd = new lib.CometD();
// Configure the CometD object.
cometd.configure({
url: 'https://myserver.com:3001/cometd'
});
// Handshake with the server.
cometd.handshake(function (h) {
if (h.successful) {
console.log(`Handshake successful`)
// Subscribe to receive messages from the server.
cometd.subscribe('/techDemo', function (m) {
var dataFromServer = m.data;
// Use dataFromServer.
console.log(dataFromServer);
});
} else {
console.error(`Handshake failed`)
console.error(h);
}
});
Handshake errors
{
id: '1',
successful: false,
channel: '/meta/handshake',
failure: {
websocketCode: 1000,
reason: 'Error',
connectionType: 'websocket',
transport: { envelopes: {}, timeouts: {}, webSocket: [WebSocket] },
message: {
id: '1',
version: '1.0',
minimumVersion: '1.0',
channel: '/meta/handshake',
supportedConnectionTypes: [Array],
advice: [Object]
}
}
}
{
id: '2',
successful: false,
channel: '/meta/handshake',
failure: {
reason: 'write EPROTO 29280:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\rec_layer_s3.c:1546:SSL alert number 40\n',
exception: undefined,
httpCode: 0,
connectionType: 'long-polling',
transport: {
status: 0,
statusText: 'write EPROTO 29280:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\rec_layer_s3.c:1546:SSL alert number 40\n',
readyState: 4,
responseText: '',
open: [Function (anonymous)],
setRequestHeader: [Function (anonymous)],
send: [Function (anonymous)],
abort: [Function (anonymous)],
_config: [Function (anonymous)],
context: undefined,
withCredentials: true,
onload: [Function (anonymous)],
onerror: [Function (anonymous)],
onabort: [Function (anonymous)]
},
message: {
id: '2',
version: '1.0',
minimumVersion: '1.0',
channel: '/meta/handshake',
supportedConnectionTypes: [Array],
advice: [Object]
}
}
}