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

WebSocket behaves differently and breaks on connection #18046

Open
wfzyx opened this issue Mar 10, 2025 · 1 comment
Open

WebSocket behaves differently and breaks on connection #18046

wfzyx opened this issue Mar 10, 2025 · 1 comment
Labels
bug Something isn't working web:websocket

Comments

@wfzyx
Copy link

wfzyx commented Mar 10, 2025

What version of Bun is running?

1.2.4+fd9a5ea66

What platform is your computer?

Linux 6.12.13-200.fc41.x86_64 x86_64 unknown

What steps can reproduce the bug?

  • bun add tiktok-live-connector
  • Use the attached minimal example
  • try running the script as bun run script.ts
import { WebcastPushConnection } from "tiktok-live-connector";
const tiktokUsername = "<insert any currently live TikTok username>";
const tiktokLiveConnection = new WebcastPushConnection(tiktokUsername, {
	enableWebsocketUpgrade: true,
});

tiktokLiveConnection.on("error", (err) => {
	console.error("An error occurred:", err);
});

tiktokLiveConnection.on("streamEnd", () => {
	console.log("Live stream has ended");
});

tiktokLiveConnection.on("disconnected", () => {
	console.log("Disconnected from the live stream");
});

tiktokLiveConnection.on("chat", (data) => {
	console.log(`Chat: ${data.uniqueId} says: ${data.comment}`);
});

tiktokLiveConnection
	.connect()
	.then((state) => {
		console.log(`Connected to roomId ${state.roomId}`);
	})
	.catch((err) => {
		console.error("Failed to connect", err);
	});

What is the expected behavior?

When running with bunx deno script.ts, or using wscat to connect to the websocket, it works fine;

What do you see instead?

The server answers that there is no option to upgrade to a websocket

Additional information

No response

@wfzyx wfzyx added bug Something isn't working needs triage labels Mar 10, 2025
@wfzyx
Copy link
Author

wfzyx commented Mar 11, 2025

I've investigated a bit more; The server answers with 1002 - CLOSE_PROTOCOL_ERROR

I believe the issue lays on buildRequestBody at bun/src/http/websocket_http_client.zig

I'm trying to troubleshoot the root cause

EDIT:

The issue is reproducible by dumping the websocket url and headers to console, writing a manual connection, and quitting the headers;

const url = '...'
const headers = {...}
const ws = new WebSocket(url, { headers }); // returns 1000
const ws2 = new WebSocket(url); // returns 1002

EDIT2:

The listed library uses https://www.npmjs.com/package/websocket - which by default doesn't use W3C implementation;
So I'm guessing that the polyfill isn't fully working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web:websocket
Projects
None yet
Development

No branches or pull requests

2 participants