yocontra / rtc-everywhere

Cross-everything WebRTC mega-project
http://rtc.works
MIT License
651 stars 40 forks source link

Error in Android - self._wrtc.RTCPeerConnection is not a constructor #15

Closed d3b00 closed 6 years ago

d3b00 commented 6 years ago

Works on Windows.

But when I try to run in Android: supported: false error: self._wrtc.RTCPeerConnection is not a constructor both in actual phone and emulator.

yocontra commented 6 years ago

I closed this because it was an empty ticket with just the letter "E" as the title, but you edited it to add info so I'll reopen.

d3b00 commented 6 years ago

Yeah I did that by mistake. What about the issue though, is rtc-everywhere not supported in android?

yocontra commented 6 years ago

@d3b00 Should work fine on android, will look into it. Can you post the code you're using?

d3b00 commented 6 years ago

Node.js is embedded in my android app and whenever I try to create a peer I get this error

yocontra commented 6 years ago

@d3b00 Yep I need to see your code, it sounds like the issue is with the usage and not rtc-everywhere itself.

d3b00 commented 6 years ago

this is my code:

const rtc = require('rtc-everywhere')();
const Peer = require('simple-peer');

console.log(rtc.supported); // prints false on Android and true on Windows

const p1 = new Peer({ wrtc: rtc, initiator: true });

And this is the error: /files/nodejs-project/node_modules/simple-peer/index.js:82 self._pc = new (self._wrtc.RTCPeerConnection)(self.config, self.constraints) ^

TypeError: self._wrtc.RTCPeerConnection is not a constructor at new Peer (/files/nodejs-project/node_modules/simple-peer/index.js:82:14) at Object. (/files/nodejs-project/abc.js:6:12) at Module._compile (module.js:624:30) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) at Function.Module.runMain (module.js:665:10) at startup (bootstrap_node.js:188:16) at bootstrap_node.js:611:3

yocontra commented 6 years ago

@d3b00 If you log the rtc object what does it show?

d3b00 commented 6 years ago

In Android

{ 
      platform: 'node',
      supported: false,
      getUserMedia: [Function],
      RTCPeerConnection: undefined,
      RTCSessionDescription: undefined,
      RTCIceCandidate: undefined,
      attachStream: [Function] 
}

On Windows

{ 
  platform: 'node',
  supported: true,
  getUserMedia: [Function],
  RTCPeerConnection: [Function: RTCPeerConnection],
  RTCSessionDescription: [Function: RTCSessionDescription],
  RTCIceCandidate: [Function: RTCIceCandidate],
  attachStream: [Function] 
}
yocontra commented 6 years ago

This is in an android emulator? Interesting, so it looks like the bug is that its identifying your emulator as node and then failing to load the node library because that is node-specific.

yocontra commented 6 years ago

Is this in cordova or some other framework? What does typeof window log?

d3b00 commented 6 years ago

well but that is the expected behavior. It should be treated like Node. As I said "Node.js is embedded in my android app" and I am running it in that embedded Node.js and all my other files where I have imported other modules like async, md5, etc are working fine so I guess Node.js is correctly configured.

yocontra commented 6 years ago

Ah I see the issue - you need to install the wrtc module. Documented here: https://github.com/contra/rtc-everywhere#other

Let me know if that doesn't work and I'll reopen.

d3b00 commented 6 years ago

wrtc is already installed. I was working with wrtc and simple-peer when I was not using WebRTC on Android but now I need it to work on Android and wrtc only supports x64 architecture that's why I installed rtc-everywhere.

But yeah, wrtc is already installed.

yocontra commented 6 years ago

@d3b00 rtc-everywhere uses wrtc for the webrtc bindings for node. If wrtc directly doesn't work for you then neither will rtc-everywhere - sorry. As far as I know wrtc is the only node binding available.

d3b00 commented 6 years ago

but I think wrtc is not working because it doesn't support Android architecture. Isn't rtc-everywhere specifically built to provide support for incompatible architectures/environments?

yocontra commented 6 years ago

@d3b00 rtc-everywhere exists to provide a nice abstraction/normalization across JS environments (and libraries), so one codebase will work everywhere regardless of the browser or mobile JS framework. Our target was never non-JS apps. If you have issues with node-webrtc not working on your environment you should open a ticket on that repository.

If you're building a native android app you would be better off using the standard java webrtc bindings than embedding node and using rtc-everywhere. I've updated our docs to reflect the limitations of the wrtc module.

d3b00 commented 6 years ago

Well you're probably right, should use java webrtc bindings. thanks for your time tho :+1: