function connect(url, options = {}) {
const { compressed } = options;
const conn = new WebSocket(url);
const recv = Generators.observe(notify => {
conn.onmessage = function(event) {
try {
const data = parseString(event.data, compressed);
notify({ status: "success", data });
} catch (e) {
notify({ status: "error", err: e.message, data: event.data });
}
};
conn.onclose = function() {
notify(null);
};
notify(null);
});
return { conn, recv };
}