11//# Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.
22
3- " use strict" ;
3+ ' use strict' ;
44
5- Object . defineProperty ( exports , " __esModule" , {
5+ Object . defineProperty ( exports , ' __esModule' , {
66 value : true
77} ) ;
88
9- var _createClass = ( function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( " value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ) ( ) ;
9+ var _createClass = ( function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( ' value' in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ) ( ) ;
1010
11- function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( " Cannot call a class as a function" ) ; } }
11+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( ' Cannot call a class as a function' ) ; } }
1212
1313var slice = [ ] . slice ;
1414var indexOf = [ ] . indexOf ;
@@ -21,8 +21,11 @@ var Connection = (function () {
2121 var _this = this ;
2222 this . events = {
2323 message : function message ( event ) {
24- var identifier , message , ref ;
25- ref = JSON . parse ( event . data ) , identifier = ref . identifier , message = ref . message ;
24+ var identifier , message , ref , type ;
25+ ref = JSON . parse ( event . data ) , identifier = ref . identifier , message = ref . message , type = ref . type ;
26+ if ( [ 'confirm_subscription' , 'reject_subscription' ] . indexOf ( type ) >= 0 ) {
27+ return ;
28+ }
2629 return _this . consumer . subscriptions . notify ( identifier , "received" , message ) ;
2730 } ,
2831 open : function open ( ) {
@@ -40,7 +43,7 @@ var Connection = (function () {
4043 }
4144
4245 _createClass ( Connection , [ {
43- key : " send" ,
46+ key : ' send' ,
4447 value : function send ( data ) {
4548 if ( this . isOpen ( ) ) {
4649 this . webSocket . send ( JSON . stringify ( data ) ) ;
@@ -50,16 +53,20 @@ var Connection = (function () {
5053 }
5154 }
5255 } , {
53- key : " open" ,
56+ key : ' open' ,
5457 value : function open ( ) {
5558 if ( this . isState ( "open" , "connecting" ) ) {
5659 return ;
5760 }
58- this . webSocket = new WebSocket ( this . consumer . url ) ;
61+ if ( this . consumer . options . createWebsocket ) {
62+ this . webSocket = this . consumer . options . createWebsocket ( ) ;
63+ } else {
64+ this . webSocket = new WebSocket ( this . consumer . url ) ;
65+ }
5966 return this . installEventHandlers ( ) ;
6067 }
6168 } , {
62- key : " close" ,
69+ key : ' close' ,
6370 value : function close ( ) {
6471 var ref ;
6572 if ( this . isState ( "closed" , "closing" ) ) {
@@ -68,7 +75,7 @@ var Connection = (function () {
6875 return ( ref = this . webSocket ) != null ? ref . close ( ) : void 0 ;
6976 }
7077 } , {
71- key : " reopen" ,
78+ key : ' reopen' ,
7279 value : function reopen ( ) {
7380 if ( this . isOpen ( ) ) {
7481 return this . closeSilently ( ( function ( _this ) {
@@ -81,31 +88,28 @@ var Connection = (function () {
8188 }
8289 }
8390 } , {
84- key : " isOpen" ,
91+ key : ' isOpen' ,
8592 value : function isOpen ( ) {
8693 return this . isState ( "open" ) ;
8794 }
8895 } , {
89- key : " isState" ,
96+ key : ' isState' ,
9097 value : function isState ( ) {
9198 var ref , states ;
9299 states = 1 <= arguments . length ? slice . call ( arguments , 0 ) : [ ] ;
93100 return ref = this . getState ( ) , indexOf . call ( states , ref ) >= 0 ;
94101 }
95102 } , {
96- key : " getState" ,
103+ key : ' getState' ,
97104 value : function getState ( ) {
98105 var ref , state , value ;
99- for ( state in WebSocket ) {
100- value = WebSocket [ state ] ;
101- if ( value === ( ( ref = this . webSocket ) != null ? ref . readyState : void 0 ) ) {
102- return state . toLowerCase ( ) ;
103- }
106+ var states = [ 'connecting' , 'open' , 'closing' , 'closed' ] ;
107+ if ( this . webSocket ) {
108+ return states [ this . webSocket . readyState ] ;
104109 }
105- return null ;
106110 }
107111 } , {
108- key : " closeSilently" ,
112+ key : ' closeSilently' ,
109113 value : function closeSilently ( callback ) {
110114 if ( callback == null ) {
111115 callback = function ( ) { } ;
@@ -120,7 +124,7 @@ var Connection = (function () {
120124 }
121125 }
122126 } , {
123- key : " installEventHandlers" ,
127+ key : ' installEventHandlers' ,
124128 value : function installEventHandlers ( ) {
125129 var eventName , results ;
126130 results = [ ] ;
@@ -130,15 +134,15 @@ var Connection = (function () {
130134 return results ;
131135 }
132136 } , {
133- key : " installEventHandler" ,
137+ key : ' installEventHandler' ,
134138 value : function installEventHandler ( eventName , handler ) {
135139 if ( handler == null ) {
136140 handler = this . events [ eventName ] . bind ( this ) ;
137141 }
138142 return this . webSocket . addEventListener ( eventName , handler ) ;
139143 }
140144 } , {
141- key : " uninstallEventHandlers" ,
145+ key : ' uninstallEventHandlers' ,
142146 value : function uninstallEventHandlers ( ) {
143147 var eventName , results ;
144148 results = [ ] ;
@@ -148,7 +152,7 @@ var Connection = (function () {
148152 return results ;
149153 }
150154 } , {
151- key : " toJSON" ,
155+ key : ' toJSON' ,
152156 value : function toJSON ( ) {
153157 return {
154158 state : this . getState ( )
@@ -159,5 +163,5 @@ var Connection = (function () {
159163 return Connection ;
160164} ) ( ) ;
161165
162- exports [ " default" ] = Connection ;
163- module . exports = exports [ " default" ] ;
166+ exports [ ' default' ] = Connection ;
167+ module . exports = exports [ ' default' ] ;
0 commit comments