Skip to content

Commit

Permalink
update webcast params
Browse files Browse the repository at this point in the history
tiktok has introduced new url parameters that may be needed soon...
  • Loading branch information
zerodytrash committed Jun 14, 2022
1 parent 3404da0 commit 31e95c1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class WebcastPushConnection extends EventEmitter {
this.#isPollingEnabled = false;
this.#isWsUpgradeDone = false;
this.#clientParams.cursor = '';
this.#clientParams.internal_ext = '';
}

/**
Expand Down Expand Up @@ -294,6 +295,7 @@ class WebcastPushConnection extends EventEmitter {

this.#roomId = roomId;
this.#clientParams.room_id = roomId;
this.#clientParams.msToken = this.#httpClient.cookieJar.getCookieByName('msToken');
} catch (err) {
throw new Error(`Failed to retrieve room_id from page source. ${err.message}`);
}
Expand Down Expand Up @@ -337,10 +339,9 @@ class WebcastPushConnection extends EventEmitter {
let webcastResponse = await this.#httpClient.getDeserializedObjectFromWebcastApi('im/fetch/', this.#clientParams, 'WebcastResponse');
let upgradeToWsOffered = !!webcastResponse.wsUrl && !!webcastResponse.wsParam;

// Set cursor param to continue with the next request
if (webcastResponse.cursor) {
this.#clientParams.cursor = webcastResponse.cursor;
}
// Set cursor and internal_ext param to continue with the next request
if (webcastResponse.cursor) this.#clientParams.cursor = webcastResponse.cursor;
if (webcastResponse.internalExt) this.#clientParams.internal_ext = webcastResponse.internalExt;

// Upgrade to Websocket offered? => Try upgrade
if (!this.#isWsUpgradeDone && this.#options.enableWebsocketUpgrade && upgradeToWsOffered) {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/tiktokCookieJar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class TikTokCookieJar {
}
}

getCookieByName(cookieName) {
return this.cookies[cookieName];
}

getCookieString() {
let cookieString = '';
for (const cookieName in this.cookies) {
Expand Down
15 changes: 13 additions & 2 deletions src/lib/webcastConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ module.exports = {
browser_name: 'Mozilla',
browser_online: true,
browser_platform: 'Win32',
browser_version: '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
browser_version: '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
cookie_enabled: true,
cursor: '',
internal_ext: '',
device_platform: 'web',
focus_state: true,
from_page: 'user',
history_len: 4,
is_fullscreen: false,
is_page_visible: true,
did_rule: 3,
fetch_rule: 1,
identity: 'audience',
Expand All @@ -24,12 +30,17 @@ module.exports = {
screen_height: 1152,
screen_width: 2048,
tz_name: 'Europe/Berlin',
referer: 'https://www.tiktok.com/',
root_referer: 'https://www.tiktok.com/',
msToken: '',
version_code: 180800,
webcast_sdk_version: '1.3.0',
update_version_code: '1.3.0',
},
DEFAULT_REQUEST_HEADERS: {
Connection: 'keep-alive',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36',
Accept: 'text/html,application/json,application/protobuf',
Referer: 'https://www.tiktok.com/',
Origin: 'https://www.tiktok.com',
Expand Down
7 changes: 6 additions & 1 deletion src/proto/tiktokSchema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ syntax = "proto3";
message WebcastResponse {
repeated Message messages = 1;
string cursor = 2;
string ackIds = 5;
int32 fetchInterval = 3;
int64 serverTimestamp = 4;
string internalExt = 5;
int32 fetchType = 6; // ws (1) or polling (2)
WebsocketParam wsParam = 7;
int32 heartbeatDuration = 8;
bool needAck = 9;
string wsUrl = 10;
}

Expand Down

0 comments on commit 31e95c1

Please sign in to comment.