.init() / .destroy() API¶
Some website are build in an approach called Single Page Application (abbreviated SPA). this methodology avoids page navigation and page refresh in favor of pseudo navigation using the HTML5 History API or through the older hash portion of the url, without actually navigating away from the page. checkout our PWA guide for more information.
When watching multiple videos without navigating and reloading the page, it's possible that a user will be connected to irrelevant peers and will have lower P2P efficiency. To solve this use case peer5 exposes
.destroy() methods that effectively resets Peer5 and allows proper P2P flow on continuous sessions.
When loading Peer5 script it's already initialized so there is no need to call init when loading.
Whenever the user navigated to another section of the SPA or even when switching to a different video,
.destroy() should be called. You may call
peer5.isInitialized() in order to check whether or not Peer5 is currently initialized or not.
NOTE: It's important to call
.destroy() after destroying the player and
.init() before creating the new player instance.
1 2 3
reacting to page/video change:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
React Component Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13