Websocket - graforlock/bs-websocket GitHub Wiki

Websocket | MDN

There's the main type that matches the Web API.

external make: string => t('msg)

Once created, you can operate on native Js objects in such way:

let ws = Websocket.make("ws://locahost/ws");

let onOpen = _ => {
 (*
  set callback:
  ws##onmessage #= handler; 
  *)
};

ws##onopen #= onOpen;

However, the interface exposes these publicly accessible methods:

let send = t('msg) => 'msg => unit;

let close = (~code=Js.Undefined.t(string), ~reason=Js.Undefined.t(string), t('msg)) => unit

let onOpen = t('msg) => MessageEvent.t => unit

let onError = t('msg) => MessageEvent.t => unit

let onClose = t('msg) => CloseEvent.t => unit

let onMessage = t('msg) => MessageEvent.t => unit

let setBinaryType = t('msg) => binaryType => string

Their use is demonstrated in the example section.