Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(LiveChat): Only store required video info values #281

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/parser/youtube/LiveChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export interface LiveMetadata {

class LiveChat extends EventEmitter {
#actions: Actions;
#video_info: VideoInfo;
#video_id: string;
#channel_id: string;
#continuation?: string;
#mcontinuation?: string;

Expand All @@ -65,7 +66,8 @@ class LiveChat extends EventEmitter {
constructor(video_info: VideoInfo) {
super();

this.#video_info = video_info;
this.#video_id = video_info.basic_info.id as string;
this.#channel_id = video_info.basic_info.channel_id as string;
this.#actions = video_info.actions;
this.#continuation = video_info.livechat?.continuation || undefined;
this.is_replay = video_info.livechat?.is_replay || false;
Expand Down Expand Up @@ -142,7 +144,7 @@ class LiveChat extends EventEmitter {
const payload: {
videoId: string | undefined;
continuation?: string;
} = { videoId: this.#video_info.basic_info.id };
} = { videoId: this.#video_id };

if (this.#mcontinuation) {
payload.continuation = this.#mcontinuation;
Expand Down Expand Up @@ -175,7 +177,7 @@ class LiveChat extends EventEmitter {
*/
async sendMessage(text: string): Promise<ObservedArray<AddChatItemAction>> {
const response = await this.#actions.execute('/live_chat/send_message', {
params: Proto.encodeMessageParams(this.#video_info.basic_info.channel_id as string, this.#video_info.basic_info.id as string),
params: Proto.encodeMessageParams(this.#channel_id, this.#video_id),
richMessage: { textSegments: [ { text } ] },
clientMessageId: uuidv4(),
parse: true
Expand Down