Elm WebSocket with binary data

I need to use sockets with binary data, so I copied the Evan library into my source code and hacked my own code to read

 socket.addEventListener("message", function(event) {
        var reader = new FileReader();
        console.log("** onmessage");

        try {
            reader.readAsArrayBuffer(event.data);
        } catch (e) {
            console.error(e)
        }

        reader.addEventListener("loadend", function(event) {
            // ArrayBuffer
            let record = msgpack.decode(new Uint8Array(event.target.result));
            let recordString = JSON.stringify(record.NewRecords[0].Record);
            _elm_lang$core$Native_Scheduler.rawSpawn(A2(settings.onMessage, socket, recordString));
        });
    });

      

I have three errors:

  • I am getting fewer callbacks in Elm than ** onmessage

    logs
  • for large messages i get a fraction of the logs ** onmessage

    i expect
  • I am not receiving any follow-up messages

First, I thought that my closure above would make a new instance of filereader every time the message appears (and indeed, I don't get any errors that filerader is busy). Code like this worked fine when I built a simple js socket handling code connected to a port.

Second, it looks like the socket has completely lost messages. I am wondering if there is a problem with having _elm_lang$core$Native_Scheduler.rawSpawn(A2(settings.onMessage, socket, recordString));

a closure in the new that leads to some kind of race condition on the value socket

?

Update Using the dev console, I see that the first time I hit the rawSpawn line, socket.readyState == 1

(open) and then socket.readyState == 3

(i.e. Closed). I don't have any code that closes it.

+3
elm sockets


source to share


No one has answered this question yet

Check out similar questions:

89
Difference in knitting between type and type alias?
51
What does the operator `` << '' mean in elm?
37
What is "! []" The syntax of Vyal codes in Todomks means
21
How do I create HTML data attributes in Elm?
eleven
Saving data to elm
ten
Elm compiler in Elm?
five
How to receive socket events in sails.js 0.10?
4
Socket data doesn't seem to reach the client
3
Elm Websites with Rust Server
1
Closing socket session after one message



All Articles
Loading...
X
Show
Funny
Dev
Pics