After successfully setting up a WebSocket server using ws for basic messaging, my next goal was to implement a peer-to-peer calling service. This involved utilizing the PeerServer on the server side and PeerJS on the client side. However, I encountered an issue where the client was unable to connect to the server, as the WebSocket continuously returned a status of "Finished." This problem specifically arose within iisnode.
Below is a snippet from 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"gt;
<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 “ws” rule pertains to the basic WebSocket server.
Here is an excerpt from the 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);
For the 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
});
});
An error log on the server side displayed :
(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 created)
It’s worth noting that despite the warning, the WebSocket server functionality remained unaffected.
Any assistance in resolving this issue would be highly appreciated.
##EDIT##
Console errors on the client side :
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.