Some checks failed
Bearer / scan (push) Successful in 9s
Go Build Multi-Platform / build (amd64, linux) (push) Successful in 42s
Go Build Multi-Platform / build (amd64, darwin) (push) Successful in 44s
Go Build Multi-Platform / build (arm, freebsd) (push) Successful in 41s
Go Build Multi-Platform / build (arm, windows) (push) Successful in 39s
Go Build Multi-Platform / build (arm64, windows) (push) Successful in 1m8s
Go Build Multi-Platform / build (wasm, js) (push) Successful in 1m6s
TinyGo Build / tinygo-build (tinygo-wasm, tinygo-wasm, reticulum-go.wasm, wasm) (pull_request) Failing after 1m2s
TinyGo Build / tinygo-build (tinygo-build, tinygo-default, reticulum-go-tinygo, ) (pull_request) Failing after 1m4s
Go Revive Lint / lint (push) Successful in 1m4s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Successful in 1m24s
Run Gosec / tests (push) Successful in 1m29s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Successful in 2m31s
Go Build Multi-Platform / build (amd64, freebsd) (push) Successful in 9m28s
Go Build Multi-Platform / build (arm, linux) (push) Successful in 9m28s
Go Build Multi-Platform / build (amd64, windows) (push) Successful in 9m30s
Go Build Multi-Platform / build (arm64, darwin) (push) Successful in 9m27s
Go Build Multi-Platform / build (arm64, linux) (push) Successful in 9m26s
Go Build Multi-Platform / build (arm64, freebsd) (push) Successful in 9m29s
Go Build Multi-Platform / Create Release (push) Has been skipped
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
// SPDX-License-Identifier: 0BSD
|
|
// Copyright (c) 2024-2026 Sudo-Ivan / Quad4.io
|
|
//go:build js && wasm
|
|
// +build js,wasm
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"syscall/js"
|
|
|
|
"git.quad4.io/Networks/Reticulum-Go/pkg/wasm"
|
|
"git.quad4.io/RNS-Things/reticulum-go-mf/pkg/mf"
|
|
)
|
|
|
|
var messenger *mf.Messenger
|
|
|
|
func main() {
|
|
// Register the generic WASM bridge functions first
|
|
wasm.RegisterJSFunctions()
|
|
|
|
// Add chat-specific functions to the "reticulum" JS object
|
|
reticulum := js.Global().Get("reticulum")
|
|
reticulum.Set("sendMessage", js.FuncOf(SendMessage))
|
|
reticulum.Set("sendAnnounce", js.FuncOf(SendAnnounce))
|
|
|
|
// Keep the Go program running
|
|
select {}
|
|
}
|
|
|
|
func SendMessage(this js.Value, args []js.Value) interface{} {
|
|
if len(args) < 2 {
|
|
return js.ValueOf(map[string]interface{}{
|
|
"error": "Destination hash and message required",
|
|
})
|
|
}
|
|
|
|
destHashHex := args[0].String()
|
|
message := args[1].String()
|
|
|
|
destHash, err := hex.DecodeString(destHashHex)
|
|
if err != nil {
|
|
return js.ValueOf(map[string]interface{}{
|
|
"error": fmt.Sprintf("Invalid destination hash: %v", err),
|
|
})
|
|
}
|
|
|
|
// Initialize messenger if not already done
|
|
if messenger == nil {
|
|
t := wasm.GetTransport()
|
|
d := wasm.GetDestinationPointer()
|
|
if t == nil || d == nil {
|
|
return js.ValueOf(map[string]interface{}{
|
|
"error": "Reticulum not initialized",
|
|
})
|
|
}
|
|
messenger = mf.NewMessenger(t, d)
|
|
}
|
|
|
|
// Use the high-level Messenger from mf package
|
|
if err := messenger.SendMessage(destHash, message); err != nil {
|
|
return js.ValueOf(map[string]interface{}{
|
|
"error": fmt.Sprintf("Send failed: %v", err),
|
|
})
|
|
}
|
|
|
|
return js.ValueOf(map[string]interface{}{
|
|
"success": true,
|
|
})
|
|
}
|
|
|
|
func SendAnnounce(this js.Value, args []js.Value) interface{} {
|
|
var appData []byte
|
|
if len(args) >= 1 && args[0].String() != "" {
|
|
appData = []byte(args[0].String())
|
|
}
|
|
|
|
return wasm.SendAnnounce(appData)
|
|
}
|