rawhat / mist

gleam HTTP server. because it glistens on a web
Apache License 2.0
333 stars 12 forks source link

WebSocket Builder Messages #14

Open varnerac opened 1 year ago

varnerac commented 1 year ago

Mist currently supports binary and string messages. It'd make sense to support StringBuilder and BitBuilder outgoing messages.

rawhat commented 1 year ago

Not sure if I'm misunderstanding your ask here, but it currently supports BitBuilder as the "data" type only. You can easily call bit_builder.from_string_builder to get that out of it, so I'm not sure how much value that would provide? It'd be another custom type variant on the response, that would end up just doing that function call anyway.

Please let me know if I am indeed misunderstanding :)

varnerac commented 1 year ago

For WebSockets I'd like to see something like:

pub type Message {
  BinaryMessage(data: BitString)
  BitBuilderMessage(data: BitBuilder)
  TextMessage(data: String)
  StringBuilderMessage(data: StringBuilder)
}

so I could:

let data: StringBuilder = my_codec.build()
let Nil = websocket.send(subject, StringBuilderMessage(data: data)

The alternative is to take my StringBuilder, convert it to a String, pass it in as a TextMessage, and have Mist convert it to a BitBuilder. I'd like to keep stuff as iodata() rather than have Mist convert it back and forth.

rawhat commented 1 year ago

Ah, sorry! I somehow managed to miss the obvious WebSocket in the title of the issue... that seems very reasonable to me. Should be a small change! Thank you 😃

varnerac commented 1 year ago

You didn't miss it. I edited the title today when I realized it was unclear.