Skip to content

Commit

Permalink
Include song status on every packet. This should fix the bug where oc…
Browse files Browse the repository at this point in the history
…casionally a client gets confused about whether a song is going on, and confusion is pretty terrible since it's used for determining whether someone is muted in the video call. Fixes #171
  • Loading branch information
jeffkaufman committed Jan 10, 2021
1 parent f40d495 commit 7d35cde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
8 changes: 2 additions & 6 deletions html/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1426,12 +1426,8 @@ async function start_singing() {
var chats = metadata["chats"] || [];
var delay_seconds = metadata["delay_seconds"];
var server_sample_rate = metadata["server_sample_rate"];
if (metadata["song_start_clock"] != null) {
song_start_clock = metadata["song_start_clock"];
}
if (metadata["song_end_clock"] != null) {
song_end_clock = metadata["song_end_clock"];
}
song_start_clock = metadata["song_start_clock"];
song_end_clock = metadata["song_end_clock"];
var client_read_clock = metadata["client_read_clock"];
var server_bpm = metadata["bpm"];
var server_repeats = metadata["repeats"];
Expand Down
16 changes: 4 additions & 12 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ def __init__(self, userid, name, last_heard_server_clock, delay_samples) -> None
scalar_to_friendly_volume(state.backing_volume))
if state.disable_song_video:
self.send("disableSongVideo", state.disable_song_video)
if state.song_start_clock:
self.send("song_start_clock", state.song_start_clock)
if state.song_end_clock:
self.send("song_end_clock", state.song_end_clock)

def allocate_twilio_token(self):
token = AccessToken(secrets["twilio"]["account_sid"],
Expand Down Expand Up @@ -787,9 +783,6 @@ def handle_special(query_params, server_clock, user=None, client_read_clock=None
state.song_start_clock = server_clock
state.song_end_clock = 0

sendall("song_start_clock", state.song_start_clock)
sendall("song_end_clock", state.song_end_clock)

state.metronome_on = False
if state.bpm and state.bpr and state.repeats:
state.requested_track = METRONOME
Expand All @@ -813,8 +806,6 @@ def handle_special(query_params, server_clock, user=None, client_read_clock=None
else:
state.song_end_clock = server_clock

sendall("song_end_clock", state.song_end_clock)

if query_params.get("clear_events", None):
events.clear()

Expand Down Expand Up @@ -943,7 +934,6 @@ def handle_post(in_data, query_string, print_status, client_address=None) -> Tup
if state.backing_track_index == len(state.backing_track):
# the song has ended, mark it so
state.song_end_clock = clear_index
sendall("song_end_clock", state.song_end_clock)

if clear_samples > 0:
if state.metronome_on:
Expand Down Expand Up @@ -972,6 +962,8 @@ def handle_post(in_data, query_string, print_status, client_address=None) -> Tup
x_audio_metadata = {
"server_clock": server_clock,
"server_sample_rate": SAMPLE_RATE,
"song_end_clock": state.song_end_clock,
"song_start_clock": state.song_start_clock,
"last_request_clock": state.last_request_clock,
"n_connected_users": len(active_users()),
"queue_size": QUEUE_LENGTH / FRAME_SIZE, # in 128-sample frames
Expand Down Expand Up @@ -1037,8 +1029,6 @@ def handle_post(in_data, query_string, print_status, client_address=None) -> Tup
assign_delays(userid)
state.song_start_clock = 0
state.song_end_clock = 0
sendall("song_start_clock", state.song_start_clock)
sendall("song_end_clock", state.song_end_clock)

state.metronome_on = False
state.leader = userid
Expand Down Expand Up @@ -1149,6 +1139,8 @@ def handle_post(in_data, query_string, print_status, client_address=None) -> Tup
"last_request_clock": saved_last_request_clock,
"client_read_clock": client_read_clock,
"client_write_clock": client_write_clock,
"song_end_clock": state.song_end_clock,
"song_start_clock": state.song_start_clock,
"n_samples": n_samples,
"n_connected_users": len(active_users()),
"queue_size": QUEUE_LENGTH / FRAME_SIZE, # in 128-sample frames
Expand Down

0 comments on commit 7d35cde

Please sign in to comment.