From e57413f25cc7b7b9c30378fbe832943b32bc32c1 Mon Sep 17 00:00:00 2001
From: Marco Ciotola <848222@stud.unive.it>
Date: Sun, 17 Feb 2019 17:42:41 +0100
Subject: [PATCH] Dispatch worker method explicitly

---
 heliosbooth/boothworker-single.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/heliosbooth/boothworker-single.js b/heliosbooth/boothworker-single.js
index edb1deb..1c87986 100644
--- a/heliosbooth/boothworker-single.js
+++ b/heliosbooth/boothworker-single.js
@@ -49,12 +49,16 @@ function do_encrypt(message) {
 // receive either
 // a) an election and an integer position of the question
 // that this worker will be used to encrypt
-// {'type': 'setup', 'question_num' : 2, 'election' : election_json}
+// {'type': 'setup', 'election': election_json}
 //
 // b) an answer that needs encrypting
-// {'type': 'encrypt', 'answer' : answer_json}
+// {'type': 'encrypt', 'q_num': 2, 'id': id, 'answer': answer_json}
 //
 self.onmessage = function(event) {
     // dispatch to method
-    self['do_' + event.data.type](event.data);
-}
+    if (event.data.type === "setup") {
+        do_setup(event.data);
+	} else if (event.data.type === "encrypt") {
+        do_encrypt(event.data);
+    }
+};
-- 
GitLab