I have a simple clientside javascript application. I want it to load a DLL file (for a SwipeReader CR100) and call functions from the DLL library from within the javascript
I've done it. The solution is to use EdgeJS as a bridge between NodeJS V8 and C# CLR. Edge loads the DLL and creates a communication channel between V8 and CLR, the messages are functions of the form Func or function(payload, callback) that are marshalled between each language VM.
I'll post the code sample below:
C#
public abstract class NetWebSocket
{
private Func
Javascript/NodeJS
(function(e,d,g,e){
var edge = require('edge'),
http = require('http'),
WebSocketServer = require('ws').Server,
swipe = edge.func('./dlls/ActiveXCOM.dll');
var server = http.createServer(function(req,res){
res.writeHead(200, {'Content-Type' : 'text/html'});
res.end((
function () { /*
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]);
});
var wss = new WebSocketServer({server: server});
wss.on('connection', function(ws) {
var sendImpl = function (message, callback) {
console.log(message);
ws.send(message);
callback();
};
var receiveHandler = swipe(sendImpl, true);
ws.on('message', function (message) {
receiveHandler(message);
});
ws.on('close', function close(){
console.log('****************************The client disconnected!');
receiveHandler('shutdown');
delete receiveHandler;
});
});
server.listen(process.env.PORT || 8080);
module.exports = this;
})();
I hope the implementation is clear. If you have any trouble understanding it, please don't hesitate to write to me.
Happy Coding!
[Don't listen to the naysayers!]