Skip to content

.configure() API

Peer5 has a client-side Javascript API for configuring different parameters of the library.

P2P Toggle

When Peer5 is loaded, it has P2P enabled by default. If, for some reason, you want to disable P2P requests for a given user session, you can do it with the following code:

window.peer5 && peer5.configure({p2p: false});

Any requests made using peer5.Request after disabling P2P will use XMLHttpRequest to fetch the file from the HTTP server.

To re-enable P2P requests, you need to call configure with {p2p:true}:

window.peer5 && peer5.configure({p2p: true});

Any requests made using peer5.Request after enabling P2P will fully utilize the Peer5 mesh network.

Upload Toggle

In some cases its required that P2P is used only for downloading without uploading. Upload is on by default for all non-cellular network users.
Disabling P2P upload manually can be achieved like so:

window.peer5 && peer5.configure({upload: false});

Re-enabling upload:

window.peer5 && peer5.configure({upload: true});

Group id / name

By default Peer5 groups all users watching the same stream together. All users within a certain group can only share with users from that same group.

If you want to split the default group in to sub groups, you can use this API which will mark a specific user as part of a group with the name of your choosing.

This can be helpful for situations where you want to limit sharing between specific networks, offices, etc.

window.peer5 && peer5.configure({group: 'group-1'});