From 5ad2b3b4bef43e0076757444177ffae71ecb4917 Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Tue, 20 Sep 2022 09:25:47 -0700
Subject: [PATCH] Add missing bindings functions

---
 main.go          |  4 ++++
 wasm/cmix.go     |  1 +
 wasm/delivery.go | 16 ++++++++++++++++
 wasm/follow.go   | 22 ++++++++++++++++++++++
 wasm/group.go    | 21 ++++++++++++++++++++-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go
index 49753be9..53347e1f 100644
--- a/main.go
+++ b/main.go
@@ -57,6 +57,9 @@ func main() {
 	js.Global().Set("NewCmix", js.FuncOf(wasm.NewCmix))
 	js.Global().Set("LoadCmix", js.FuncOf(wasm.LoadCmix))
 
+	// wasm/delivery.go
+	js.Global().Set("SetDashboardURL", js.FuncOf(wasm.SetDashboardURL))
+
 	// wasm/dummy.go
 	js.Global().Set("NewDummyTrafficManager",
 		js.FuncOf(wasm.NewDummyTrafficManager))
@@ -76,6 +79,7 @@ func main() {
 
 	// wasm/group.go
 	js.Global().Set("NewGroupChat", js.FuncOf(wasm.NewGroupChat))
+	js.Global().Set("DeserializeGroup", js.FuncOf(wasm.DeserializeGroup))
 
 	// wasm/identity.go
 	js.Global().Set("StoreReceptionIdentity",
diff --git a/wasm/cmix.go b/wasm/cmix.go
index 52af87f7..14b33853 100644
--- a/wasm/cmix.go
+++ b/wasm/cmix.go
@@ -45,6 +45,7 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} {
 		"GetNodeRegistrationStatus":   js.FuncOf(c.GetNodeRegistrationStatus),
 		"HasRunningProcessies":        js.FuncOf(c.HasRunningProcessies),
 		"IsHealthy":                   js.FuncOf(c.IsHealthy),
+		"GetRunningProcesses":         js.FuncOf(c.GetRunningProcesses),
 		"AddHealthCallback":           js.FuncOf(c.AddHealthCallback),
 		"RemoveHealthCallback":        js.FuncOf(c.RemoveHealthCallback),
 		"RegisterClientErrorCallback": js.FuncOf(c.RegisterClientErrorCallback),
diff --git a/wasm/delivery.go b/wasm/delivery.go
index f65af1e9..25f9a7b7 100644
--- a/wasm/delivery.go
+++ b/wasm/delivery.go
@@ -10,10 +10,26 @@
 package wasm
 
 import (
+	"gitlab.com/elixxir/client/bindings"
 	"gitlab.com/elixxir/xxdk-wasm/utils"
 	"syscall/js"
 )
 
+// SetDashboardURL is a function which modifies the base dashboard URL that is
+// returned as part of any send report. Internally, this is defaulted to
+// "https://dashboard.xx.network". This should only be called if the user
+// explicitly wants to modify the dashboard URL. This function is not
+// thread-safe, and as such should only be called on setup.
+//
+// Parameters:
+//  - args[0] - A valid URL that will be used for round look up on any send
+//    report (string).
+func SetDashboardURL(_ js.Value, args []js.Value) interface{} {
+	bindings.SetDashboardURL(args[0].String())
+
+	return nil
+}
+
 // messageDeliveryCallback wraps Javascript callbacks to adhere to the
 // [bindings.MessageDeliveryCallback] interface.
 type messageDeliveryCallback struct {
diff --git a/wasm/follow.go b/wasm/follow.go
index c1e11b3b..2543466e 100644
--- a/wasm/follow.go
+++ b/wasm/follow.go
@@ -154,6 +154,28 @@ func (c *Cmix) IsHealthy(js.Value, []js.Value) interface{} {
 	return c.api.IsHealthy()
 }
 
+// GetRunningProcesses returns the names of all running processes at the time
+// of this call. Note that this list may change and is subject to race
+// conditions if multiple threads are in the process of starting or stopping.
+//
+// Returns:
+//  - JSON of strings (Uint8Array).
+//
+// JSON Example:
+//  {
+//    "FileTransfer{BatchBuilderThread, FilePartSendingThread#0, FilePartSendingThread#1, FilePartSendingThread#2, FilePartSendingThread#3}",
+//    "MessageReception Worker 0"
+//  }
+func (c *Cmix) GetRunningProcesses(js.Value, []js.Value) interface{} {
+	list, err := c.api.GetRunningProcesses()
+	if err != nil {
+		utils.Throw(utils.TypeError, err)
+		return nil
+	}
+
+	return utils.CopyBytesToJS(list)
+}
+
 // networkHealthCallback adheres to the [bindings.NetworkHealthCallback]
 // interface.
 type networkHealthCallback struct {
diff --git a/wasm/group.go b/wasm/group.go
index 9e0249e8..69bda854 100644
--- a/wasm/group.go
+++ b/wasm/group.go
@@ -219,7 +219,7 @@ func (g *GroupChat) GetGroups(js.Value, []js.Value) interface{} {
 //    returned by GroupChat.MakeGroup.
 //
 // Returns:
-//  - Javascript representation of the Group object.
+//  - Javascript representation of the GroupChat object.
 //  - Throws a TypeError if getting the group fails
 func (g *GroupChat) GetGroup(_ js.Value, args []js.Value) interface{} {
 	grp, err := g.api.GetGroup(utils.CopyBytesToGo(args[0]))
@@ -333,6 +333,25 @@ func (g *Group) Serialize(js.Value, []js.Value) interface{} {
 	return utils.CopyBytesToJS(g.api.Serialize())
 }
 
+// DeserializeGroup converts the results of Group.Serialize into a
+// [bindings.Group] so that its methods can be called.
+//
+// Parameters:
+//  - args[0] - Byte representation of the Group (Uint8Array).
+//
+// Returns:
+//  - Javascript representation of the GroupChat object.
+//  - Throws a TypeError if getting the group fails
+func DeserializeGroup(_ js.Value, args []js.Value) interface{} {
+	grp, err := bindings.DeserializeGroup(utils.CopyBytesToGo(args[0]))
+	if err != nil {
+		utils.Throw(utils.TypeError, err)
+		return nil
+	}
+
+	return newGroupJS(grp)
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Callbacks                                                                  //
 ////////////////////////////////////////////////////////////////////////////////
-- 
GitLab