discoveredPeers

This commit is contained in:
dmitry 2020-11-23 17:39:32 +03:00
parent 7863879122
commit 25bf8e4740
4 changed files with 29 additions and 9 deletions

View File

@ -54,7 +54,7 @@ init flags url key =
, url = url
, key = key
, page = r
, loadedPeers = Dict.empty
, discoveredPeers = Dict.empty
}
in
( emptyModel, Route.routeCommand emptyModel r )

View File

@ -36,5 +36,5 @@ type alias Model =
, key : Nav.Key
, url : Url.Url
, page : Route
, loadedPeers : Dict String PeerData
, discoveredPeers : Dict String PeerData
}

View File

@ -19,6 +19,7 @@ limitations under the License.
import Air
import Browser
import Browser.Navigation as Nav
import Dict
import Model exposing (Model)
import Msg exposing (..)
import Port exposing (sendAir)
@ -51,11 +52,29 @@ update msg model =
( model, Nav.load href )
AquamarineEvent { name, args } ->
let
a =
Debug.log "event in ELM" name
in
( model, Cmd.none )
case name of
"peers_discovered" ->
let
b =
Debug.log "args" args
up p =
case p of
Nothing ->
Just { interfaces = [] }
Just x ->
Just x
in
-- TODO get data from args, propagate
( { model | discoveredPeers = Dict.update "abc" up model.discoveredPeers }, Cmd.none )
_ ->
let
a =
Debug.log "event in ELM" name
in
( model, Cmd.none )
Click ->
( model

View File

@ -40,14 +40,15 @@ function genFlags(peerId: string): any {
// If the relay is ever changed, an event shall be sent to elm
let client = await Fluence.connect(relays[relayIdx].multiaddr, pid)
Fluence.setLogLevel("debug")
let app = Elm.Main.init({
node: document.getElementById('root'),
flags: flags
});
let eventService = new ServiceOne("event", (fnName, args: any[]) => {
console.log("event service called: " + fnName)
console.log("event service called: ", fnName)
console.log("event service args: ", args)
app.ports.eventReceiver.send({name: fnName, args})