Skip to content

Commit

Permalink
Add the P2p object
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienCozeDev committed Dec 15, 2023
1 parent 91ff5a2 commit cb6688b
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions pod/peer_to_peer/static/peer_to_peer/js/p2p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class P2p {

/**
* Video identifier for the current session.
*
* @type {string}
*
* @default undefined
*/
videoSlug;



/**
* List of URLs related to the video.
*
* @type {Array}
*
* @default []
*/
urlList = [];



/**
* Peer object for peer-to-peer communication.
*
* @type {Peer}
*
* @default undefined // TODO Update this ?
*/
peer;



/**
* Flag indicating whether it's the first time performing an action.
*
* @type {boolean}
*
* @default false
*/
firstTime = false;



constructor(videoSlug) {
this.videoSlug = videoSlug;
}



/**
* Retrieves peer identifiers associated with the current video.
* @async
* @returns {Array} - A list of peer identifiers.
*/
async getIds() {
let idList = [];
let postData = {
'url': this.videoSlug,
};
await fetch('http://localhost:9090/peer-to-peer/get-ids/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(postData),
}).then(response => response.json())
.then(response => {
idList = [].concat(response);
})
.catch(err => console.error(err));
return idList;
}



// TODO Add the other functions
}

0 comments on commit cb6688b

Please sign in to comment.