-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91ff5a2
commit cb6688b
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |