Getting started with effects managers and WebRTC

486 views
Skip to first unread message

Gábor Varga

unread,
Jul 6, 2016, 1:31:47 PM7/6/16
to elm-dev
Hello folks,


I would like to use WebRTC from Elm. 
I did not find any prior work on that, so I believe I will have to write it my self -- which sounds like fun for now.

To me this seems like an exercise where I should write an effects manager as well as some native JS.

Where shall I get started with effects managers? Are there any secret blog posts, or not-yet-published documentation on this?
If not, which elm package/module would be the most educative: perhaps Websocket in core?


Thanks,

Gabor

Alex Lew

unread,
Jul 7, 2016, 10:26:07 AM7/7/16
to elm-dev
If you're willing to put up with potential inaccuracies / incompleteness, I have an unpublished (and probably to-remain-unpublished) blog post draft here with some observations about effect managers: https://medium.com/@alex.lew/8e87fd14332c. This was really written out of curiosity & in case others were curious, not as a how-to-write-effect-managers guide, but you may find it helpful in making sense of existing effect manager code. Good luck! :)

Pablo Bollansée

unread,
Dec 22, 2016, 2:54:12 PM12/22/16
to elm-dev
Did you ever finish this? As I was looking to try WebRTC in Elm as well.

Martin Janiczek

unread,
Feb 10, 2017, 3:30:47 PM2/10/17
to elm-dev
I think the problem with WebRTC is the non-existence of universal signaling protocol.

Disregarding how the signaling server code would work, the API would probably have to look something like:

type ConnectionStatus
 
= Disconnected
 
| ConnectedNotReady
 
| ConnectedReady


listenOnly
: String -> (ConnectionStatus -> msg) -> (Json.Decode.Value -> msg) -> Sub msg
listenOnly connectionName setConnectionStatusMsg getDataMsg
= ...


sendOnly
: String -> (ConnectionStatus -> msg) -> Sub msg
sendOnly connectionName setConnectionStatusMsg
= ...


listenAndSend
: String -> (ConnectionStatus -> msg) -> (Json.Decode.Value -> msg) -> Sub msg
listenAndSend connectionName setConnectionStatus getDataMsg
= ...


send
: String -> Json.Decode.Value -> Cmd msg
send connectionName value
= ...


I am creating an Elm app with three WebRTC peers (library, controller, output) and the graph like this:
- library -> controller
- library -> output
- controller -> output

So that would translate into (controller):

type Peer
 
= Library
 
| Output


type
Msg
 
= SetPeerStatus Peer WebRTC.ConnectionStatus
 
| SendDataToOutput -- sent periodically or onClick of a button
 
| GetDataFromLibrary Json.Decode.Value

type
alias DataFromLibrary =
 
Bool

type
alias DataForOutput =
 
Int

type
alias Model =
 
{ webRtcStatus : List (Peer, WebRTC.ConnectionStatus)
 
, dataFromLibrary : Maybe DataFromLibrary
 
, dataForOutput : DataForOutput
 
}

update msg model
=
 
case msg of
   
SetPeerStatus peer status ->
     
( { model | webRtcStatus =
           
List.Extra.updateIf
             
(\(oldPeer, _) -> oldPeer == peer)
             
(\_ -> (peer, status))
             model
.webRtcStatus
       
}
     
, Cmd.none
     
)


   
SendDataToOutput ->
     
( model
     
, WebRTC.send "output" model.data
     
)

   
GetDataFromLibrary json ->
     
( model -- do something with JSON, eg. Json.Decode.decodeValue libraryDataDecoder. This part is big so I did not include it. But it can be done :)
     
, Cmd.none
     
)


subscriptions model
=
 
Sub.batch
   
[ WebRTC.listenOnly "library" (SetPeerStatus Library) GetDataFromLibrary
   
, WebRTC.sendOnly "output" (SetPeerStatus Output)
   
]

I don't know how/whether to handle reconnections, error values (as in WebSocket.LowLevel), ...

Does this kind of API make sense? Gabor, did you make any progress with this effect manager?

Gábor Varga

unread,
Mar 3, 2017, 3:20:41 PM3/3/17
to elm-dev
Sorry guys for the late answer. 
I never got too far with this, so I do not have anything to share. Currently we use our in-house JS lib to take care of the WebRTC/media related stuff, and since it mostly get's the job done, I do not see it getting replaced in the near term future.
Reply all
Reply to author
Forward
0 new messages