Skip to content

Commit

Permalink
refactor(LiveChat): Only store required video info values (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 9, 2023
1 parent dca61c3 commit 89ee68b
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 89ee68b

Please sign in to comment.