javascriptc#node.jsasp.net-coresimple-peer

require function is not working in Asp.netcore javascript


I tried to implement WebRTC simple-peer video chat application using .net core MVC. But when writing javascript implementation that needs to make peer connection, they have used require("xxx") function and I am getting an error that required is not defined. I know this needs node or requirejs. I have tried installing the node also but it is not working.

 1)let Peer = require('simple-peer');
   let p = new Peer()

can anyone tell me how to load the required function in .netcore MVC project javascript files? (I have also use SignalR)


Solution

  •  var stream;
    
     navigator.mediaDevices.getUserMedia({ video: true, audio: false }, function (stream) {
            stream = stream;
     });
    
    function InitPeer(type) {
                    var peer = new SimplePeer({
                        initiator: (type == 'init') ? true : false,
                        stream: stream,
                        trickle: false
                    });
    

    So I had the issue to create the simple peer object in using standard java script if we use node.js we would be able to create the simple peer object by using reqired()

    var Peer = require('simple-peer');
    

    but I can't use this in standard java script so if I create like this

    var peer = new SimplePeer({
                            initiator: (type == 'init') ? true : false,
                            stream: stream,
                            trickle: false
                        });
    

    stream will give an error telling that stream is not recognize. So to avoid that need to create another variable and assign the streaming inside

     navigator.mediaDevices.getUserMedia({ video: true, audio: false }, function (stream) {
                stream = stream;
         });
    

    So now you can use. This part is important if you are going to implement video chat as we need streaming