Skip to content

Instantly share code, notes, and snippets.

@sergkh
Created June 6, 2023 06:16
Show Gist options
  • Save sergkh/beadcc6866879b435f18fe86114cc04a to your computer and use it in GitHub Desktop.
Save sergkh/beadcc6866879b435f18fe86114cc04a to your computer and use it in GitHub Desktop.
var WebSocketClient = require('websocket').client;
const client = new WebSocketClient({ closeTimeout: 10 });
const deliveryRequest = {
sessionId: 'test-session',
serviceId: 'slow',
cardId: {
cin: '0000000000000000',
iin: '31045100000000'
},
capabilities: {},
fields: {
delay: '1',
repeat: '10'
}
}
const transceiveResponse = {
operationId: '3C7A88C4-4810-4666-9F3D-83E9F3026FA4',
sessionId: 'test-session',
responses: [ '9000' ],
statusCode: 200,
operationType: 'transceive'
}
client.on('connect', connection => {
connection.on('error', (error) => console.log("Connection Error: " + error.toString()))
connection.on('close', () => console.log('Connection Closed'))
connection.on('message', function(messageReq) {
const message = JSON.parse(messageReq.utf8Data)
console.log("Got: '" + messageReq.utf8Data + "'")
if (message.operation == 'transceive') {
connection.sendUTF(JSON.stringify(transceiveResponse))
} else if (message.operation == 'status') {
connection.close()
}
});
// init delivery
connection.sendUTF(JSON.stringify(deliveryRequest))
})
client.connect('ws://localhost:9000/ws-deliver/slow')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment