Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/wasm-client/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"github.com/btcsuite/btclog"
"github.com/lightninglabs/lightning-node-connect/gbn"
"github.com/lightninglabs/lightning-node-connect/mailbox"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
Expand All @@ -25,6 +26,7 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {

lnd.SetSubLogger(root, Subsystem, log)
lnd.AddSubLogger(root, mailbox.Subsystem, intercept, mailbox.UseLogger)
lnd.AddSubLogger(root, gbn.Subsystem, intercept, gbn.UseLogger)

grpclog.SetLoggerV2(NewGrpcLogLogger(root, intercept, "GRPC"))
}
Expand Down
27 changes: 22 additions & 5 deletions cmd/wasm-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,29 @@ func (w *wasmClient) IsConnected(_ js.Value, _ []js.Value) interface{} {
return js.ValueOf(w.lndConn != nil)
}

func (w *wasmClient) Disconnect(_ js.Value, _ []js.Value) interface{} {
// Disconnect disconnects the client, and closes the connection.
// The first argument passed should be a onDisconnect callback, which will be
// invoked once the client has disconnected.
func (w *wasmClient) Disconnect(_ js.Value, args []js.Value) interface{} {
if w.lndConn != nil {
if err := w.lndConn.Close(); err != nil {
log.Errorf("Error closing RPC connection: %v", err)
}
w.lndConn = nil
// We launch the closure of the connection in a goroutine to
// avoid that the JS websocket freezes and blocks while closing.
go func() {
if err := w.lndConn.Close(); err != nil {
log.Errorf("Error closing RPC connection: %v",
err)
}
w.lndConn = nil

// We expect the first arg to be the onDisconnect
// callback
if len(args) > 0 && args[0].Type() == js.TypeFunction {
callback := args[0]

// Call the onDisconnect callback.
callback.Invoke()
}
}()
}

return nil
Expand Down
4 changes: 3 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@
}

async function disconnect() {
window[namespace].wasmClientDisconnect();
window[namespace].wasmClientDisconnect(onDisconnect);
}

function onDisconnect() {
document.getElementById('disconnectBtn').disabled = true;
document.getElementById('reconnectBtn').disabled = false;
document.getElementById('ready').style.display= 'none' ;
Expand Down