tiktok-live-connector
Advanced tools
Comparing version 0.9.26 to 0.9.27
@@ -133,2 +133,3 @@ "use strict"; | ||
* @param {boolean} [options[].enableWebsocketUpgrade=true] Use WebSocket instead of request polling if TikTok offers it | ||
* @param {boolean} [options[].enableRequestPolling=true] Use request polling if no WebSocket upgrade is offered. If `false` an exception will be thrown if TikTok does not offer a WebSocket upgrade. | ||
* @param {number} [options[].requestPollingIntervalMs=1000] Request polling interval if WebSocket is not used | ||
@@ -273,7 +274,19 @@ * @param {string} [options[].sessionId=null] The session ID from the "sessionid" cookie is required if you want to send automated messages in the chat. | ||
_classPrivateFieldSet(this, _isConnected, true); // Sometimes no upgrade to websocket is offered by TikTok | ||
// In that case we use request polling | ||
_classPrivateFieldSet(this, _isConnected, true); // 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).'); | ||
} | ||
if (!_classPrivateFieldGet(this, _options).sessionId) { | ||
// We cannot use request polling if the user has no sessionid defined. | ||
// The reason for this is that TikTok needs a valid signature if the user is not logged in. | ||
// Signing a request every second would generate too much traffic to the signing server. | ||
// 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.'); | ||
} | ||
_classPrivateMethodGet(this, _startFetchRoomPolling, _startFetchRoomPolling2).call(this); | ||
@@ -453,2 +466,3 @@ } | ||
enableWebsocketUpgrade: true, | ||
enableRequestPolling: true, | ||
requestPollingIntervalMs: 1000, | ||
@@ -519,3 +533,3 @@ sessionId: null, | ||
try { | ||
await _classPrivateMethodGet(this, _fetchRoomData, _fetchRoomData2).call(this); | ||
await _classPrivateMethodGet(this, _fetchRoomData, _fetchRoomData2).call(this, false); | ||
} catch (err) { | ||
@@ -533,4 +547,8 @@ _classPrivateMethodGet(this, _handleError, _handleError2).call(this, err, 'Error while fetching webcast data via request polling'); | ||
if (isInitial && !webcastResponse.cursor) { | ||
throw new Error('Missing cursor in initial fetch response.'); | ||
if (!webcastResponse.cursor) { | ||
if (isInitial) { | ||
throw new Error('Missing cursor in initial fetch response.'); | ||
} else { | ||
_classPrivateMethodGet(this, _handleError, _handleError2).call(this, null, 'Missing cursor in fetch response.'); | ||
} | ||
} // Set cursor and internal_ext param to continue with the next request | ||
@@ -546,7 +564,2 @@ | ||
await _classPrivateMethodGet(this, _tryUpgradeToWebsocket, _tryUpgradeToWebsocket2).call(this, webcastResponse); | ||
} else if (!_classPrivateFieldGet(this, _options).sessionId) { | ||
// we cannot use request polling if the user has no sessionid defined. | ||
// the reason for this is that it would generate too much traffic to the signing server. | ||
// if a sessionid is present a signature is not required. | ||
throw new Error('TikTok does not offer a websocket upgrade or `enableWebsocketUpgrade` disabled. Please provide a valid `sessionId` to use request polling instead.'); | ||
} | ||
@@ -579,3 +592,3 @@ } // Skip processing initial data if option disabled | ||
} catch (err) { | ||
_classPrivateMethodGet(this, _handleError, _handleError2).call(this, err, 'Upgrade to websocket failed. Using request polling...'); | ||
_classPrivateMethodGet(this, _handleError, _handleError2).call(this, err, 'Upgrade to websocket failed'); | ||
} | ||
@@ -598,7 +611,8 @@ } | ||
_classPrivateFieldGet(this, _websocket).on('signingFailed', err => reject(`Websocket url signing failed, ${err}`)); | ||
_classPrivateFieldGet(this, _websocket).on('webcastResponse', msg => _classPrivateMethodGet(this, _processWebcastResponse, _processWebcastResponse2).call(this, msg)); | ||
_classPrivateFieldGet(this, _websocket).on('messageDecodingFailed', err => _classPrivateMethodGet(this, _handleError, _handleError2).call(this, err, 'Websocket message decoding failed')); | ||
_classPrivateFieldGet(this, _websocket).on('messageDecodingFailed', err => _classPrivateMethodGet(this, _handleError, _handleError2).call(this, err, 'Websocket message decoding failed')); // Hard timeout if the WebSocketClient library does not handle connect errors correctly. | ||
setTimeout(() => reject('Websocket not responding'), 30000); | ||
}); | ||
@@ -605,0 +619,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
if (webcastObject.event) { | ||
Object.assign(webcastObject, webcastObject.event); | ||
Object.assign(webcastObject, getEventAttributes(webcastObject.event)); | ||
delete webcastObject.event; | ||
@@ -124,6 +124,7 @@ } | ||
function getUserAttributes(webcastUser) { | ||
var _webcastUser$userId, _webcastUser$profileP, _webcastUser$extraAtt, _userAttributes$userB, _userAttributes$userB2, _userAttributes$userB3; | ||
var _webcastUser$userId, _webcastUser$secUid, _webcastUser$profileP, _webcastUser$extraAtt, _userAttributes$userB, _userAttributes$userB2, _userAttributes$userB3; | ||
let userAttributes = { | ||
userId: (_webcastUser$userId = webcastUser.userId) === null || _webcastUser$userId === void 0 ? void 0 : _webcastUser$userId.toString(), | ||
secUid: (_webcastUser$secUid = webcastUser.secUid) === null || _webcastUser$secUid === void 0 ? void 0 : _webcastUser$secUid.toString(), | ||
uniqueId: webcastUser.uniqueId !== '' ? webcastUser.uniqueId : undefined, | ||
@@ -142,2 +143,8 @@ nickname: webcastUser.nickname !== '' ? webcastUser.nickname : undefined, | ||
function getEventAttributes(event) { | ||
if (event.msgId) event.msgId = event.msgId.toString(); | ||
if (event.createTime) event.createTime = event.createTime.toString(); | ||
return event; | ||
} | ||
function mapBadges(badges) { | ||
@@ -144,0 +151,0 @@ let simplifiedBadges = []; |
{ | ||
"name": "tiktok-live-connector", | ||
"version": "0.9.26", | ||
"version": "0.9.27", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82417
1119