diff options
Diffstat (limited to 'packages/connect/src/orderbook_channel_factory.ts')
-rw-r--r-- | packages/connect/src/orderbook_channel_factory.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/connect/src/orderbook_channel_factory.ts b/packages/connect/src/orderbook_channel_factory.ts new file mode 100644 index 000000000..cb00212e7 --- /dev/null +++ b/packages/connect/src/orderbook_channel_factory.ts @@ -0,0 +1,33 @@ +// import * as WebSocket from 'websocket'; + +import { BrowserWebSocketOrderbookChannel } from './browser_ws_orderbook_channel'; +import { NodeWebSocketOrderbookChannel } from './node_ws_orderbook_channel'; + +export const orderbookChannelFactory = { + async createBrowserOrderbookChannelAsync(url: string): Promise<BrowserWebSocketOrderbookChannel> { + return new Promise<BrowserWebSocketOrderbookChannel>((resolve, reject) => { + const client = new WebSocket(url); + console.log(client); + client.onopen = () => { + const orderbookChannel = new BrowserWebSocketOrderbookChannel(client); + console.log(orderbookChannel); + resolve(orderbookChannel); + }; + client.onerror = err => { + reject(err); + }; + }); + }, + // async createNodeOrderbookChannelAsync(url: string): Promise<NodeWebSocketOrderbookChannel> { + // return new Promise<BrowserWebSocketOrderbookChannel>((resolve, reject) => { + // const client = new WebSocket.w3cwebsocket(url); + // client.onopen = () => { + // const orderbookChannel = new BrowserWebSocketOrderbookChannel(client); + // resolve(orderbookChannel); + // }; + // client.onerror = err => { + // reject(err); + // }; + // }); + // }, +}; |