Websockets undefined error

651 views
Skip to first unread message

Oliver Batchelor

unread,
Mar 29, 2015, 10:01:44 PM3/29/15
to elm-d...@googlegroups.com
Hi guys, 

I've been trying to make a little multi-player game using Haskell/Elm and Websockets, and I've run into this problem trying to get the client to respond to messages from the server. As you see the clientMessages and serverMessages are defined in terms of each other which seems to cause a problem and I get this error:

Cannot read property 'value' of undefined


I've tried various things to try and break the cycle (e.g. using keepIf, merging the signal with a constant value etc.) but none successful so far. 

If anyone can point me in the right direction, that'd be great!
Thanks!
Oliver


import Html
import String

import WebSocket
import Signal (keepWhen, Signal, constant, merge)
import Signal


clientMessages : Signal String
clientMessages = Signal.map String.toUpper serverMessages

serverMessages : Signal String
serverMessages = WebSocket.connect "ws://localhost:9160" clientMessages

view : String -> Html.Html
view str = Html.text str
    
main = Signal.map view clientMessages

Oliver Batchelor

unread,
Mar 30, 2015, 3:26:01 AM3/30/15
to elm-d...@googlegroups.com

So, I understand this is a lot of what the changes for 0.15 are designed to fix, to facilitate events via "Streams" because of just this problem.
I guess all that needs to be done is to implement a web sockets interface in terms of the new primitives. Was having a look at the new elm-http and it seems quite a bit to learn to do it properly. Do websockets also need to deal with the binary/string data division that the http interface deals with?

Alex Neslusan

unread,
Mar 30, 2015, 3:50:16 AM3/30/15
to elm-d...@googlegroups.com
The basic problem is that you can't define Signals cyclically. That is, a Signal cannot be defined in terms of itself or in terms of other Signals that are defined in terms of it. I think this is one of the things that should be easier to do in 0.15, and for now, you can use an outgoing and incoming port and manage it in Javascript yourself.

Oliver Batchelor

unread,
Mar 30, 2015, 8:07:32 PM3/30/15
to elm-d...@googlegroups.com
Alright, thanks for that, seems quite a manageable approach.

Oliver

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/s_dA41bCAW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages