Error using moonlink in deno

I'm trying to update my bot to use moonlink given issues I've been having with other libraries and I get the following error:
error: Uncaught (in promise) SyntaxError: Invalid protocol value
at new WebSocket (ext:deno_websocket/01_websocket.js:207:13)
at Node.connect (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/entities/Node.js:62:23)
at file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:28:18
at Map.forEach (<anonymous>)
at NodeManager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:27:20)
at Manager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/core/Manager.js:52:20)
at initLava (file:///home/blocks/Documents/BIDOME/imports/queue.tsx:436:8)
at file:///home/blocks/Documents/BIDOME/index.ts:152:8
at CommandClient.emit (https://jsr.io/@denosaurs/event/2.0.2/mod.ts:295:7)
at CommandClient.emit (https://jsr.io/@harmony/harmony/2.9.1/src/client/client.ts:419:18
error: Uncaught (in promise) SyntaxError: Invalid protocol value
at new WebSocket (ext:deno_websocket/01_websocket.js:207:13)
at Node.connect (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/entities/Node.js:62:23)
at file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:28:18
at Map.forEach (<anonymous>)
at NodeManager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:27:20)
at Manager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/core/Manager.js:52:20)
at initLava (file:///home/blocks/Documents/BIDOME/imports/queue.tsx:436:8)
at file:///home/blocks/Documents/BIDOME/index.ts:152:8
at CommandClient.emit (https://jsr.io/@denosaurs/event/2.0.2/mod.ts:295:7)
at CommandClient.emit (https://jsr.io/@harmony/harmony/2.9.1/src/client/client.ts:419:18
Any ideas on how to fix it?
20 Replies
Bloxs
BloxsOP•2w ago
I'm using the following code:
export const nodes = new Manager({
nodes: new Array(nodesCount).fill(undefined).map((_, i) => ({
host: Deno.env.get(`LAVALINK_${i + 1}_HOST`)!,
port: parseInt(Deno.env.get(`LAVALINK_${i + 1}_PORT`)!),
password: Deno.env.get(`LAVALINK_${i + 1}_PASSWORD`)!,
secure: Deno.env.get(`LAVALINK_${i + 1}_SECURE`) == "true",
identifier: Deno.env.get(`LAVALINK_${i + 1}_NAME`)!,
retryDelay: 60 * 1000,
})),
options: {
NodeLinkFeatures: true,
clientName: "Bidome/2.0.0"
},
sendPayload: async (guildID: string, payload: unknown) => {
const guild = await client.guilds.resolve(guildID);
if (guild == undefined) return;
const shard = client.shards.get(guild.shardID) as Gateway;
// deno-lint-ignore no-explicit-any
shard.send(JSON.parse(payload as any));
},
});
export const nodes = new Manager({
nodes: new Array(nodesCount).fill(undefined).map((_, i) => ({
host: Deno.env.get(`LAVALINK_${i + 1}_HOST`)!,
port: parseInt(Deno.env.get(`LAVALINK_${i + 1}_PORT`)!),
password: Deno.env.get(`LAVALINK_${i + 1}_PASSWORD`)!,
secure: Deno.env.get(`LAVALINK_${i + 1}_SECURE`) == "true",
identifier: Deno.env.get(`LAVALINK_${i + 1}_NAME`)!,
retryDelay: 60 * 1000,
})),
options: {
NodeLinkFeatures: true,
clientName: "Bidome/2.0.0"
},
sendPayload: async (guildID: string, payload: unknown) => {
const guild = await client.guilds.resolve(guildID);
if (guild == undefined) return;
const shard = client.shards.get(guild.shardID) as Gateway;
// deno-lint-ignore no-explicit-any
shard.send(JSON.parse(payload as any));
},
});
UnschooledGamer
UnschooledGamer•2w ago
Deno's inbuilt Websocket doesn't support headers that's the reason you receive that error. Options you have are: - poly-fill the Global Websocket with some libraries like ws or others. - use an unstable WebSocketStream API refer: https://questions.deno.com/m/1205621973657321534 - Wait for @1Lucas1.apk (better option ig)
Headers for WebSocket client - Deno
I need to connect Deno (as a client) to a WebSocket server that requires custom headers on connection. I can't seem to find any currently supported method to accomplish this since the WebSocket API only allows for the url and protocols parameters. Is there any known best practice to accomplish this?
1Lucas1.apk
1Lucas1.apk•2w ago
I always forget about the stability of Deno and Bun NO STABILITY, COMPATIBILITY
UnschooledGamer
UnschooledGamer•2w ago
Welcome to JS Ecosystem.
1Lucas1.apk
1Lucas1.apk•2w ago
How now for me it's 11h at night Tomorrow morning, I do a search to better understand these problems And I bring a solution And also check the bun
UnschooledGamer
UnschooledGamer•2w ago
It's 8:41 A.M for me and we're in the #help channel
1Lucas1.apk
1Lucas1.apk•2w ago
here is 23:12 Sleep Tomorrow, it is better, I think more clearly, with sleep is very bad Have a good day for you and sorry for the delay of the solution If you want to skip the direct solution of the package, you can find a package on the internet with webSocket working with headers, and put as a global until you do it in the package officially
Bloxs
BloxsOP•2w ago
Global polyfills don't work for my usecase because it breaks the discord api library im using, so unless there's a way I can only pass it to moonlink that doesn't work
1Lucas1.apk
1Lucas1.apk•2w ago
You can do the following import WebSocket from "npm:ws"; globalThis.WebSocket = WebSocket; I'll see how I put it inside the package or just declare I will have to bring him back from the visa
Bloxs
BloxsOP•2w ago
I don't know how the moonlink internals look but maybe a solution to this could be a way to pass in your own websocket client when instanciating the manager for example?
MEE6
MEE6•2w ago
GG @Bloxs, you just advanced to level 1!
Bloxs
BloxsOP•2w ago
then you provide a fix for this + don't add any extra deps I presume you could probably also check for the deno namespace then use WebSocketStream but that feels more patchworky to me
1Lucas1.apk
1Lucas1.apk•2w ago
GitHub
GitHub - Ecliptia/moonlink.js: MoonLink.js is a simple package for ...
MoonLink.js is a simple package for lavalink client, perfect for you to create your discord bot with songs, and very simple and easy to use. - GitHub - Ecliptia/moonlink.js: MoonLink.js is a simpl...
1Lucas1.apk
1Lucas1.apk•2w ago
Try to install by Dev I put WS again Used Nodejs Global Websocket on V22
Bloxs
BloxsOP•2w ago
I know it'll work because I added the global npm import and that worked fine I'll try it out though and see if smth diff happens
1Lucas1.apk
1Lucas1.apk•2w ago
I've done it once, but then I was accused of plagiarism and so I removed from the package, now I make it possible not to do that
Bloxs
BloxsOP•2w ago
Getting accused of plagarism over allowing custom websocket implementations is crazy
1Lucas1.apk
1Lucas1.apk•2w ago
They almost knocked the package because of this, nowadays they will not do that, but I do not do it
Bloxs
BloxsOP•2w ago
I tried it out and it works, interestingly enough it's also giving me faster song load/skip times than when I global polyfill but I assume that's probably just the lava node im using rather than code related
1Lucas1.apk
1Lucas1.apk•2w ago
interesting There's also one thing, I use global fetch, and it might be more efficient than Polly.

Did you find this page helpful?