it-ws
Version:
Simple async iterables for websocket client connections
13 lines • 561 B
JavaScript
// load websocket library if we are not in the browser
import duplex from './duplex.js';
import WebSocket from './web-socket.js';
import wsurl from './ws-url.js';
export function connect(addr, opts) {
const location = typeof window === 'undefined' ? undefined : window.location;
opts = opts ?? {};
const url = wsurl(addr, location);
// it's necessary to stringify the URL object otherwise react-native crashes
const socket = new WebSocket(url.toString(), opts.websocket);
return duplex(socket, opts);
}
//# sourceMappingURL=client.js.map