mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 06:00:51 -07:00
Hack things to make sure we know what is going on when clients don't send a stop event.
This commit is contained in:
parent
74e8d7d329
commit
9fdcc93e2e
2 changed files with 34 additions and 16 deletions
|
@ -395,7 +395,7 @@ available_notification_agents = notifiers.available_notification_agents()
|
|||
<label>
|
||||
<input type="checkbox" id="monitoring_use_websocket" name="monitoring_use_websocket" value="1" ${config['monitoring_use_websocket']}> Use Websocket (requires restart)
|
||||
</label>
|
||||
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental.</p>
|
||||
<p class="help-block">Instead of polling the server at regular intervals let the server tell us when something happens. This is currently experimental. Encrypted websocket is not currently supported.</p>
|
||||
</div>
|
||||
|
||||
<div class="padded-header">
|
||||
|
|
|
@ -23,6 +23,7 @@ class ActivityHandler(object):
|
|||
|
||||
def __init__(self, timeline):
|
||||
self.timeline = timeline
|
||||
# print timeline
|
||||
|
||||
def is_valid_session(self):
|
||||
if 'sessionKey' in self.timeline:
|
||||
|
@ -63,7 +64,7 @@ class ActivityHandler(object):
|
|||
# Write the new session to our temp session table
|
||||
self.update_db_session()
|
||||
|
||||
def on_stop(self):
|
||||
def on_stop(self, force_stop=False):
|
||||
if self.is_valid_session():
|
||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has stopped." % str(self.get_session_key()))
|
||||
|
||||
|
@ -72,6 +73,8 @@ class ActivityHandler(object):
|
|||
ap.set_session_last_paused(session_key=self.get_session_key(), timestamp=None)
|
||||
|
||||
# Update the session state and viewOffset
|
||||
# Set force_stop to true to disable the state set
|
||||
if not force_stop:
|
||||
ap.set_session_state(session_key=self.get_session_key(),
|
||||
state=self.timeline['state'],
|
||||
view_offset=self.timeline['viewOffset'])
|
||||
|
@ -110,7 +113,7 @@ class ActivityHandler(object):
|
|||
threading.Thread(target=notification_handler.notify,
|
||||
kwargs=dict(stream_data=db_session, notify_action='pause')).start()
|
||||
|
||||
def on_resume(self, time_line=None):
|
||||
def on_resume(self):
|
||||
if self.is_valid_session():
|
||||
logger.debug(u"PlexPy ActivityHandler :: Session %s has been resumed." % str(self.get_session_key()))
|
||||
|
||||
|
@ -171,7 +174,16 @@ class ActivityHandler(object):
|
|||
if db_session:
|
||||
this_state = self.timeline['state']
|
||||
last_state = db_session['state']
|
||||
this_key = str(self.timeline['ratingKey'])
|
||||
last_key = str(db_session['rating_key'])
|
||||
|
||||
# Make sure the same item is being played
|
||||
if this_key == last_key:
|
||||
# Update the session state and viewOffset
|
||||
if this_state == 'playing':
|
||||
ap.set_session_state(session_key=self.get_session_key(),
|
||||
state=this_state,
|
||||
view_offset=self.timeline['viewOffset'])
|
||||
# Start our state checks
|
||||
if this_state != last_state:
|
||||
if this_state == 'paused':
|
||||
|
@ -182,6 +194,12 @@ class ActivityHandler(object):
|
|||
self.on_stop()
|
||||
elif this_state == 'buffering':
|
||||
self.on_buffer()
|
||||
# If a client doesn't register stop events (I'm looking at you PHT!) check if the ratingKey has changed
|
||||
else:
|
||||
# Manually stop and start
|
||||
# Set force_stop so that we don't overwrite our last viewOffset
|
||||
self.on_stop(force_stop=True)
|
||||
self.on_start()
|
||||
|
||||
# Monitor if the stream has reached the watch percentage for notifications
|
||||
# The only purpose of this is for notifications
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue