Skip to content
Snippets Groups Projects
Commit 192df0a3 authored by Kelvin's avatar Kelvin
Browse files

Prevent dup history broadcasts

parent 14b69948
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,7 @@ class StateHistory {
return getHistoryPosition(url) > duration * 0.7;
}
private var _lastHistoryBroadcast = "";
fun updateHistoryPosition(liveObj: IPlatformVideo, index: DBHistory.Index, updateExisting: Boolean, position: Long = -1L, date: OffsetDateTime? = null, isUserAction: Boolean = false): Long {
val pos = if(position < 0) 0 else position;
val historyVideo = index.obj;
......@@ -82,19 +83,21 @@ class StateHistory {
historyVideo.date = date ?: OffsetDateTime.now();
_historyDBStore.update(index.id!!, historyVideo);
onHistoricVideoChanged.emit(liveObj, pos);
}
if(isUserAction) {
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
if(StateSync.instance.hasAtLeastOneOnlineDevice()) {
Logger.i(TAG, "SyncHistory playback broadcasted (${liveObj.name}: ${position})");
StateSync.instance.broadcastJsonData(
GJSyncOpcodes.syncHistory,
listOf(historyVideo)
);
}
};
val historyBroadcastSig = "${historyVideo.position}${historyVideo.video.id.value ?: historyVideo.video.url}"
if(isUserAction && _lastHistoryBroadcast != historyBroadcastSig) {
_lastHistoryBroadcast = historyBroadcastSig;
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
if(StateSync.instance.hasAtLeastOneOnlineDevice()) {
Logger.i(TAG, "SyncHistory playback broadcasted (${liveObj.name}: ${position})");
StateSync.instance.broadcastJsonData(
GJSyncOpcodes.syncHistory,
listOf(historyVideo)
);
}
};
}
}
return positionBefore;
}
......
Subproject commit 946bc835e18d62a584de7150a05cebea7c832b51
Subproject commit 62e19e2e61ac55ee0d6d836dc1953c5e2b6751b3
Subproject commit e2d896ac45357e85b88a8d1f0a1fc5f4b72bfcfa
Subproject commit f018ca772da6bfc287fa4ef767a4f13c601b52c4
Subproject commit 946bc835e18d62a584de7150a05cebea7c832b51
Subproject commit 62e19e2e61ac55ee0d6d836dc1953c5e2b6751b3
Subproject commit e2d896ac45357e85b88a8d1f0a1fc5f4b72bfcfa
Subproject commit f018ca772da6bfc287fa4ef767a4f13c601b52c4
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment