I tried to use the livechat example, which works on 9.4.0. Here's my code:
import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';
import { ChatAction } from 'youtubei.js/dist/src/parser/youtube/LiveChat';
export async function initYoutube() {
const yt = await Innertube.create({cache: new UniversalCache(false), generate_session_locally: true});
const search = await yt.search('Xkonti livestream', {
features: ['live'],
upload_date: 'today',
});
console.log('Searched for items: ', search)
const info = await yt.getInfo(search.videos[0].as(YTNodes.Video).id);
console.log('Selected item: ', search)
const livechat = info.getLiveChat();
livechat.on('chat-update', (action: ChatAction) => {
console.log('Received YT chat update event');
if (action.is(YTNodes.AddChatItemAction)) {
const item = action.as(YTNodes.AddChatItemAction).item;
if (!item)
return console.info('Action did not have an item.', action);
const hours = new Date(item.hasKey('timestamp') ? item.timestamp : Date.now()).toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit'
});
switch (item.type) {
case 'LiveChatTextMessage':
console.info(
`${item.as(YTNodes.LiveChatTextMessage).author?.is_moderator ? '[MOD]' : ''}`,
`${hours} - ${item.as(YTNodes.LiveChatTextMessage).author?.name.toString()}:\n` +
`${item.as(YTNodes.LiveChatTextMessage).message.toString()}\n`
);
break;
case 'LiveChatPaidMessage':
console.info(
`${item.as(YTNodes.LiveChatPaidMessage).author?.is_moderator ? '[MOD]' : ''}`,
`${hours} - ${item.as(YTNodes.LiveChatPaidMessage).author.name.toString()}:\n` +
`${item.as(YTNodes.LiveChatPaidMessage).message.toString()}\n`,
`${item.as(YTNodes.LiveChatPaidMessage).purchase_amount}\n`
);
break;
case 'LiveChatPaidSticker':
console.info(
`${item.as(YTNodes.LiveChatPaidSticker).author?.is_moderator ? '[MOD]' : ''}`,
`${hours} - ${item.as(YTNodes.LiveChatPaidSticker).author.name.toString()}:\n` +
`${item.as(YTNodes.LiveChatPaidSticker).purchase_amount}\n`
);
break;
default:
console.debug(action);
break;
}
}
});
livechat.start();
}
After executing await initYoutube(); the error shows up :(
Failure Logs
1 | (function (entry, fetcher)
^
SyntaxError: Export named 'setGlobalDispatcher' not found in module 'undici'.
1 | (function (entry, fetcher)
^
SyntaxError: Export named 'setGlobalDispatcher' not found in module 'undici'.
Expected behavior
It should work just like it does on 9.4.0.
Current behavior
Currently there are errors.
Version
Default
Anything else?
Runtime: Bun 1.1.13
OS: Windows
WebFramework: Elysia.js
Checklist
[X] I am running the latest version.
[X] I checked the documentation and found no answer.
[X] I have searched the existing issues and made sure this is not a duplicate.
Steps to reproduce
I tried to use the livechat example, which works on 9.4.0. Here's my code:
After executing
await initYoutube();
the error shows up :(Failure Logs
Expected behavior
It should work just like it does on 9.4.0.
Current behavior
Currently there are errors.
Version
Default
Anything else?
Runtime: Bun 1.1.13 OS: Windows WebFramework: Elysia.js
Checklist