From: Carl Worth Date: Mon, 8 Jun 2020 13:57:22 +0000 (-0700) Subject: Add a new "broadcast_event_object" method to accept an obejct not a string X-Git-Url: https://git.cworth.org/git?p=lmno-server;a=commitdiff_plain;h=ea4d0802292a43555d5710041a050f6df71c38e0 Add a new "broadcast_event_object" method to accept an obejct not a string I probably want this to be the default, (replacing broadcast_event entirely, or perhaps renaming it to broadcast_event_string if there are any users that do need to stick around). With cases like this, I do wish I was using a type safe language to avoid the confusion that comes with "Does this function want an object or a string representation of that object?". --- diff --git a/game.js b/game.js index eb78f31..eb1ba80 100644 --- a/game.js +++ b/game.js @@ -224,6 +224,10 @@ class Game { this.broadcast_string(`event: ${type}\ndata: ${data}\n`); } + broadcast_event_object(type, obj) { + this.broadcast_event(type, JSON.stringify(obj)); + } + handle_events(request, response) { /* These headers will keep the connection open so we can stream events. */ const headers = {