diff options
author | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-02-23 19:34:56 +0100 |
commit | 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch) | |
tree | 75be5fba4368472fb11c8015aee026b2b9a71888 /together/src/types | |
parent | 8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff) | |
download | pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2 pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip |
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'together/src/types')
-rw-r--r-- | together/src/types/Session.ts | 39 | ||||
-rw-r--r-- | together/src/types/User.ts | 44 | ||||
-rw-r--r-- | together/src/types/Video.ts | 41 |
3 files changed, 0 insertions, 124 deletions
diff --git a/together/src/types/Session.ts b/together/src/types/Session.ts deleted file mode 100644 index 5d3e799..0000000 --- a/together/src/types/Session.ts +++ /dev/null @@ -1,39 +0,0 @@ -import {v4 as uuidv4} from 'uuid'; -import User from "./User"; -import Video, {OngoingVideo} from "./Video"; -import {generateParyCode} from "../utils/PartyCodes"; - -export default class Session { - public id: string; - public partyCode: string; - public videoQueue: Video[]; - public currentVideo: OngoingVideo; - public users: User[]; - - constructor() { - this.id = uuidv4(); - this.partyCode = generateParyCode(); - this.videoQueue = []; - this.currentVideo = null; - this.users = []; - } - - update() { - if(this.videoQueue.length === 0) this.currentVideo = null; - else this.currentVideo = (this.videoQueue.shift()).toOngoingVideo(); - - this.users.forEach(user => { - user.ws.send(JSON.stringify({ - "task": "VIDEO_UPDATE", - "payload": { - "url": this.currentVideo.url, - "title": this.currentVideo.title, - "author": this.currentVideo.author, - "thumbnail": this.currentVideo.thumbnail, - "state": this.currentVideo.state, - "position": this.currentVideo.position - } - })) - }); - } -}
\ No newline at end of file diff --git a/together/src/types/User.ts b/together/src/types/User.ts deleted file mode 100644 index 900acb8..0000000 --- a/together/src/types/User.ts +++ /dev/null @@ -1,44 +0,0 @@ -import {WebSocket} from "ws"; -import Video from "./Video"; -import superagent from "superagent"; - -export default class User { - public id: string; - public ws: WebSocket; - public videoPositon: number; - private apiToken: string; - - constructor(ws: WebSocket, apiToken: string) { - this.videoPositon = 0; - this.ws = ws; - this.apiToken = apiToken; - - this.getUserData(); - } - - async getUserData() { - let res = await superagent.get("https://peh-internal.minteck.org/api/me") - .set("Cookie", "PEH2_SESSION_TOKEN=" + this.apiToken) - .send(); - - this.id = res.body["id"]; - } - - async getYoutubeVideo(id: string): Promise<Video> { - let res = await superagent.get("https://peh-internal.minteck.org/api/video?id=" + id) - .set("Cookie", "PEH2_SESSION_TOKEN=" + this.apiToken) - .send(); - - return new Video(id, res.body["title"], res.body["author"], res.body["duration"], res.body["duration_pretty"], res.body["url"], res.body["poster"]); - } - - toAPIUser(): APIUser { - return { - id: this.id - } - } -} - -export interface APIUser { - id: string; -}
\ No newline at end of file diff --git a/together/src/types/Video.ts b/together/src/types/Video.ts deleted file mode 100644 index 9bba13f..0000000 --- a/together/src/types/Video.ts +++ /dev/null @@ -1,41 +0,0 @@ -export default class Video { - public id: string; - public title: string; - public author: string; - public duration: number; - public duration_pretty: string; - public url: string; - public thumbnail: string; - - constructor(id, title, author, duration, duration_pretty, url, thumbnail) { - this.id = id; - this.title = title; - this.author = author; - this.duration = duration; - this.duration_pretty = duration_pretty - this.url = url; - this.thumbnail = thumbnail; - } - - toOngoingVideo() { - return new OngoingVideo(this.id, this.title, this.author, this.duration, this.duration_pretty, this.url, this.thumbnail); - } -} - -export class OngoingVideo extends Video { - public state: VideoState; - public position: number; - - constructor(id, title, author, duration, duration_pretty, url, thumbnail) { - super(id, title, author, duration, duration_pretty, url, thumbnail); - this.state = VideoState.Paused; - this.position = 0; - } -} - -export enum VideoState { - Paused, - Playing, - Buffering, - Loading -}
\ No newline at end of file |