Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

kfish610/bs-ws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bs-ws

Simple node websocket implementation for Reason

npm

GitHub issues

Installation

npm install --save bs-ws

or

npm i -S bs-ws

Then add bs-ws to bs-dependencies in your bsconfig.json:

{
  ...
  "bs-dependencies": ["bs-ws"]
}

Examples

Simple Example

let ws = Ws.WebSocket.make("wss://www.example.com");
Ws.WebSocket.(
ws
-> on(`message((data) => Js.log("Message: " ++ data)))
-> on(`close((code, reason) => Js.log("Closed: " ++ string_of_int(code) ++ reason)))
-> on(`open_(() => Js.log("Opened!")))
-> on(`error(error => Js.log("Error: " ++ Ws.ErrorEvent.message(error))))
);

Example with subprotocols

let ws = Ws.WebSocket.makeWithProtocols("wss://www.example.com", [| "soap" |]);
Ws.WebSocket.(
ws
-> on(`message((data) => Js.log("Message: " ++ data)))
-> on(`close((code, reason) => Js.log("Closed: " ++ string_of_int(code) ++ reason)))
-> on(`open_(() => Js.log("Opened!")))
-> on(`error(error => Js.log("Error: " ++ Ws.ErrorEvent.message(error))))
);

Send

let ws = Ws.WebSocket.make("wss://www.example.com");
Ws.WebSocket.(
ws
-> send("Hello World!")
);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages