Multiplayer plugin and WebRTC on iOS

Discussion and feedback on Construct 2

Post » Fri Oct 09, 2015 11:59 am

Folllowing this thread: viewtopic.php?f=146&t=150315 I've been doing some more tests, to see if the approach to use the cordova plugin "iosrtc" inside Multiplayer plugin is doable.

I've modified the Multiplayer "js" files to include the plugin and all his "stuff" (basically the initialization method to ensure that window.RTCPeerConnection is "implemented"), following the instructions of the "iosrtc" plugin.

Then I've exported my game as Cordova target and created a Cordova project in a Mac with OSX, Cordova and XCode installed, to compile for iOS and test inside the simulator.

But my problem is that the method "C2Multiplayer_IsSupported" is behaving "strange". I've checked why but I'm becoming mad because can't figure it out.

This is a screenshoot of a debugging session using the XCode iPad Simulator inside a Mac with OSX.

Image

As you can see if I call "C2Multiplayer_IsSupported" it returns "false".

But calling the "expression" alone it returns "true"!!!

Can anybody explain me why?
B
6
S
1
Posts: 24
Reputation: 460

Post » Sat Oct 10, 2015 10:37 am

It's probably because the C2Multiplayer_IsSupported function's use of RTCPeerConnection refers to a variable in its closure, not a global variable.
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Post » Tue Oct 13, 2015 2:54 pm

Thanks @Ashley. Don't know what do you mean exactly because I've not digged into all the source code of Multiplayer plugin. That's something beyond my scope and knowdledge.

Anyway... I'm "throwing the towel". Desist to make the Multiplayer plugin run on iOS.

Now using Photon plugin. It runs ok on iOS in our first testing.

Just a shame that iOS doesn't supports WebRTC natively. In my opinion that's something that could "hurt" the adoption of Construct 2 to some people.
B
6
S
1
Posts: 24
Reputation: 460

Post » Tue Oct 13, 2015 9:49 pm

@jsj
Since your just testing. May I suggest just overwriting the validity check for is supported. I wouldn't do this in the long run. I would also suggest just console.log() each of the checks in the return line. Just to see which one is failing the whole line.

But for starters just force
C2Multiplayer_IsSupported
{
console.log("RTC Peer: " + RTCPeerConnection );
console.log("ArrayBuffer: " + ArrayBuffer !== "undefined" );
console.log("DataView is defined:" + typeof DataView !== "undefined" );

// return RTCPeerConnection && ArrayBugger !== "undefined" && typeof DataView !== "undefined";
return true;
}


ArrayBuffer does exist
https://developer.mozilla.org/en-US/doc ... rrayBuffer

DataView seems to exist too
https://developer.mozilla.org/en-US/doc ... s/DataView


My Guess is the RTCPeer library isn't accessible when it's wanted.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Fri Nov 20, 2015 7:27 pm

I got it to work. With all functionality from the c2 multiplayer.

No shimming required, apart from some adaptions.

Just keep in mind the cordova library already contains everything required ... so after exporting you are required to take some bits out of the c2 plugin and change the intitiation to use the cordova lib.

RTCPeerconnection and RTCSessionDescription and RTCIcecandidate are already handled by the iosrtc plugin. So remove those definitions in c2mp.js and c2mp-peer.js.

Also add cordova.plugins.iosrtc. to the initiator:


c2mp-peer.js

this:
this.pc = new RTCPeerConnection({"ICe etc etc etc

to:
this.pc = new cordova.plugins.iosrtc.RTCPeerConnection({"ICe etc etc etc

and voila, all work out of the box, even the IsSUpported :)

Performance is a bitch though
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sat Nov 21, 2015 10:24 am

@Ashley: this seems cool. Can you integrate it directly in the export?
B
33
S
4
Posts: 57
Reputation: 1,575

Post » Sat Nov 21, 2015 7:08 pm

Gianmichele wrote:@Ashley: this seems cool. Can you integrate it directly in the export?


Not sure that is smart to trial yet.


lennaert wrote:Performance is a bitch though


This was an understatement.



The iosrtc plugin bogs down the cpu, causing low fps to just a couple, and causing timeouts in the c2mp, making it drop connections and the iOS client not even able to process all the incoming data. (which in my test was relatively small and using an ipad3)


I have been tampering with the cordova-plugin-webrtc too, which has lots of similarities to the cordova-plugin-iosrtc, but seems to work a lot smoother ... sadly, only half of the functionality .... seems the DataChannel binary stuff is not implemented.

I am relatively new to Mac os development, but if there is someone here on scirra who's a bit more acquainted with the OSX and the debugging tools accompanied with xcode, then please team up with me for a bit, and we'll nail this puppy.


ATM I am trying to rebuild the library, seeing if some other build parameters might favor the outcome.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Nov 23, 2015 11:24 am

This is why we avoid relying on any third-party non-browser implementations of browser features. They're always buggy, incomplete or have other major drawbacks like poor performance. Basically unless the library advertises that it passes a comprehensive standards-compliant test suite, it's probably useless. If anyone finds something that actually works smoothly we could think about supporting it more directly, but if not I think it would be better to wait until Apple add built-in support (which rumour has it they are working on).
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Post » Tue Nov 24, 2015 2:20 pm

Ashley wrote:This is why we avoid relying on any third-party non-browser implementations of browser features. They're always buggy, incomplete or have other major drawbacks like poor performance. Basically unless the library advertises that it passes a comprehensive standards-compliant test suite, it's probably useless. If anyone finds something that actually works smoothly we could think about supporting it more directly, but if not I think it would be better to wait until Apple add built-in support (which rumour has it they are working on).




I have boiled the performance problems down to an implementation problem:

Host, chrome on windows
Peer, chrome on windows
Peer IOS app


I made a test app to track whats happening as my OSX skills are rather poor.

Now I found that the chrome < = > chrome as expected, flawless

but the ios < = >chrome is doing something I can not explain atm


It seem, that the IOS app is sending out like between 2 ,and 4 packages, with something between 250 and 300 bandwidth OUT

but on the chrome end it is receiving 10 to 15 packages, with over 500k of bandwidth .... IN

And this only happens when the IOS is connected.

Also, in the console I see a lot of dropped packages NOT containing the magic number.


So, somewhere in the implementation I am guessing the wrong Send commands are being used, or even double.


I think that if we can get this sorted, it will work as desired. But my skills in RTC are meager.


@Ashley

If you I send you the WEBRTC.js file created on on my system, would you mind laying it next to your c2m-* .js files and see where the snag occurs/happens ?

Something tells me you might be able to sort it a lot quicker then I can.


Because, the slowness only occurs when it sending data.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Nov 24, 2015 5:01 pm

No, I do not want to get dragged in to debugging somebody else's poor-quality non-standards-compliant WebRTC code.
Scirra Founder
B
399
S
236
G
89
Posts: 24,546
Reputation: 195,436

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests