-2

hi, i got this error when i run my local serves, thanks

code html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>

    <label>Your ID:</label><br/>
    <textarea id="yourId"></textarea><br/>
    <label>Other ID:</label><br/>
    <textarea id="otherId"></textarea>
    <button id="connect">connect</button><br/>

    <label>Enter Message:</label><br/>
    <textarea id="yourMessage"></textarea>
    <button id="send">send</button>
    <pre id="messages"></pre>

    <script src="index.js" ></script>
  </body>
</html>

index.js

var getUserMedia = require('getusermedia')

getUserMedia({ video: true, audio: false }, function (err, stream) {
  if (err) return console.error(err)

  var Peer = require('simple-peer')
  console.log("conectar")
  var peer = new Peer({
    initiator: location.hash === '#init',
    trickle: false,
    stream: stream

  })

  peer.on('signal', function (data) {
    document.getElementById('yourId').value = JSON.stringify(data)
    console.log("peer on signal 1")
    console.log(data)

  })

  document.getElementById('connect').addEventListener('click', function () {
    var otherId = JSON.parse(document.getElementById('otherId').value)
    console.log("conectar")
    peer.signal(otherId)
  })

  document.getElementById('send').addEventListener('click', function () {
    var yourMessage = document.getElementById('yourMessage').value
    console.log("getElementById")
    peer.send(yourMessage)
  })

  peer.on('data', function (data) {
    console.log("peer data")
    document.getElementById('messages').textContent += data + '\n'
  })

  peer.on('stream', function (stream) {
    console.log("stream")
    var video = document.createElement('video')
    document.body.appendChild(video)

    video.src = window.URL.createObjectURL(stream)
    video.play()
  })
})

server.js

var https = require('https');
var fs = require('fs');




var options = {
  key: fs.readFileSync('privateKey.key'),
  cert: fs.readFileSync('certificate.crt')
};

var mundo= https.createServer(options, function (req, res) {

  console.log(req.url)



  if(req.url === '/') {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end(fs.readFileSync("./index.html"));
  }

  if(req.url === '/index.js') {
  res.writeHead(200, {'Content-Type': 'application/javascript'});
    res.end(fs.readFileSync("./index.js"));
    };


  if(req.url === '/favicon.ico') {
    res.end(fs.readFileSync("./favicon.ico"));
    };


  res.end();
  console.log("listening to port 8000");

});


mundo.listen(8443);

this is the error

Rahul Sharma
  • 9,534
  • 1
  • 15
  • 37
  • Hello, welcome to Stack overflow. Please look properly when you add the code. Please add the image embed, so people answering to your question doesn't need to open separate window or go outside SOF. Also please be as much specific as possible. In other words - read first How to ask question on stack overflow. – Dominik Bucher Feb 04 '18 at 14:52
  • 1
    @DominikBucher New users cannot embed images. – klutt Feb 04 '18 at 15:50

1 Answers1

0

You are using require in a client side script (in index.js). require is not supported in browsers.

Check here for more information.

Skyler
  • 656
  • 5
  • 14