informa
/
2 MIN READ
Blogs

Multipeer Connectivity Plugin for Cordova

As you may remember, one of the downsides of the Multipeer Connectivity was that there was no Cordova implementation available. Well, not anymore.

Originally posted on the cownado.com blog.


As you may remember, one of the downsides of the Multipeer Connectivity was that there was no Cordova implementation available. Well, not anymore.

Today I just released cordova-plugin-networking-multipeer, which allows you to connect multiple iOS devices regardless of network availabiltiy, and send and receive data between them, all from a Cordova application.

Unfortunately, the other big problem remains, that is that Multipeer Connectivity is a proprietary technology by Apple, which means that it can be used to connect iOS devices only.

The API is a little different than traditional sockets, so I will try to explain the basic concepts here:

Instead of having a device that acts as a server, and one or more client devices that connect to it, with Multipeer Connectivity there are advertisers and browsers.

An advertiser is a device that makes itself discoverable by advertising a service.

A browser is a device that searches for nearby devices that are advertising a service.

Once the browser has found a device, it sends an invitation.

The advertiser receives the invitation, and in turn can accept or decline. If the invitation is accepted, a connection is made.

In order to know whether the devices are connected, you have to add a listener to the onChangeState event, and wait until the state associated to the other peer is 'Connected'.

I also suggest adding a timeout of, say, 30 seconds on both ends (on the browser set the timeout after inviting the peer, on the advertiser set the timeout after accepting the invitation), after which, if the other peer does not change its state to 'Connected', it means that someting went wrong.

After the peer has changed its state to 'Connected', data can be sent and received as usual.

I deliberately didn't go into the API details, as they are explained in the README at cordova-plugin-networking-multipeer.

If you want to play around, there is also a test application at test-cordova-multipeer.

Of course our next game will implement local multiplayer with Multipeer Connectivity on iOS devices, so stay tuned for more details about it.

Latest Jobs

Treyarch

Playa Vista, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead/ Senior Asset Artist

Treyarch

Playa Vista, Los Angeles, CA, USA
8.22.23
Senior Gameplay Systems Engineer - Treyarch

High Moon Studios

Carlsbad, CA, USA
9.18.23
VFX Artist
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more