Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added protocols support #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/channels-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ class WebsocketTransport extends EventEmitter implements ITransport {
* @param url Websocket URL to connect to
* @param options Options to pass to ReconnectingWebsocket
*/
constructor(url: string, options: Object={}) {
constructor(url: string, protocols: Array<any>, options: Object={}) {
super();
this.url = url;
this.options = options;
this.protocols = protocols;
this.socket = null;
this.hasConnected = false;
}
Expand All @@ -109,7 +110,7 @@ class WebsocketTransport extends EventEmitter implements ITransport {
}

log.info('Connecting to websocket at %s', this.url);
this.socket = new ReconnectingWebsocket(this.url, [], this.options);
this.socket = new ReconnectingWebsocket(this.url, this.protocols, this.options);
this.socket.addEventListener('message', this._handleMessage);
this.socket.addEventListener('open', this._handleOpen);
return true;
Expand Down Expand Up @@ -526,8 +527,8 @@ export default {
* @param url WebSocket URL to connect to
* @param options Configuration for ChannelsApi and ReconnectingWebsocket
*/
connect(url: string, options: ChannelsApiOptions={}): ChannelsApi {
const client = this.createClient(url, options);
connect(url: string, protocols: Array<any>=[], options: ChannelsApiOptions={}): ChannelsApi {
const client = this.createClient(url, protocols, options);
client.initialize();
return client;
},
Expand All @@ -538,9 +539,9 @@ export default {
* @param url WebSocket URL to connect to
* @param options Configuration for ChannelsApi and ReconnectingWebsocket
*/
createClient(url: string, options: ChannelsApiOptions={}): ChannelsApi {
createClient(url: string, protocols: Array<any> = [], options: ChannelsApiOptions={}): ChannelsApi {
const dispatcher = new FifoDispatcher();
const transport = new WebsocketTransport(url, options.websocket);
const transport = new WebsocketTransport(url, protocols, options.websocket);
const queue = new FifoQueue();
const serializer = new JSONSerializer();
return new ChannelsApi(dispatcher, transport, queue, serializer, options);
Expand Down