From 21a0dafae68d5ea9d9f073f11076495999c7fbeb Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Tue, 30 Dec 2025 19:17:37 -0600 Subject: [PATCH] feat: enhance chat message handling in WASM by including sender information and user-specific app data --- pkg/wasm/wasm.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/wasm/wasm.go b/pkg/wasm/wasm.go index d9c2ac7..508e6cc 100644 --- a/pkg/wasm/wasm.go +++ b/pkg/wasm/wasm.go @@ -115,13 +115,27 @@ func InitReticulum(this js.Value, args []js.Value) interface{} { }) } + if userName != "" { + dest.SetDefaultAppData([]byte(userName)) + } + dest.SetPacketCallback(func(data []byte, ni common.NetworkInterface) { stats.packetsReceived++ stats.bytesReceived += len(data) - + + var from string + var text string + if len(data) >= 16 { + from = hex.EncodeToString(data[:16]) + text = string(data[16:]) + } else { + from = "" + text = string(data) + } + js.Global().Call("onChatMessage", js.ValueOf(map[string]interface{}{ - "text": string(data), - "from": "", + "text": text, + "from": from, })) }) @@ -206,7 +220,11 @@ func SendAnnounce(this js.Value, args []js.Value) interface{} { appData = []byte(userName) } - if err := reticulumDest.Announce(false, appData, nil); err != nil { + if len(appData) > 0 { + reticulumDest.SetDefaultAppData(appData) + } + + if err := reticulumDest.Announce(false, nil, nil); err != nil { return js.ValueOf(map[string]interface{}{ "error": fmt.Sprintf("Failed to send announce: %v", err), }) @@ -338,7 +356,11 @@ func SendMessage(this js.Value, args []js.Value) interface{} { }) } - encrypted, err := targetDest.Encrypt([]byte(message)) + // Prepend sender hash to message + senderHash := reticulumDest.GetHash() + payload := append(senderHash, []byte(message)...) + + encrypted, err := targetDest.Encrypt(payload) if err != nil { return js.ValueOf(map[string]interface{}{ "error": fmt.Sprintf("Encryption failed: %v", err),