KeV
KeV

Reputation: 2891

Cordova peer-to-peer app using webRTC

I have to build a cross-platform peer-to-peer application (at least support iOS & Android). For that I am using Cordova. Currently I can do service discovery using the ZeroConf plugin. Now I would want to make a peer-to-peer connection on discovery.

An equivalent app has already been made using Titanium. After discovery, it uses sockets to connect to the discovered machine.

/*
    Service Discovery resulting in an IP address and port number
    ...
*/

socket = Titanium.Network.createTCPSocket({
    hostName: discoveredHostName,
    port: discoveredPort,
    mode: Titanium.Network.READ_WRITE_MODE
});
...
socket.connect();

However, I need to translate the app to Cordova, hence i will need an alternative to those sockets used in the Titanium version. Using an intermediary server is not an option (only for signaling it may be used, not for message exchange).

My mentor advised to use webRTC as it is a simple standard Javascript API, mentioning it works on iOS referring to the official website which metions iOS support. I implemented it, testing it in the browser and it works like a charm.

However, when testing it on iOS webRTC does not work :

var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.msRTCPeerConnection;

This works in the browser, but on iOS this results in RTCPeerConnection being undefined. I presume i am missing something, as the official website mentions iOS support?

Upvotes: 4

Views: 4190

Answers (1)

beaver
beaver

Reputation: 17647

WebRTC is not supported by Safari, both MacOS and iOS:

see http://caniuse.com/#search=webrtc

The article cited (https://webrtc.org/native-code/ios/) refers to a native development on iOS using, I think, a library or an SDK which implements WebRTC API.

Using Cordova Framework you can't rely natively on a WebView WebRTC enabled, but you have to adopt a specific plugin or subtituite the Cordova WebView with Crosswalk (for example).

On iOS a plugin implementing w3c WebRTC APIs is iosrtc, but it has some issues pending and some limitation on video element implementation.

Upvotes: 4

Related Questions