Skip to content

.configure() API

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

HTTP Only Toggle

If you would like to disable P2P but keep using the Peer5 analytics, it is possible to use Peer5 as an HTTP Proxy. To enable this feature please call configure with {httpOnly:true}:

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

If, after enabling this feature, you would like to disable it again, please call the same code with {httpOnly:false}. The client will resume using P2P.

Upload Toggle

In some cases it's 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:

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

Re-enabling upload:

1
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.

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

Local IP

By default, most modern browsers don't expose local ip anymore, if you wish to expose it manually in order to enable cross subnets connections you can do it in the following way:

1
window.peer5 && peer5.configure({localIP:'192.168.1.200'});

Note:

This feature can greatly increase P2P offload

Custom Label

Our analytics can be enhanced by adding a custom label to every differnt user session, which in turn will provide you the ability to have more meaningful analysis of the data gathered.

1
window.peer5 && peer5.configure({customLabel: 'marketingDepartment'});

If you wish to pass several parameters you can do as well by providing a JSON string.

1
peer5.configure({customLabel:'{"uid":1234,"network":"wifi","office":"NY","building":5,"floor":2}'});

Important notice:

The Custom Label feature only works for Internal Communication customers that have requested this feature, if you believe you could profit from having this enabled, please contact us.

contentIdReplacer

This method allows you to add a js function that will parse the url of a segment and return the digested url without any custom session token (or with session token replaced).

1
2
3
4
5
6
window.peer5 
&& peer5.configure({
 contentIdReplacer: function replacer(url) {
   return url.replace(/\d.*\d/, 'abcdefg');
 }
});

The following is an example of the client behaviour with this contentIdReplacer configured

1
2
3
4
5
<!-- URL to be replaced -->
https://example.com/hls/1sometoken2/segment001.ts

<!-- Resulting URL -->
https://example.com/hls/abcdefg/segment001.ts

More info is available in our url-tokenization page.