33 var n = t ( ) ;
44 for ( var o in n ) ( "object" == typeof exports ? exports : e ) [ o ] = n [ o ] ;
55 }
6- } ( this , function ( ) {
6+ } ( "undefined" != typeof self ? self : this , function ( ) {
77 return function ( e ) {
88 function t ( o ) {
99 if ( n [ o ] ) return n [ o ] . exports ;
10- var s = n [ o ] = {
10+ var r = n [ o ] = {
1111 i : o ,
1212 l : ! 1 ,
1313 exports : { }
1414 } ;
15- return e [ o ] . call ( s . exports , s , s . exports , t ) , s . l = ! 0 , s . exports ;
15+ return e [ o ] . call ( r . exports , r , r . exports , t ) , r . l = ! 0 , r . exports ;
1616 }
1717 var n = { } ;
1818 return t . m = e , t . c = n , t . d = function ( e , n , o ) {
3030 return t . d ( n , "a" , n ) , n ;
3131 } , t . o = function ( e , t ) {
3232 return Object . prototype . hasOwnProperty . call ( e , t ) ;
33- } , t . p = "" , t ( t . s = 0 ) ;
33+ } , t . p = "" , t ( t . s = 1 ) ;
3434 } ( [ function ( e , t , n ) {
35+ "use strict" ;
36+ function o ( e ) {
37+ return console . log ( e ) ;
38+ }
39+ Object . defineProperty ( t , "__esModule" , {
40+ value : ! 0
41+ } ) , t . logError = o ;
42+ } , function ( e , t , n ) {
3543 "use strict" ;
3644 Object . defineProperty ( t , "__esModule" , {
3745 value : ! 0
3846 } ) ;
39- var o = n ( 1 ) , s = n ( 2 ) , r = n ( 3 ) , i = n ( 4 ) , c = n ( 5 ) , u = function ( ) {
47+ var o = n ( 2 ) , r = n ( 3 ) , i = n ( 4 ) , s = n ( 0 ) , c = function ( ) {
4048 function e ( e ) {
41- return this . channels = { } , this . events = new s . EventEmitter ( ) , this . missedPing = 0 ,
49+ return this . channels = { } , this . missedPing = 0 , this . events = new r . EventEmitter ( ) ,
4250 this . useBinary = ! 1 , e . url && "string" == typeof e . url ? e . port && "number" == typeof e . port ? ( this . options = {
4351 url : e . url ,
4452 port : e . port ,
4553 autoReconnect : e . autoReconnect || ! 1 ,
4654 reconnectionIntervalMin : e . reconnectionIntervalMin || 1e3 ,
4755 reconnectionIntervalMax : e . reconnectionIntervalMax || 5e3 ,
48- reconnectionAttempts : e . reconnectionAttempts || 0
49- } , this . options . reconnectionIntervalMin > this . options . reconnectionIntervalMax ? i . logError ( "reconnectionIntervalMin can not be more then reconnectionIntervalMax" ) : ( this . reconnection = new r . Reconnection ( this ) ,
50- void this . create ( ) ) ) : i . logError ( "Port must be provided and it must be number" ) : i . logError ( "Url must be provided and it must be string" ) ;
56+ reconnectionAttempts : e . reconnectionAttempts || 0 ,
57+ secure : e . secure || ! 1
58+ } , this . options . reconnectionIntervalMin > this . options . reconnectionIntervalMax ? s . logError ( "reconnectionIntervalMin can not be more then reconnectionIntervalMax" ) : ( this . reconnection = new i . Reconnection ( this ) ,
59+ void this . create ( ) ) ) : s . logError ( "Port must be provided and it must be number" ) : s . logError ( "Url must be provided and it must be string" ) ;
5160 }
52- return e . getBuffer = function ( e ) {
53- for ( var t = new Uint8Array ( e . length ) , n = 0 , o = e . length ; n < o ; n ++ ) t [ n ] = e . charCodeAt ( n ) ;
54- return t . buffer ;
61+ return e . buffer = function ( e ) {
62+ for ( var t = e . length , n = new Uint8Array ( t ) , o = 0 ; o < t ; o ++ ) n [ o ] = e . charCodeAt ( o ) ;
63+ return n . buffer ;
64+ } , e . decode = function ( e , t ) {
65+ switch ( t [ "#" ] [ 0 ] ) {
66+ case "e" :
67+ return e . events . emit ( t [ "#" ] [ 1 ] , t [ "#" ] [ 2 ] ) ;
68+
69+ case "p" :
70+ return e . channels [ t [ "#" ] [ 1 ] ] ? e . channels [ t [ "#" ] [ 1 ] ] . onMessage ( t [ "#" ] [ 2 ] ) : "" ;
71+
72+ case "s" :
73+ switch ( t [ "#" ] [ 1 ] ) {
74+ case "c" :
75+ e . pingInterval = setInterval ( function ( ) {
76+ return e . missedPing ++ > 2 ? e . disconnect ( 4001 , "Did not get pings" ) : "" ;
77+ } , t [ "#" ] [ 2 ] . ping ) , e . useBinary = t [ "#" ] [ 2 ] . binary , e . events . emit ( "connect" ) ;
78+ }
79+ }
80+ } , e . encode = function ( e , t , n ) {
81+ switch ( n ) {
82+ case "ping" :
83+ return e ;
84+
85+ case "emit" :
86+ return JSON . stringify ( {
87+ "#" : [ "e" , e , t ]
88+ } ) ;
89+
90+ case "publish" :
91+ return JSON . stringify ( {
92+ "#" : [ "p" , e , t ]
93+ } ) ;
94+
95+ case "system" :
96+ switch ( e ) {
97+ case "subscribe" :
98+ return JSON . stringify ( {
99+ "#" : [ "s" , "s" , t ]
100+ } ) ;
101+
102+ case "unsubscribe" :
103+ return JSON . stringify ( {
104+ "#" : [ "s" , "u" , t ]
105+ } ) ;
106+
107+ case "configuration" :
108+ return JSON . stringify ( {
109+ "#" : [ "s" , "c" , t ]
110+ } ) ;
111+ }
112+ }
55113 } , e . prototype . create = function ( ) {
56- var e = this ;
57- this . websocket = new WebSocket ( "ws://" + this . options . url + ":" + this . options . port ) ,
58- this . websocket . binaryType = "arraybuffer" , this . websocket . onopen = function ( ) {
59- return e . reconnection . isConnected ( ) ;
60- } , this . websocket . onerror = function ( ) {
61- return e . events . emit ( "error" ) ;
62- } , this . websocket . onmessage = function ( t ) {
63- if ( t = t . data , e . useBinary && "string" != typeof t && ( t = String . fromCharCode . apply ( null , new Uint8Array ( t ) ) ) ,
64- "#0" === t ) return e . send ( "#1" , null , "ping" ) , e . missedPing = 0 ;
114+ var t = this , n = window . MozWebSocket || window . WebSocket , o = this . options . secure ? "wss://" : "ws://" ;
115+ this . websocket = new n ( o + this . options . url + ":" + this . options . port ) , this . websocket . binaryType = "arraybuffer" ,
116+ this . websocket . onopen = function ( ) {
117+ return t . reconnection . isConnected ( ) ;
118+ } , this . websocket . onerror = function ( e ) {
119+ return t . events . emit ( "error" , e . message ) ;
120+ } , this . websocket . onmessage = function ( n ) {
121+ var o = n . data ;
122+ if ( t . useBinary && "string" != typeof o && ( o = String . fromCharCode . apply ( null , new Uint8Array ( o ) ) ) ,
123+ "#0" === o ) return t . missedPing = 0 , t . send ( "#1" , null , "ping" ) ;
65124 try {
66- t = JSON . parse ( t ) ;
125+ o = JSON . parse ( o ) ;
67126 } catch ( e ) {
68- return i . logError ( e ) ;
127+ return s . logError ( e ) ;
69128 }
70- c . socketDecodeMessages ( e , t ) ;
71- } , this . websocket . onclose = function ( t ) {
72- if ( e . missedPing = 0 , clearInterval ( e . pingInterval ) , e . events . emit ( "disconnect" , t . code , t . reason ) ,
73- ! e . reconnection . inReconnectionState ) {
74- if ( e . options . autoReconnect && 1e3 !== t . code ) return e . reconnection . reconnect ( ) ;
75- e . events . removeAllEvents ( ) ;
76- for ( var n in e ) e . hasOwnProperty ( n ) && delete e [ n ] ;
129+ e . decode ( t , o ) ;
130+ } , this . websocket . onclose = function ( e ) {
131+ if ( t . missedPing = 0 , clearInterval ( t . pingInterval ) , t . events . emit ( "disconnect" , e . code , e . reason ) ,
132+ ! t . reconnection . inReconnectionState ) {
133+ if ( t . options . autoReconnect && 1e3 !== e . code ) return t . reconnection . reconnect ( ) ;
134+ t . events . removeAllEvents ( ) ;
135+ for ( var n in t ) t . hasOwnProperty ( n ) && delete t [ n ] ;
77136 }
78137 } ;
79138 } , e . prototype . on = function ( e , t ) {
80139 this . events . on ( e , t ) ;
81140 } , e . prototype . send = function ( t , n , o ) {
82- if ( this . useBinary ) return this . websocket . send ( e . getBuffer ( c . socketEncodeMessages ( t , n , o || "emit" ) ) ) ;
83- this . websocket . send ( c . socketEncodeMessages ( t , n , o || "emit" ) ) ;
141+ void 0 === o && ( o = "emit" ) , this . websocket . send ( this . useBinary ? e . buffer ( e . encode ( t , n , o ) ) : e . encode ( t , n , o ) ) ;
84142 } , e . prototype . disconnect = function ( e , t ) {
85143 this . websocket . close ( e || 1e3 , t ) ;
86144 } , e . prototype . getState = function ( ) {
87145 return this . websocket . readyState ;
88146 } , e . prototype . subscribe = function ( e ) {
89- return this . channels [ e ] ? this . channels [ e ] : this . channels [ e ] = new o . Channel ( e , this ) ;
147+ return this . channels [ e ] ? this . channels [ e ] : this . channels [ e ] = new o . Channel ( this , e ) ;
90148 } , e . prototype . getChannelByName = function ( e ) {
91149 return this . channels [ e ] ;
92150 } , e ;
93151 } ( ) ;
94- t . ClusterWS = u ;
152+ t . ClusterWS = c ;
95153 } , function ( e , t , n ) {
96154 "use strict" ;
97155 Object . defineProperty ( t , "__esModule" , {
98156 value : ! 0
99157 } ) ;
100- var o = function ( ) {
158+ var o = n ( 0 ) , r = function ( ) {
101159 function e ( e , t ) {
102- this . channel = e , this . socket = t , this . subscribe ( ) ;
160+ this . socket = e , this . channel = t , this . subscribe ( ) ;
103161 }
104162 return e . prototype . watch = function ( e ) {
105- return this . listener = e , this ;
163+ return "[object Function]" !== { } . toString . call ( e ) ? o . logError ( "Listener must be a function" ) : ( this . listener = e ,
164+ this ) ;
106165 } , e . prototype . publish = function ( e ) {
107166 return this . socket . send ( this . channel , e , "publish" ) , this ;
108167 } , e . prototype . unsubscribe = function ( ) {
113172 this . socket . send ( "subscribe" , this . channel , "system" ) ;
114173 } , e ;
115174 } ( ) ;
116- t . Channel = o ;
175+ t . Channel = r ;
117176 } , function ( e , t , n ) {
118177 "use strict" ;
119178 Object . defineProperty ( t , "__esModule" , {
120179 value : ! 0
121180 } ) ;
122- var o = function ( ) {
181+ var o = n ( 0 ) , r = function ( ) {
123182 function e ( ) {
124183 this . events = { } ;
125184 }
126185 return e . prototype . on = function ( e , t ) {
186+ if ( "[object Function]" !== { } . toString . call ( t ) ) return o . logError ( "Listener must be a function" ) ;
127187 this . events [ e ] || ( this . events [ e ] = t ) ;
128188 } , e . prototype . emit = function ( e ) {
129189 for ( var t = [ ] , n = 1 ; n < arguments . length ; n ++ ) t [ n - 1 ] = arguments [ n ] ;
133193 this . events = { } ;
134194 } , e ;
135195 } ( ) ;
136- t . EventEmitter = o ;
196+ t . EventEmitter = r ;
137197 } , function ( e , t , n ) {
138198 "use strict" ;
139199 Object . defineProperty ( t , "__esModule" , {
151211 } , e . prototype . reconnect = function ( ) {
152212 var e = this ;
153213 this . inReconnectionState = ! 0 , this . interval = setInterval ( function ( ) {
154- e . socket . websocket . readyState === e . socket . websocket . CLOSED && ( e . reconnectionAttempted ++ ,
214+ e . socket . getState ( ) === e . socket . websocket . CLOSED && ( e . reconnectionAttempted ++ ,
155215 0 !== e . socket . options . reconnectionAttempts && e . reconnectionAttempted >= e . socket . options . reconnectionAttempts && ( clearInterval ( e . interval ) ,
156216 e . autoReconnect = ! 1 , e . inReconnectionState = ! 1 ) , clearTimeout ( e . timer ) , e . timer = setTimeout ( function ( ) {
157217 return e . socket . create ( ) ;
160220 } , e ;
161221 } ( ) ;
162222 t . Reconnection = o ;
163- } , function ( e , t , n ) {
164- "use strict" ;
165- function o ( e ) {
166- return console . log ( e ) ;
167- }
168- Object . defineProperty ( t , "__esModule" , {
169- value : ! 0
170- } ) , t . logError = o ;
171- } , function ( e , t , n ) {
172- "use strict" ;
173- function o ( e , t , n ) {
174- switch ( n ) {
175- case "ping" :
176- return e ;
177-
178- case "emit" :
179- return JSON . stringify ( {
180- "#" : [ "e" , e , t ]
181- } ) ;
182-
183- case "publish" :
184- return JSON . stringify ( {
185- "#" : [ "p" , e , t ]
186- } ) ;
187-
188- case "system" :
189- switch ( e ) {
190- case "subscribe" :
191- return JSON . stringify ( {
192- "#" : [ "s" , "s" , t ]
193- } ) ;
194-
195- case "unsubscribe" :
196- return JSON . stringify ( {
197- "#" : [ "s" , "u" , t ]
198- } ) ;
199-
200- case "configuration" :
201- return JSON . stringify ( {
202- "#" : [ "s" , "c" , t ]
203- } ) ;
204- }
205- }
206- }
207- function s ( e , t ) {
208- switch ( t [ "#" ] [ 0 ] ) {
209- case "e" :
210- return e . events . emit ( t [ "#" ] [ 1 ] , t [ "#" ] [ 2 ] ) ;
211-
212- case "p" :
213- return e . channels [ t [ "#" ] [ 1 ] ] ? e . channels [ t [ "#" ] [ 1 ] ] . onMessage ( t [ "#" ] [ 2 ] ) : "" ;
214-
215- case "s" :
216- switch ( t [ "#" ] [ 1 ] ) {
217- case "c" :
218- e . pingInterval = setInterval ( function ( ) {
219- return e . missedPing < 3 ? e . missedPing ++ : e . disconnect ( 4001 , "Did not get pings" ) ;
220- } , t [ "#" ] [ 2 ] . ping ) , e . useBinary = t [ "#" ] [ 2 ] . binary , e . events . emit ( "connect" ) ;
221- }
222- }
223- }
224- Object . defineProperty ( t , "__esModule" , {
225- value : ! 0
226- } ) , t . socketEncodeMessages = o , t . socketDecodeMessages = s ;
227223 } ] ) ;
228224} ) ;
0 commit comments