diff --git a/src/angular-websocket.js b/src/angular-websocket.js index 3f4e919..618c728 100644 --- a/src/angular-websocket.js +++ b/src/angular-websocket.js @@ -43,12 +43,12 @@ if (!Array.prototype.indexOf) { // $WebSocketProvider.$inject = ['$rootScope', '$q', '$timeout', '$websocketBackend']; function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) { - function $WebSocket(url, protocols, options) { + function $WebSocket(url, protocols, options, wsOptions = {}) { if (!options && isObject(protocols) && !isArray(protocols)) { options = protocols; protocols = undefined; } - + this.wsOptions = wsOptions; this.protocols = protocols; this.url = url || 'Missing URL'; this.ssl = /(wss)/i.test(this.url); @@ -121,7 +121,7 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) { $WebSocket.prototype._connect = function _connect(force) { if (force || !this.socket || this.socket.readyState !== this._readyStateConstants.OPEN) { - this.socket = $websocketBackend.create(this.url, this.protocols); + this.socket = $websocketBackend.create(this.url, this.protocols, this.wsOptions); this.socket.onmessage = angular.bind(this, this._onMessageHandler); this.socket.onopen = angular.bind(this, this._onOpenHandler); this.socket.onerror = angular.bind(this, this._onErrorHandler); @@ -367,13 +367,17 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) { // $WebSocketBackendProvider.$inject = ['$log']; function $WebSocketBackendProvider($log) { - this.create = function create(url, protocols) { + this.create = function create(url, protocols, options) { var match = /wss?:\/\//.exec(url); if (!match) { throw new Error('Invalid url provided'); } + if (options) { + return new Socket(url, protocols, options); + } + if (protocols) { return new Socket(url, protocols); }