Use client_message_id as key for sent_messages lookups.

We now use a client-side message id to track the state of our
sent messages.  This sets up future commits to start tracking
state earlier in the message's life cycle.

It also avoids ugly reify logic where we capture an event to
update our data structure to key on the server's message id
instead of the local id.  That eliminates the node test as well.

Another node test gets deleted here, just because it's not
worth the trouble with upcoming refactorings.
This commit is contained in:
Steve Howell
2017-07-13 10:21:16 -04:00
committed by showell
parent 7e88fb25b3
commit 9ee2be4a0d
6 changed files with 46 additions and 75 deletions

View File

@@ -216,11 +216,15 @@ exports.send_message_success = function (local_id, message_id, locally_echoed) {
};
exports.transmit_message = function (request, on_success, error) {
request.client_message_id = sent_messages.get_new_client_message_id({
var client_message_id = sent_messages.get_new_client_message_id({
local_id: request.local_id,
});
sent_messages.clear(request.id);
// The host will attach this to message events, and it will allow
// us to match up the right messages to this request.
request.client_message_id = client_message_id;
sent_messages.clear(client_message_id);
var local_id = request.local_id;
var start_time = new Date();
@@ -231,11 +235,13 @@ exports.transmit_message = function (request, on_success, error) {
// box and turning off spinners and reifying locally echoed messages.
on_success(data);
var message_id = data.id;
// Once everything is reified, get ready to report times to the server.
sent_messages.process_success(message_id, start_time, locally_echoed);
sent_messages.set_timer_for_restarting_event_loop(message_id);
sent_messages.process_success({
client_message_id: client_message_id,
start: start_time,
locally_echoed: locally_echoed,
});
sent_messages.set_timer_for_restarting_event_loop(client_message_id);
}
if (page_params.use_websockets) {