diff --git a/package-lock.json b/package-lock.json index 6f6ebec..6bd30c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tiktok-live-connector", - "version": "1.1.9", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tiktok-live-connector", - "version": "1.1.9", + "version": "1.2.0", "funding": [ { "type": "Ko-fi", diff --git a/package.json b/package.json index 994d022..741d375 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tiktok-live-connector", - "version": "1.2.0", + "version": "1.2.1", "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", diff --git a/src/index.js b/src/index.js index 091d965..7a8919a 100644 --- a/src/index.js +++ b/src/index.js @@ -8,8 +8,14 @@ const { deserializeMessage, deserializeWebsocketMessage } = require('./lib/webca const Config = require('./lib/webcastConfig.js'); const { - AlreadyConnectingError, AlreadyConnectedError, UserOfflineError, NoWSUpgradeError, - InvalidSessionIdError, InvalidResponseError, ExtractRoomIdError, InitialFetchError + AlreadyConnectingError, + AlreadyConnectedError, + UserOfflineError, + NoWSUpgradeError, + InvalidSessionIdError, + InvalidResponseError, + ExtractRoomIdError, + InitialFetchError, } = require('./lib/tiktokErrors'); const ControlEvents = { @@ -92,7 +98,7 @@ class WebcastPushConnection extends EventEmitter { this.#clientParams = { ...Config.DEFAULT_CLIENT_PARAMS, - ...this.#options.clientParams + ...this.#options.clientParams, }; this.#setUnconnected(); @@ -114,7 +120,7 @@ class WebcastPushConnection extends EventEmitter { websocketHeaders: Config.DEFAULT_REQUEST_HEADERS, requestOptions: {}, websocketOptions: {}, - signProviderOptions: {} + signProviderOptions: {}, }, providedOptions ); @@ -173,7 +179,6 @@ class WebcastPushConnection extends EventEmitter { await this.#fetchAvailableGifts(); } - try { await this.#fetchRoomData(true); } catch (ex) { @@ -182,9 +187,7 @@ class WebcastPushConnection extends EventEmitter { try { jsonError = JSON.parse(ex.response.data.toString()); - retryAfter = ( - ex.response.headers?.['retry-after'] ? parseInt(ex.response.headers['retry-after']) : null - ) + retryAfter = ex.response.headers?.['retry-after'] ? parseInt(ex.response.headers['retry-after']) : null; } catch (parseErr) { throw ex; } @@ -192,8 +195,6 @@ class WebcastPushConnection extends EventEmitter { if (!jsonError) throw ex; const errorMessage = jsonError?.error || 'Failed to retrieve the initial room data.'; throw new InitialFetchError(errorMessage, retryAfter); - - } // Sometimes no upgrade to WebSocket is offered by TikTok diff --git a/src/lib/tiktokErrors.js b/src/lib/tiktokErrors.js index 50cfb9c..7fd57e1 100644 --- a/src/lib/tiktokErrors.js +++ b/src/lib/tiktokErrors.js @@ -1,63 +1,44 @@ class ConnectError extends Error { - constructor(message) { super(message); } } +class InvalidUniqueIdError extends Error {} -class InvalidUniqueIdError extends Error { -} - -class InvalidSessionIdError extends Error { -} - -class ExtractRoomIdError extends Error { -} +class InvalidSessionIdError extends Error {} +class ExtractRoomIdError extends Error {} class InvalidResponseError extends Error { - constructor(message, requestErr = undefined) { super(message); this.name = 'InvalidResponseError'; this.requestErr = requestErr; } - } class SignatureError extends InvalidResponseError { - constructor(message, requestErr = undefined) { super(message, requestErr); this.name = 'SignatureError'; } - } - class InitialFetchError extends ConnectError { - constructor(message, retryAfter) { super(message); this.retryAfter = retryAfter; } - } +class AlreadyConnectingError extends ConnectError {} -class AlreadyConnectingError extends ConnectError { -} +class AlreadyConnectedError extends ConnectError {} -class AlreadyConnectedError extends ConnectError { -} - -class UserOfflineError extends ConnectError { -} - -class NoWSUpgradeError extends ConnectError { -} +class UserOfflineError extends ConnectError {} +class NoWSUpgradeError extends ConnectError {} module.exports = { InitialFetchError, @@ -69,5 +50,5 @@ module.exports = { InvalidSessionIdError, InvalidResponseError, ExtractRoomIdError, - SignatureError + SignatureError, }; diff --git a/src/lib/webcastConfig.js b/src/lib/webcastConfig.js index 0ab9f56..508c6fe 100644 --- a/src/lib/webcastConfig.js +++ b/src/lib/webcastConfig.js @@ -31,7 +31,6 @@ module.exports = { referer: 'https://www.tiktok.com/', root_referer: 'https://www.tiktok.com/', host: 'https://webcast.tiktok.com', - version_code: 270000, webcast_sdk_version: '1.3.0', update_version_code: '1.3.0', },