I am encountering an issue where the client side is unable to connect to a peerjs server hosted on iisnode. The status currently shows as "Finished" instead of the expected "101". I am unsure why this is happening

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.

Answer №1

It's amazing how something so obvious can slip through the cracks, but in case someone else stumbles upon this same issue, here's the solution.

In the PeerJS Server file, make sure to correctly set the express app to use the ExpressPeerServer with the designated URL path. In my situation, it was "/NodeJS/PeerJS/Server/".

// Setup 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);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Building Your Own Custom Mobile Global Breakpoint Plugin with Vuetify in Nuxt.js

Looking to set up a custom breakpoint system for my Nuxt/Vuetify project so I can easily manage it from one centralized location instead of using $vuetif.breakpoint..... etc To achieve this, I have created a plugin file named mobile.js. While it functions ...

Including a hyperlink to a non-secure website from a secure relative path

Forgive me for asking what may be the silliest question ever, but I'm stumped: On my secure HTTPS page: <a href="../../../folder/index.php?openMenu=SEARCH">Advanced search</a> The link seems to work fine, but it points to an HTTP page i ...

Using JavaScript to send form input in the form of a 2D array through AJAX

I am currently working on a form that looks like this: <form name="chat" id="chat" action="" onsubmit="sendMessage()"> <a name="chat">&nbsp;</a> <input type="text" name="chat" id="chat" size="38" maxlength="50" vertical-align="m ...

Listen for the 'open' event on a node HTTP server

This question pertains to a previous inquiry I had about node httpServer encountering the EADDRINUSE error and moving to the next available port. Currently, my code looks like this: var port = 8000; HTTPserver .listen(port, function() { console.lo ...

How to create a sequence of queries to a mongoDB database (using mongoose) depending on a condition

Source Code let placeForSearch="hampi" let filteredHotelFacilities=req.body.filter //["Free Wifi"] let hotels = await Hotel.find({placeForSearch}) .where("facilities") .select(selectedProperties) .skip(pageNu ...

Utilizing Bootstrap Modal to trigger an Action Result function when a button is clicked

I could use some assistance. In my current setup, I have a file picker that loads a file into a specific table in my database. When the user clicks a button, a bootstrap modal pops up to ask if they are uploading more files. This is how it looks in my vi ...

Methods for retrieving HTML tag attribute values with JavaScript Regular Expressions

Imagine I have the following HTML stored in a string: <meta http-equiv="Set-Cookie" content="COOKIE1_VALUE_HERE"> <meta http-equiv="Set-Cookie" content="COOKIE2_VALUE_HERE"> <meta http-equiv="Set-Cookie" content="COOKIE3_VALUE_HERE"> Ad ...

It is not possible to include parameters in mongoose schema that have not been defined

Is it possible to add new parameters in a MongoDB collection that are not defined in the Mongoose schema? Below is the current schema: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UsersSchema = new Schema({ FirstNam ...

Encountering an issue with the combination of SockJS and AngularJS: Error message

Currently experimenting with Angularjs and sockjs, utilizing this helpful resource: https://github.com/bendrucker/angular-sockjs On page load, I aim to transmit data via sockjs, however, encountering an Error: INVALID_STATE_ERR on the client side when att ...

Rendering Single File Components with Render Functions in Vue 2: A Step-by-Step Guide

I am facing an issue with rendering a Single File Vue Component using a render function. I have tried different variations like the one below: // simple.vue <template> ... </template> <script> ... </script> // parent.vue <scr ...

Tips for customizing Material UI Tooltip styles

Is there a way to customize the appearance of the Material UI Tooltip title? I have noticed that by default, the tooltip displays with a black background and no text wrap on hover. Can the background color, text color, and other styles be modified? Wonde ...

Secure your controller functions by wrapping them with session values in a separate function

My system relies on session values to determine if a user is an admin. Currently, I am checking for this information in each controller function like so: exports.DeleteUser = function (req, res) { if(req.session == undefined || req.session.Lv < 80) ...

Explore the various installation possibilities for Node.js and npm

Can you explain the variance between npm install express npm install -g express If you can provide a link that elaborates on these options, it would be greatly appreciated. ...

The problem of width and display arises when utilizing highchart

I am attempting to create a select option that will display a different chart when changed. However, I am encountering two main issues: 1. The chart is not displaying properly within the div width. 2. How can I hide other charts when one is displayed? JS ...

Managing control among various child popups

In the situation I am facing, a parent window with login fields is present. In order to manage its controls, I have stored the window handle using: String parentWindow = idriver.getWindowHandle(); After entering the login credentials, a new popup (let&ap ...

Display intricate header and preview in a printed datatable

Hey there, I've been using the Datatable plugin and it's really great. However, I've come across a problem with complex headers like this: <thead> <tr><td>some text</td></tr> <tr><td>some te ...

When attempting to input a date, the forward slashes symbolize the dividing line between

In my webpage, I have a variable called var holding a date "29/5/2017". I am attempting to pass this variable to a function stored in a separate JavaScript file. However, when I examine the JavaScript code through debugging, I notice that it interprets the ...

Handling errors with Busboy in Express.JS: A comprehensive guide

I need assistance with capturing all errors in a file event using busboy and passing the error to the next function. Additionally, I want to be able to handle any busboy errors and pass them to the next function as well. import * as Busboy from 'busbo ...

The Owl carousel seems to be malfunctioning as there are no error messages displayed and the div containing it disappears unexpectedly

I'm having an issue with Owl carousel. I've included the necessary owl.carousel.css, owl.carousel.js, and owl.theme.css files. Created a div with the class "owl-carousel", and called the function $(".owl-carousel").owlCarousel();. However, after ...

What could be the reason for Object.assign failing to update a key in my new object?

Function handleSave @bind private handleSave() { const { coin, balance } = this.state; console.log('coin', coin); console.log('balance', balance); const updatedCoin = Object.assign({ ...coin, position: balance }, coi ...