WebRTC on iOS - multiplayer is possible

Discussion and feedback on Construct 2

Post » Mon Jul 20, 2015 9:16 pm

I was told there are more WebRTC apps running on iOS than there are running on Android? And I was wondering if anyone has info about when it may be available for the Chrome or Safari web browser?

Is there a way to make a Construct 2 game that has multiplayer ( using WebRTC ) - that would work on the iOS? Or is it very complicated?

I believe iOS ( an iPhone ) uses apps.. or wants to use apps, instead of using a web browser as a middle ware. And there's lots of self-sustaining apps out there using WebRTC? But there's not support in Chrome or Safari for WebRTC? This is perhaps because browser support isn't irrelevant for many vendors creating apps.

*btw I'm an iPhone newbie, just got my first one. :)
Soulmachine @Soundcloud
B
14
S
2
G
1
Posts: 63
Reputation: 928

Post » Mon Jul 20, 2015 10:30 pm

It's going to be more complicated to get the MP plugin working on IOS than Android.

There is a Cordova/PhoneGap plugin for WebRTC that should be just WebRTC. You will need that plugin for either CocoonJS or PhoneGap. This is not a C2 plugin, so you will be working out side of the C2 environment. Also I'm not sure if any extra tinkering if any is going to be needed.

So the plugin may work out of the box, or the plugin may no. If it does great, it works, not to much of a problem. If the plugin doesn't some one will need to find out what's not working and fix it.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Thu Jul 23, 2015 9:17 am

I'm just with the same problem on iOS. Multiplayer games I'm working on runs smoothly on Android but on iOS is another history.

I'm only been able to make it working on iOS using Bowser, exporting the games to HTML5. Bowser is the only browser on iOS that, to date, supports WebRTC. But Bowser has his pitfalls, is not as competent as Safary or Chrome in terms of funcionallity. But to make Construct 2 multiplayer-games work on iOS is near perfect.

I'm trying to use CocoonJS also. But all my tests have failed and I think that CocoonJS doesn't support WebRTC at all, or his support is not as complete as to make multiplayer-games made with Construct 2 works.

A question: could it be possible to modify the Construct 2 Multiplayer plugin to use that Cordova/PhoneGap plugin for WebRTC @jayderyu just mentioned?
B
6
S
1
Posts: 24
Reputation: 460

Post » Thu Jul 23, 2015 2:14 pm

CocoonJS does not support many features that the entire C2 relies on. CJS does support a lot of the core game elements. Unfortunatly WebRTC and advanced WebAudio are not in that list. Though CJS does support audio their own audio system to at least have good sound to an extent.

The best way to get WebRTC is to find the closest to the WebRTC api standard. there are a few, but I think this one might be the closest.
https://github.com/eface2face/cordova-plugin-iosrtc

Create a plugin that shims( https://en.wikipedia.org/wiki/Shim_(computing) ) C2 use of the webrtc of a browser, to the cordova plugin. The shim puts all the missing functions and references and makes links to the cordova plugin. If the plugin and shim supports all the same functions as what C2 uses. Then you should have WebRTC on IOS.

It's not impossible. It's not even extremely hard. Shims are easy to create. But it is a level of technical knowledge required to use Cordova, some swift, C2 Plugin SDK, and javascript. So it's not a drop and use feature with IOS right now. :(
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Fri Jul 24, 2015 7:41 am

@jayderyu I've been looking to that Cordova plugin (iosrtc). And I've an idea but don't know if it's doable. My technicall knwoledge about Cordova and iOS is not very advanced.

My idea is to "duplicate" the "Multiplayer" plugin of C2 and call it, for example, "Multiplayer2". Then modify "Multiplayer2" to detect if is executing under iOS (think this is trivial) and if in iOS "shim" (or whatever you call it) the RTCPeerConnection functionallity that, if I'm not wrong, is the only function that Multiplayer uses.

From c2mp-peer.js of C2 Multiplayer:

Code: Select all
var RTCPeerConnection = window["RTCPeerConnection"] || window["webkitRTCPeerConnection"] || window["mozRTCPeerConnection"] || window["msRTCPeerConnection"];


I'm planning to add something like this:

Code: Select all
// Just for Cordova apps.
document.addEventListener('deviceready', function () {
  // Just for iOS devices.
  if (window.device.platform === 'iOS') {
    cordova.plugins.iosrtc.registerGlobals();
  }
});


As they say in his documentation:

iosrtc.registerGlobals() also generates window.webkitRTCPeerConnection and navigator.webkitGetUserMedia() for backwards compatibility with WebRTC JavaScript wrappers/adapters that assume browser vendor prefixes ( webkit , moz ) in the underlying WebRTC API.


In theory if I generate for Cordova in C2 and add the Cordova plugin:

Code: Select all
$ cordova plugin add cordova-plugin-iosrtc


Then this should work on iOS.

As I said although I'm veteran programmer I'm not familizarized enough with Cordova internals and C2 plugins. And never have done anything for iOS nativelly, only small hybrid apps with Cordova.

But, do you think this could work?
B
6
S
1
Posts: 24
Reputation: 460

Post » Fri Jul 24, 2015 1:56 pm

I say go for it. I was checking out the source code for iosrtc, and comparing c2mp-peer.js use of WebRTC function calls, and it does look like a number of them already exist. I didn't find any missing functions, but I didn't go over everything with a fine tooth comb either. I say give it a try and find a way to constantly check for errors. Send out a lot of console logs and watch xcode's debugging. See if and where it fails. But I think iosrtc looks viable.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Mon Jul 27, 2015 7:22 am

I'll give it a try. But this will be when I return from my Holidays!!!. :)
B
6
S
1
Posts: 24
Reputation: 460

Post » Sat May 21, 2016 1:03 pm

Hi DID you get this working ?

Would love to get multiplay on ios too work

REGARDS
B
33
S
17
G
11
Posts: 350
Reputation: 8,695

Post » Sat Jul 23, 2016 9:24 am

@flemmig any luck with your multiplay on IOS?
B
11
S
4
Posts: 14
Reputation: 807

Post » Sat Jul 23, 2016 10:41 am

@cliffordwh
Yes - BUT did it with other solution

Used the Photon - plugin and this is running fine in both iOS and Android
B
33
S
17
G
11
Posts: 350
Reputation: 8,695

Next

Return to Construct 2 General

Who is online

Users browsing this forum: David181 and 9 guests