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

Fix body decoding #91

Merged
merged 1 commit into from
Dec 21, 2022
Merged

Fix body decoding #91

merged 1 commit into from
Dec 21, 2022

Conversation

joaovs2004
Copy link
Contributor

Hello i came across your package today but it wouldn't work no matter what livestream i used, looking a bit onto the code i found out axios was the responsible for this, the response's bodies weren't being decoded correctly and therefore the checks to make sure there was a livestream running weren't working, adding this one line fixed the issue, please test it on your end to make sure it works :^)

This code:

const { LiveChat } = require("youtube-chat");

const liveChat = new LiveChat({channelId: "UCV306eHqgo0LvBf3Mh36AHg"});

// Emit at start of observation chat.
// liveId: string
liveChat.on("start", (liveId) => {
    console.log("start");
});

// Emit at end of observation chat.
// reason: string?
liveChat.on("end", (reason) => {
    console.log("end");
});

// Emit at receive chat.
// chat: ChatItem
liveChat.on("chat", (chatItem) => {
    console.log(chatItem);
})

// Emit when an error occurs
// err: Error or any
liveChat.on("error", (err) => {
    console.log(err);
});

(async () => {
    // Start fetch loop
    const ok = await liveChat.start();
    if (!ok) {
    console.log("Failed to start, check emitted error");
    }
})();

Gave me this error:

$ node main.js

Error: Live Stream was not found
    at getOptionsFromLivePage (.../node_modules/youtube-chat/dist/parser.js:11:15)
    at .../node_modules/youtube-chat/dist/requests.js:41:52
    at Generator.next (<anonymous>)
    at fulfilled (.../node_modules/youtube-chat/dist/requests.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Failed to start, check emitted error

getOptionsFromLivePage was receiving this as data:

@neverclear86 neverclear86 merged commit b8cdc3a into LinaTsukusu:develop Dec 21, 2022
@neverclear86
Copy link
Collaborator

thank you PR!
I'm pretty sure the encoding should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants