So I have built a WebSocket server on ws and this works perfectly for sending basic messages. What I wanted to do next was create a peer to peer calling service using PeerServer server side and PeerJS client side. However the client cannot connect to the server the WebSocket keeps returning status:"Finished". Again this is specifically iisnode.
Here is my web.config file :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="node_app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="ws" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^NodeJS/WebSocket/WS/?$" />
<action type="Rewrite" url="\NodeJS\WebSocket\WS\node_app.js" />
</rule>
<rule name="peerjs" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^NodeJS/PeerJS/Server/?.*" />
<action type="Rewrite" url="\NodeJS\PeerJS\Server\node_app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The rule name="ws" is for the basic WebSocket server.
Server side code for PeerServer "\NodeJS\PeerJS\Server\node_app.js" :
// peer_server
var ExpressPeerServer = require('peer').ExpressPeerServer;
var peerExpress = require('express');
var peerApp = peerExpress();
var peerServer = require('http').createServer(peerApp);
var options = { debug: true }
var peerPort = process.env.PORT;
peerApp.use('/', ExpressPeerServer(peerServer, options));
peerServer.listen(peerPort);
Client side Javascript :
window.addEventListener('load', function() {
var url = '/NodeJS/PeerJS/Server/';
var peer_url = location.hostname + url;
var thisCallerID = 123;
peerJS = new Peer(thisCallerID,{
host: location.hostname,
path: url,
debug: 1
});
});
The error log I get sever side is :
(node:17520) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use
node --trace-deprecation ...
to show where the warning was cre ated)
However I get this warning on the WebSocket server too and it works just fine.
Any help would be greatly appreciated.
##EDIT##
Client side console errors :
socket.ts:42 WebSocket connection to 'wss://mydomain.co.za/NodeJS/PeerJS/Server?key=peerjs&id=123&token=s0gab0l3rf9&version=1.5.4' failed:
logger.ts:76 ERROR PeerJS: Error: Lost connection to server.
So it was really quite obvious can't believe I missed this but in case someone else made this mistake too.
In the PeerJS Server file where you set the express app to use the ExpressPeerServer this takes a url path as an argument. This path needs to be the actual URL path of file, in my case "/NodeJS/PeerJS/Server/".
// peer_server
var ExpressPeerServer = require('peer').ExpressPeerServer;
var peerExpress = require('express');
var peerApp = peerExpress();
var peerServer = require('http').createServer(peerApp);
var options = { debug: true }
var peerPort = process.env.PORT;
peerApp.use('/NodeJS/PeerJS/Server/', ExpressPeerServer(peerServer, options));
peerServer.listen(peerPort);