@@ -22,6 +22,8 @@ var BadConnectionError = scErrors.BadConnectionError;
2222
2323
2424var SCTransport = function ( authEngine , codecEngine , options ) {
25+ var self = this ;
26+
2527 this . state = this . CLOSED ;
2628 this . auth = authEngine ;
2729 this . codec = codecEngine ;
@@ -35,53 +37,14 @@ var SCTransport = function (authEngine, codecEngine, options) {
3537 this . _callbackMap = { } ;
3638 this . _batchSendList = [ ] ;
3739
38- this . open ( ) ;
39- } ;
40-
41- SCTransport . prototype = Object . create ( Emitter . prototype ) ;
42-
43- SCTransport . CONNECTING = SCTransport . prototype . CONNECTING = 'connecting' ;
44- SCTransport . OPEN = SCTransport . prototype . OPEN = 'open' ;
45- SCTransport . CLOSED = SCTransport . prototype . CLOSED = 'closed' ;
46-
47- SCTransport . prototype . uri = function ( ) {
48- var query = this . options . query || { } ;
49- var schema = this . options . secure ? 'wss' : 'ws' ;
50-
51- if ( this . options . timestampRequests ) {
52- query [ this . options . timestampParam ] = ( new Date ( ) ) . getTime ( ) ;
53- }
54-
55- query = querystring . encode ( query ) ;
56-
57- if ( query . length ) {
58- query = '?' + query ;
59- }
60-
61- var host ;
62- if ( this . options . host ) {
63- host = this . options . host ;
64- } else {
65- var port = '' ;
66-
67- if ( this . options . port && ( ( schema == 'wss' && this . options . port != 443 )
68- || ( schema == 'ws' && this . options . port != 80 ) ) ) {
69- port = ':' + this . options . port ;
70- }
71- host = this . options . hostname + port ;
72- }
73-
74- return schema + '://' + host + this . options . path + query ;
75- } ;
76-
77- SCTransport . prototype . open = function ( ) {
78- var self = this ;
40+ // Open the connection.
7941
8042 this . state = this . CONNECTING ;
8143 var uri = this . uri ( ) ;
8244
8345 var wsSocket = createWebSocket ( uri , this . options ) ;
8446 wsSocket . binaryType = this . options . binaryType ;
47+
8548 this . socket = wsSocket ;
8649
8750 wsSocket . onopen = function ( ) {
@@ -124,6 +87,42 @@ SCTransport.prototype.open = function () {
12487 } , this . connectTimeout ) ;
12588} ;
12689
90+ SCTransport . prototype = Object . create ( Emitter . prototype ) ;
91+
92+ SCTransport . CONNECTING = SCTransport . prototype . CONNECTING = 'connecting' ;
93+ SCTransport . OPEN = SCTransport . prototype . OPEN = 'open' ;
94+ SCTransport . CLOSED = SCTransport . prototype . CLOSED = 'closed' ;
95+
96+ SCTransport . prototype . uri = function ( ) {
97+ var query = this . options . query || { } ;
98+ var schema = this . options . secure ? 'wss' : 'ws' ;
99+
100+ if ( this . options . timestampRequests ) {
101+ query [ this . options . timestampParam ] = ( new Date ( ) ) . getTime ( ) ;
102+ }
103+
104+ query = querystring . encode ( query ) ;
105+
106+ if ( query . length ) {
107+ query = '?' + query ;
108+ }
109+
110+ var host ;
111+ if ( this . options . host ) {
112+ host = this . options . host ;
113+ } else {
114+ var port = '' ;
115+
116+ if ( this . options . port && ( ( schema == 'wss' && this . options . port != 443 )
117+ || ( schema == 'ws' && this . options . port != 80 ) ) ) {
118+ port = ':' + this . options . port ;
119+ }
120+ host = this . options . hostname + port ;
121+ }
122+
123+ return schema + '://' + host + this . options . path + query ;
124+ } ;
125+
127126SCTransport . prototype . _onOpen = function ( ) {
128127 var self = this ;
129128
0 commit comments