diff --git a/src/modules/stream/stream.ts b/src/modules/stream/stream.ts index f123d7c..82326ba 100644 --- a/src/modules/stream/stream.ts +++ b/src/modules/stream/stream.ts @@ -1,8 +1,7 @@ -import { GetPlayerOptions, GetMetadata, GetLastMessages } from '../../services/rest.service'; +import { GetMetadata, GetLastMessages } from '../../services/rest.service'; import { timeout } from '../../utils/async.utils'; import { from, Subscription } from '@reactivex/rxjs/dist/package'; import { Metadata } from '../../types/metadata.types'; -import { PlayerOptions } from '../../types/playeroptions.types'; import { ChatResponse } from '../../types/chat.types'; import { OpenWebsocketConnection } from '../../services/websocket.service'; @@ -10,7 +9,8 @@ export class StreamManager { private readonly username: string = ''; private serviceStarted: boolean = false; private metadata?: Metadata = undefined; // https://api.vkplay.live/v1/blog//public_video_stream?from=layer - private playerOptions?: PlayerOptions = undefined; // https://ok.ru/videoembed/?sig=&uid=&t=&cip=&ua=>&promo=boosty + // todo: looks like it is deprecated, need to check + // private playerOptions?: PlayerOptions = undefined; // https://ok.ru/videoembed/?sig=&uid=&t=&cip=&ua=>&promo=boosty private subscription: Subscription; public constructor(username: string, immediateStart: boolean = true) { @@ -25,7 +25,8 @@ export class StreamManager { public async start() { this.serviceStarted = true; this.metadata = await GetMetadata(this.username, this.metadata); - this.playerOptions = await GetPlayerOptions(this.username, this.metadata?.data?.[0]?.url); + // todo: looks like it is deprecated, need to check + // this.playerOptions = await GetPlayerOptions(this.username, this.metadata?.data?.[0]?.url); } public stop() { @@ -48,17 +49,18 @@ export class StreamManager { return null; } - public async GetPlayerOptions(failCount: number = 10): Promise { - for (let fails = 0; fails < failCount; fails++) { - if (this.playerOptions) { - return this.playerOptions; - } - - await timeout(200); - } - - return null; - } + // todo: looks like it is deprecated, need to check + // public async GetPlayerOptions(failCount: number = 10): Promise { + // for (let fails = 0; fails < failCount; fails++) { + // if (this.playerOptions) { + // return this.playerOptions; + // } + // + // await timeout(200); + // } + // + // return null; + // } public async GetLastMessages(limit: number = 20): Promise { return GetLastMessages(this.username, limit); diff --git a/src/services/rest.service.ts b/src/services/rest.service.ts index c1aa3a5..cfd9fb7 100644 --- a/src/services/rest.service.ts +++ b/src/services/rest.service.ts @@ -20,33 +20,34 @@ export const GetMetadata = async (username: string, metadata?: Metadata): Promis ); }; -export const GetPlayerOptions = async ( - username?: string, - url?: string -): Promise => { - if (!url || !username) { - console.error(new Error('url for getting player options is incorrect')); - return; - } - - return axios - .get(url, { - headers: { - ...GetAdditionalHeaders(username) - } - }) - .then(response => { - const regexp = /data-options="([^"]+)"/gm; - const result: any = JSON.parse(decode(regexp.exec(response.data)?.[1] ?? '{}')); - - // hack for stringified vars - if (result?.flashvars?.metadata) { - result.flashvars.metadata = JSON.parse(result.flashvars.metadata); - } - - return result; - }); -}; +// todo: looks like it is deprecated, need to check +// export const GetPlayerOptions = async ( +// username?: string, +// url?: string +// ): Promise => { +// if (!url || !username) { +// console.error(new Error('url for getting player options is incorrect')); +// return; +// } +// +// return axios +// .get(url, { +// headers: { +// ...GetAdditionalHeaders(username) +// } +// }) +// .then(response => { +// const regexp = /data-options="([^"]+)"/gm; +// const result: any = JSON.parse(decode(regexp.exec(response.data)?.[1] ?? '{}')); +// +// // hack for stringified vars +// if (result?.flashvars?.metadata) { +// result.flashvars.metadata = JSON.parse(result.flashvars.metadata); +// } +// +// return result; +// }); +// }; export const GetAppConfig = (username: string): Promise => { return axios diff --git a/src/unofficial-vk-play-live-api.ts b/src/unofficial-vk-play-live-api.ts index 0575f57..11c405e 100644 --- a/src/unofficial-vk-play-live-api.ts +++ b/src/unofficial-vk-play-live-api.ts @@ -6,7 +6,7 @@ import { StreamManager } from './modules/stream/stream'; export default class VKPLAPI { - public static GetStreamManager(username: string) { - return new StreamManager(username); + public static GetStreamManager(username: string, immediateStart: boolean = true) { + return new StreamManager(username, immediateStart); } } diff --git a/test/unofficial-vk-play-live-api.test.ts b/test/unofficial-vk-play-live-api.test.ts index 9bfaab4..c0795f3 100644 --- a/test/unofficial-vk-play-live-api.test.ts +++ b/test/unofficial-vk-play-live-api.test.ts @@ -14,7 +14,7 @@ import VKPLAPI from '../src/unofficial-vk-play-live-api'; * Dummy test */ describe('Dummy test', () => { - const streamManager = VKPLAPI.GetStreamManager('terablade'); + const streamManager = VKPLAPI.GetStreamManager('bezzdar'); it('Root class is instantiable', () => { expect(new VKPLAPI()).toBeInstanceOf(VKPLAPI); @@ -27,12 +27,13 @@ describe('Dummy test', () => { // expect(fieldsAreMatchingWithType(metadata, keyof)).toBeTruthy(); }); - it('PlayerOptions must come from server', async () => { - const playerOptions = await streamManager.GetPlayerOptions(); - expect(playerOptions).not.toBeNull(); - // todo: fix and enable check - // expect(fieldsAreMatchingWithType(playerOptions, PlayerOptions)).toBeTruthy(); - }); + // todo: looks like it is deprecated, need to check + // it('PlayerOptions must come from server', async () => { + // const playerOptions = await streamManager.GetPlayerOptions(); + // expect(playerOptions).not.toBeNull(); + // // todo: fix and enable check + // // expect(fieldsAreMatchingWithType(playerOptions, PlayerOptions)).toBeTruthy(); + // }); it('Chat messages must come from server', async () => { const playerOptions = await streamManager.GetLastMessages();