Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiktok-live-connector

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiktok-live-connector - npm Package Compare versions

Comparing version 1.1.9 to 1.2.0

dist/lib/tiktokErrors.d.ts

62

dist/index.js

@@ -47,2 +47,13 @@ "use strict";

const {
AlreadyConnectingError,
AlreadyConnectedError,
UserOfflineError,
NoWSUpgradeError,
InvalidSessionIdError,
InvalidResponseError,
ExtractRoomIdError,
InitialFetchError
} = require('./lib/tiktokErrors');
const ControlEvents = {

@@ -253,7 +264,7 @@ CONNECTED: 'connected',

if (_classPrivateFieldGet(this, _isConnecting)) {
throw new Error('Already connecting!');
throw new AlreadyConnectingError('Already connecting!');
}
if (_classPrivateFieldGet(this, _isConnected)) {
throw new Error('Already connected!');
throw new AlreadyConnectedError('Already connected!');
}

@@ -281,3 +292,3 @@

if (_classPrivateFieldGet(this, _roomInfo).status === 4) {
throw new Error('LIVE has ended');
throw new UserOfflineError('LIVE has ended');
}

@@ -291,8 +302,29 @@ } // Fetch all available gift info if option enabled

await _classPrivateMethodGet(this, _fetchRoomData, _fetchRoomData2).call(this, true); // Sometimes no upgrade to WebSocket is offered by TikTok
try {
await _classPrivateMethodGet(this, _fetchRoomData, _fetchRoomData2).call(this, true);
} catch (ex) {
var _jsonError;
let jsonError;
let retryAfter;
try {
var _ex$response$headers;
jsonError = JSON.parse(ex.response.data.toString());
retryAfter = (_ex$response$headers = ex.response.headers) !== null && _ex$response$headers !== void 0 && _ex$response$headers['retry-after'] ? parseInt(ex.response.headers['retry-after']) : null;
} catch (parseErr) {
throw ex;
}
if (!jsonError) throw ex;
const errorMessage = ((_jsonError = jsonError) === null || _jsonError === void 0 ? void 0 : _jsonError.error) || 'Failed to retrieve the initial room data.';
throw new InitialFetchError(errorMessage, retryAfter);
} // Sometimes no upgrade to WebSocket is offered by TikTok
// In that case we use request polling (if enabled and possible)
if (!_classPrivateFieldGet(this, _isWsUpgradeDone)) {
if (!_classPrivateFieldGet(this, _options).enableRequestPolling) {
throw new Error('TikTok does not offer a websocket upgrade and request polling is disabled (`enableRequestPolling` option).');
throw new NoWSUpgradeError('TikTok does not offer a websocket upgrade and request polling is disabled (`enableRequestPolling` option).');
}

@@ -305,3 +337,3 @@

// If a sessionid is present a signature is not required.
throw new Error('TikTok does not offer a websocket upgrade. Please provide a valid `sessionId` to use request polling instead.');
throw new NoWSUpgradeError('TikTok does not offer a websocket upgrade. Please provide a valid `sessionId` to use request polling instead.');
}

@@ -403,3 +435,3 @@

if (!_classPrivateFieldGet(this, _options).sessionId) {
throw new Error('Missing SessionId. Please provide your current SessionId to use this feature.');
throw new InvalidSessionIdError('Missing SessionId. Please provide your current SessionId to use this feature.');
}

@@ -429,9 +461,9 @@

case 20003:
throw new Error('Your SessionId has expired. Please provide a new one.');
throw new InvalidSessionIdError('Your SessionId has expired. Please provide a new one.');
default:
throw new Error(`TikTok responded with status code ${response === null || response === void 0 ? void 0 : response.status_code}: ${response === null || response === void 0 ? void 0 : (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.message}`);
throw new InvalidResponseError(`TikTok responded with status code ${response === null || response === void 0 ? void 0 : response.status_code}: ${response === null || response === void 0 ? void 0 : (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.message}`, response);
}
} catch (err) {
throw new Error(`Failed to send chat message. ${err.message}`);
throw new InvalidResponseError(`Failed to send chat message. ${err.message}`, err);
}

@@ -534,3 +566,3 @@ }

});
if (roomData.statusCode) throw new Error(`API Error ${roomData.statusCode} (${roomData.message || 'Unknown Error'})`);
if (roomData.statusCode) throw new InvalidResponseError(`API Error ${roomData.statusCode} (${roomData.message || 'Unknown Error'})`, undefined);

@@ -542,3 +574,3 @@ _classPrivateFieldSet(this, _roomId, roomData.data.user.roomId);

} catch (err) {
throw new Error(`Failed to retrieve room_id from page source. ${err.message}`);
throw new ExtractRoomIdError(`Failed to retrieve room_id from page source. ${err.message}`);
}

@@ -553,3 +585,3 @@ }

} catch (err) {
throw new Error(`Failed to fetch room info. ${err.message}`);
throw new InvalidResponseError(`Failed to fetch room info. ${err.message}`, err);
}

@@ -564,3 +596,3 @@ }

} catch (err) {
throw new Error(`Failed to fetch available gifts. ${err.message}`);
throw new InvalidResponseError(`Failed to fetch available gifts. ${err.message}`, err);
}

@@ -591,3 +623,3 @@ }

if (isInitial) {
throw new Error('Missing cursor in initial fetch response.');
throw new InvalidResponseError('Missing cursor in initial fetch response.');
} else {

@@ -594,0 +626,0 @@ _classPrivateMethodGet(this, _handleError, _handleError2).call(this, null, 'Missing cursor in fetch response.');

@@ -13,2 +13,6 @@ "use strict";

const {
SignatureError
} = require('./tiktokErrors');
const axios = require('axios').create({

@@ -77,11 +81,11 @@ timeout: 5000,

if (!signResponse) {
throw signError;
throw new SignatureError(`Failed to sign request: ${signError.message}; URL: ${url}`, signError);
}
if (signResponse.status !== 200) {
throw new Error(`Status Code: ${signResponse.status}`);
throw new SignatureError(`Status Code: ${signResponse.status}`);
}
if (!((_signResponse$data = signResponse.data) !== null && _signResponse$data !== void 0 && _signResponse$data.signedUrl)) {
throw new Error('missing signedUrl property');
throw new SignatureError('missing signedUrl property');
}

@@ -118,3 +122,3 @@

throw new Error(`Failed to sign request: ${error.message}; URL: ${url}`);
throw new SignatureError(`Failed to sign request: ${error.message}; URL: ${url}`);
}

@@ -121,0 +125,0 @@ }

"use strict";
const {
UserOfflineError,
InvalidUniqueIdError
} = require('./tiktokErrors');
let uu = [];

@@ -21,3 +26,3 @@

let validResponse = mainPageHtml.includes('"og:url"');
throw new Error(validResponse ? 'User might be offline.' : 'Your IP or country might be blocked by TikTok.');
throw new UserOfflineError(validResponse ? 'User might be offline.' : 'Your IP or country might be blocked by TikTok.');
}

@@ -27,3 +32,3 @@

if (typeof uniqueId !== 'string') {
throw new Error("Missing or invalid value for 'uniqueId'. Please provide the username from TikTok URL.");
throw new InvalidUniqueIdError("Missing or invalid value for 'uniqueId'. Please provide the username from TikTok URL.");
} // Support full URI

@@ -30,0 +35,0 @@

{
"name": "tiktok-live-connector",
"version": "1.1.9",
"version": "1.2.0",
"description": "Node.js module to receive live stream chat events like comments and gifts from TikTok LIVE",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc