diff --git a/main.go b/main.go index 49753be97da1d0486774a4153fc5e6b86d8173f1..53347e1fcec7d7e8552e7c824472ee50176d391d 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 52af87f78907127c0cbd4c1f8fb413f4dbcf00cc..14b33853465bbaa5201797a228b3a8244f0587e7 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 f65af1e933da6a6634bf9ee747e75bd3c552394c..25f9a7b77fb79b8640e9f564e97df14f262a9bd0 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 c1e11b3ba21869c7e9c3bce923de4b6dc4bd5c71..2543466ed7ab87779c043b55a1f8ad463cd274dd 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 9e0249e8ebc76632e5c09deb639b289c6f197f9b..69bda8549f16a93356ee15ce52270db413793ac0 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 // ////////////////////////////////////////////////////////////////////////////////