aboutsummaryrefslogtreecommitdiff
path: root/jellyfin_apiclient_python/keepalive.py
blob: 7d9e40e60012b72cc9d998d57667bdfa0e61aa7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import threading

class KeepAlive(threading.Thread):
    def __init__(self, timeout, ws):
        self.halt           = threading.Event()
        self.timeout        = timeout
        self.ws             = ws

        threading.Thread.__init__(self)
    
    def stop(self):
        self.halt.set()
        self.join()

    def run(self):
        while not self.halt.is_set():
            if self.halt.wait(self.timeout/2):
                break
            else:
                self.ws.send("KeepAlive")