Search code examples
javascriptwebrtcpeer

window not defined with peer.js


When I run my node server.js it gives me the following error:

/Users/Phil/Desktop/webrtc-core/node_modules/peerjs/lib/adapter.js:1
le, __filename, __dirname) { module.exports.RTCSessionDescription = window.RTC
                                                                    ^
ReferenceError: window is not defined
    at Object.<anonymous> (/Users/Phil/Desktop/webrtc-core/node_modules/peerjs/lib/adapter.js:1:102)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/Phil/Desktop/webrtc-core/node_modules/peerjs/lib/util.js:5:25)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Isn't window defined in the adapter.js file?


Solution

  • From the server, the object window dosnt exist, so you are confusing client code with server code, the nodeJs code is server code.

    For example you can use for example, console.log on bot server/client, but you cannot use alert, on the server side, take a look here, to know which Properties and methods belongs with the object window.