Since we are there is a delay between each socket-io emit and receive between server and clients, the clients currently play music with a slight delay between them.
To counter this, an emitTime value can be included in the message which when paired with a receivedTime value generated from on the receiving end, can be used to calculate the latency for each socket communication.
This latency can then be used to compensate for the delayed elapsedTime passed on the connection handshake when a new client joins (received elapsedTime + latency = actual elapsedTime)
Dayjs is used to get the local time from the endpoints, need error detection for when the local time is incorrectly set and error handling for when the latency is too high
Since we are there is a delay between each socket-io emit and receive between server and clients, the clients currently play music with a slight delay between them. To counter this, an
emitTime
value can be included in the message which when paired with areceivedTime
value generated from on the receiving end, can be used to calculate thelatency
for each socket communication. Thislatency
can then be used to compensate for the delayedelapsedTime
passed on the connection handshake when a new client joins (receivedelapsedTime
+latency
= actualelapsedTime
)