TwitchLib / TwitchLib.Unity

TwitchLib repository representing all code belonging to the implementation of TwitchLib for Unity. Maintained primarily by LuckyNoS7evin.
164 stars 33 forks source link

PubSub stop working after awhile #66

Closed Konichuchu closed 1 year ago

Konichuchu commented 1 year ago

Hi, I have this code :

private void Start()
    {
        // Create new instance of PubSub Client
        _pubSub = new PubSub();

        // Subscribe to Events
        _pubSub.OnWhisper += OnWhisper;
        _pubSub.OnPubSubServiceConnected += OnPubSubServiceConnected;
        _pubSub.OnMessageDeleted  += OnMessageDeleted;
        _pubSub.OnRewardRedeemed += OnRewardRedeemed;

        // Connect
        _pubSub.Connect();
    }
    private void OnPubSubServiceConnected(object sender, System.EventArgs e)
    {
        Debug.Log("PubSubServiceConnected!");

        // On connect listen to Bits evadsent
        // Please note that listening to the whisper events requires the chat_login scope in the OAuth token.
        _pubSub.ListenToWhispers(Secrets.CHANNEL_ID_FROM_OAUTH_TOKEN);
        _pubSub.ListenToRewards(Secrets.CHANNEL_ID_FROM_OAUTH_TOKEN);

        // SendTopics accepts an oauth optionally, which is necessary for some topics, such as bit events.
        _pubSub.SendTopics(Secrets.OAUTH_TOKEN);
    }

It works fine, It does the things I want to but after a random amount of time (it can be 5 minutes or 1hour) it stop working without any error log.

I saw as well that TwitchLib.Unity for PubSub is at version 3.2.3 and TwitchLib.PubSub is at 3.2.5 with a note version : "Includes a fix for the socket reconnect issues" which may be the answer to my problem. Is there a way for you to update it or a way for me to do it ?

Konichuchu commented 1 year ago

Well, I don't have a permanent fix, but if it stop working, it's for 5 min max.

private void Update()
    {
        timer += Time.deltaTime;
        if (timer > 360)
        {
            Deconnection();
            Reconnection();
            timer = 0;
        }
        if (Input.GetKeyDown(KeyCode.F10))
        {
            Deconnection();
            Reconnection();
        }   
    }
public void Deconnection()
    {
        _pubSub.Disconnect();
    }

public void Reconnection()
    {
        _pubSub.Connect();
        _pubSub.ListenToSubscriptions(Secrets.CHANNEL_ID_FROM_OAUTH_TOKEN);
        _pubSub.ListenToRewards(Secrets.CHANNEL_ID_FROM_OAUTH_TOKEN);
        _pubSub.SendTopics(Secrets.OAUTH_TOKEN);
    }