Skip to content

Commit

Permalink
fix websocket upgrade error
Browse files Browse the repository at this point in the history
Fix "TikTok does not offer a websocket upgrade" error due to missing "Sec-Websocket-Protocol" header in response.
  • Loading branch information
zerodytrash committed Mar 13, 2024
1 parent af5d2ee commit 47d18e1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiktok-live-connector",
"version": "1.1.3",
"version": "1.1.4",
"description": "Node.js module to receive live stream chat events like comments and gifts from TikTok LIVE",
"main": "index.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class WebcastPushConnection extends EventEmitter {

async #fetchRoomData(isInitial) {
let webcastResponse = await this.#httpClient.getDeserializedObjectFromWebcastApi('im/fetch/', this.#clientParams, 'WebcastResponse', isInitial);
let upgradeToWsOffered = !!webcastResponse.wsUrl && !!webcastResponse.wsParam;
let upgradeToWsOffered = !!webcastResponse.wsUrl;

if (!webcastResponse.cursor) {
if (isInitial) {
Expand Down Expand Up @@ -438,7 +438,7 @@ class WebcastPushConnection extends EventEmitter {
try {
// Websocket specific params
let wsParams = {
imprp: webcastResponse.wsParam.value,
imprp: webcastResponse.wsParam?.value || '',
compress: 'gzip',
};

Expand Down
5 changes: 3 additions & 2 deletions src/lib/webcastConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
device_platform: 'web',
focus_state: true,
from_page: 'user',
history_len: 4,

This comment has been minimized.

Copy link
@ugurberkecan

ugurberkecan Mar 23, 2024

why u change history_len ?

history_len: 0,
is_fullscreen: false,
is_page_visible: true,
did_rule: 3,
Expand All @@ -30,7 +30,8 @@ module.exports = {
tz_name: 'Europe/Berlin',
referer: 'https://www.tiktok.com/',
root_referer: 'https://www.tiktok.com/',
version_code: 180800,
host: 'https://webcast.tiktok.com',
version_code: 270000,
webcast_sdk_version: '1.3.0',
update_version_code: '1.3.0',
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/webcastWebsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WebcastWebsocket extends websocket.client {
};

this.#handleEvents();
this.connect(this.wsUrlWithParams, 'echo-protocol', Config.TIKTOK_URL_WEBCAST, this.wsHeaders, websocketOptions);
this.connect(this.wsUrlWithParams, '', Config.TIKTOK_URL_WEB, this.wsHeaders, websocketOptions);
}

#handleEvents() {
Expand Down

0 comments on commit 47d18e1

Please sign in to comment.