Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Error: No valid WebSocket class provided #48

Open
ledlamp opened this issue Nov 25, 2022 · 2 comments
Open

Error: No valid WebSocket class provided #48

ledlamp opened this issue Nov 25, 2022 · 2 comments

Comments

@ledlamp
Copy link

ledlamp commented Nov 25, 2022

my code

import * as Misskey from 'misskey-js';

var TOKEN = "redacted";

var client = new Misskey.api.APIClient({
	origin: "https://misskey.io",
	credential: TOKEN
});

var stream = new Misskey.Stream("https://misskey.io", {token: TOKEN});
var channel = stream.useChannel("homeTimeline");
channel.on("note", note => {
	console.log("note");
});

error

me@g:~/Desktop/c30-translate$ node index.mjs 
/home/me/Desktop/c30-translate/node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:508
            throw Error('No valid WebSocket class provided');
                  ^

Error: No valid WebSocket class provided
    at ReconnectingWebSocket._connect (/home/me/Desktop/c30-translate/node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:508:19)
    at new ReconnectingWebSocket (/home/me/Desktop/c30-translate/node_modules/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:205:14)
    at new Stream (/home/me/Desktop/c30-translate/node_modules/misskey-js/built/streaming.js:39:23)
    at file:///home/me/Desktop/c30-translate/index.mjs:11:14
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.12.1
@ledlamp
Copy link
Author

ledlamp commented Nov 25, 2022

work-around

import WebSocket from "ws";
global.WebSocket = WebSocket;
import * as Misskey from 'misskey-js';

@paihu
Copy link

paihu commented Mar 19, 2023

Pass the WebSocket as an argument to Stream.

var stream = new Misskey.Stream("https://misskey.io", {token: TOKEN}, {WebSocket: WebSocket})

https://github.com/misskey-dev/misskey.js/pull/21/files

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

No branches or pull requests

2 participants