sebheron / TikTokLiveSharp

Port of TikTok live library for C#
60 stars 49 forks source link

Unity Package Issue #10

Closed Typhereus closed 2 years ago

Typhereus commented 2 years ago

Can't seem to get this to work on unity using the unity package. Empty project, Unity version 2022.1.4f1. Seems like the event isn't firing. As client.Connected returns true, and the other properties are returning some information. Any help is appreciated, thanks. Only code:

using System.Collections;
using System.Collections.Generic;
using TikTokLiveSharp.Client;
using TikTokLiveSharp.Errors;
using TikTokLiveSharp.Events;
using TikTokLiveSharp.Protobuf;
using UnityEngine;

public class StartLive : MonoBehaviour
{
    private static TikTokLiveClient client;
    public string id = "juicyjcr";

    private void Start()
    {
        client = new TikTokLiveClient(id);
        client.OnCommentRecieved += Client_OnCommentRecieved;
        client.Start(System.Threading.CancellationToken.None, true);
    }
    private void Client_OnCommentRecieved(object sender, WebcastChatMessage e)
    {
        string s = $"{e.User.uniqueId}: {e.Comment}";
        Debug.Log(s);
    }
}
brogrammer1337 commented 2 years ago

I have the same problem.

Must be because TikTok has blocked it today. The code from the other repo with JavaScript only works if you provide a SessionId.

Is there any way to provide a SessionId to the TikTokLiveClient class? I think then it would work again.

sebheron commented 2 years ago

I haven't been keeping up with the other repos. I'll look into this, but I can't guarantee getting it to work.

Typhereus commented 2 years ago

Yeah I've implemented all the events and the only one that is firing is OnConnected. Haven't tried JS but the python repo works just fine. I'd really appreciate unity as I have a ton of game ideas for this xD

MayisGM commented 2 years ago

I haven't been keeping up with the other repos. I'll look into this, but I can't guarantee getting it to work.

Hello, you need to add a few parameters in this constructor:

var client = new TikTokLiveClient(uniqueID);

TikTok Live stream events work now if you add this:

let tiktokChatConnection = new WebcastPushConnection('kingmohehe', {
    requestHeaders: {
        "Cookie": "sessionid=f6324878b8b34dbb8f86f1a2aafe5a0a; ttwid=1%7CLw5aVXrdJshrcdKNG2-zgC617ecDJ2WsxVHMymzZArQ%7C1658320010%7C03913e3ebc15cda442d9164e4f3f426544564573935abce01da09a557fa5130b;",
    },
    websocketHeaders: {
        "Cookie": "sessionid=f6324878b8b34dbb8f86f1a2aafe5a0a; ttwid=1%7CLw5aVXrdJshrcdKNG2-zgC617ecDJ2WsxVHMymzZArQ%7C1658320010%7C03913e3ebc15cda442d9164e4f3f426544564573935abce01da09a557fa5130b;",
    }
});

For reference please check this issue:

https://github.com/zerodytrash/TikTok-Live-Connector/issues/42

After adding this NodeJS started to work again for me.

brogrammer1337 commented 2 years ago

But how can I add the parameters to the constructor of TikTokLiveClient? I can't get this to work. Do I need to add the sessionId in the clientParams?

I tried this:

var clientParams = new Dictionary<string, object>(); clientParams.Add("sessionId", "SESSION_ID"); client = new TikTokLiveClient("TIKTOKUSERNAME", null, new System.TimeSpan(0, 0, 0, 0, 1000), clientParams);

But that didn't work.

Has anyone solved this problem?

brogrammer1337 commented 2 years ago

The NodeJS version is now running again without the need to add a SessionId. Can the problem be solved in this repo here please?

sebheron commented 2 years ago

I haven't been keeping up with the other repos. I'll look into this, but I can't guarantee getting it to work.

Hello, you need to add a few parameters in this constructor:

var client = new TikTokLiveClient(uniqueID);

TikTok Live stream events work now if you add this:

let tiktokChatConnection = new WebcastPushConnection('kingmohehe', {
    requestHeaders: {
        "Cookie": "sessionid=f6324878b8b34dbb8f86f1a2aafe5a0a; ttwid=1%7CLw5aVXrdJshrcdKNG2-zgC617ecDJ2WsxVHMymzZArQ%7C1658320010%7C03913e3ebc15cda442d9164e4f3f426544564573935abce01da09a557fa5130b;",
    },
    websocketHeaders: {
        "Cookie": "sessionid=f6324878b8b34dbb8f86f1a2aafe5a0a; ttwid=1%7CLw5aVXrdJshrcdKNG2-zgC617ecDJ2WsxVHMymzZArQ%7C1658320010%7C03913e3ebc15cda442d9164e4f3f426544564573935abce01da09a557fa5130b;",
    }
});

For reference please check this issue:

zerodytrash/TikTok-Live-Connector#42

After adding this NodeJS started to work again for me.

Nice work, if you make a PR I can test it and merge it in.

brogrammer1337 commented 2 years ago

I don't think he fixed the problem, he just points out that the NodeJS version is working again. It was probably a problem with the signing server.

Can you please make the Unity package work again?

sebheron commented 2 years ago

Recent package update should fix this problem :)