zerodytrash / TikTok-Live-Connector

Node.js library to receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
https://discord.gg/2c6kX6g3Pa
MIT License
1.34k stars 279 forks source link

Failed to connect ! #104

Open H30NA1 opened 1 year ago

H30NA1 commented 1 year ago

Why it returned an error at this step and return a weird long link ? Need Help ! Thanks

// Connect to the chat (await can be used as well)
tiktokLiveConnection.connect().then(state => {
    console.info(`Connected to roomId ${state.roomId}`);
}).catch(err => {
    console.error('Failed to connect', err);
})

Error message: Failed to sign request: timeout of 5000ms exceeded; URL: _https://webcast.tiktok.com/webcast/im/fetch/?aid=1988&app_language=en-US&app_name=tiktok_web&browser_language=en&browser_name=Mozilla&browser_online=true&browser_platform=Win32&browser_version=5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F106.0.0.0+Safari%2F537.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&last_rtt=0&live_id=12&resp_content_type=protobuf&screen_height=1152&screen_width=2048&tz_name=Europe%2FBerlin&referer=https%3A%2F%2Fwww.tiktok.com%2F&root_referer=https%3A%2F%2Fwww.tiktok.com%2F&version_code=180800&webcast_sdk_version=1.3.0&update_version_code=1.3.0&room_id=7218108758063336218_

My full code:

exports.getLiveComments = async function (req, res) {
  try {
    // Retrieve video ID from request parameters
    let username = req.params.userId;
    // Username of someone who is currently live

    // Create a new wrapper object and pass the username
    let liveStream = new WebcastPushConnection(username, {
      processInitialData: true,
      enableWebsocketUpgrade: true,
      requestPollingIntervalMs: 2000,
      requestOptions: {
        timeout: 10000,
      },
      websocketOptions: {
        timeout: 10000,
      },
    });

    // Connect to the chat (await can be used as well)
    liveStream
      .connect()
      .then((state) => {
        console.info(`Connected to roomId ${state.roomId}`);
      })
      .catch((err) => {
        res.status(500).send(err.message);
      });

    // Define the events that you want to handle
    // In this case we listen to chat messages (comments)
    liveStream.on("chat", (data) => {
      console.log(
        `${data.uniqueId} (userId:${data.userId}) writes: ${data.comment}`
      );
    });
  } catch (error) {
    console.log(error.message);
    res.status(500).send(error.message);
  }
};

Note: Sorry for my lack of English

H30NA1 commented 1 year ago

Now i'm getting a new error. What should i do ?

Note: Don't know why but that error from yesterday magically disappeared. Now i can't re-produced it.

Error: Error: Failed to fetch room info. timeout of 10000ms exceeded

Had tried: increase 10000 to 50000 and then it's returned another error "socket hang up."

let liveStream = new WebcastPushConnection(username, {
      processInitialData: true,
      enableWebsocketUpgrade: true,
      requestPollingIntervalMs: 2000,
      requestOptions: {
        timeout: 50000,
      },
      websocketOptions: {
        timeout: 50000,
      },
    });
qrq commented 8 months ago

Same problem started in the last two days