Skip to content

Commit

Permalink
allow specifying roomId when connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash committed Mar 8, 2023
1 parent ef0754d commit 2bc501b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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.0.2",
"version": "1.0.3",
"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
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ class WebcastPushConnection extends EventEmitter {

/**
* Connects to the current live stream room
* @param {string} [roomId] If you want to connect to a specific roomId. Otherwise the current roomId will be retrieved.
* @returns {Promise} Promise that will be resolved when the connection is established.
*/
async connect() {
async connect(roomId = null) {
if (this.#isConnecting) {
throw new Error('Already connecting!');
}
Expand All @@ -140,7 +141,13 @@ class WebcastPushConnection extends EventEmitter {
this.#isConnecting = true;

try {
await this.#retrieveRoomId();
// roomId already specified?
if (roomId) {
this.#roomId = roomId;
this.#clientParams.room_id = roomId;
} else {
await this.#retrieveRoomId();
}

// Fetch room info if option enabled
if (this.#options.fetchRoomInfoOnConnect) {
Expand Down

0 comments on commit 2bc501b

Please sign in to comment.