@@ -36,25 +36,18 @@ module openflow {
3636 private _sendQueue : SocketMessage [ ] = [ ] ;
3737 public user :TokenUser = null ;
3838 public jwt :string = null ;
39- static $inject = [ "$rootScope" , "$location" ] ;
39+ static $inject = [ "$rootScope" , "$location" , "$window" ] ;
4040 public messageQueue : IHashTable < QueuedMessage > = { } ;
41- constructor ( public $rootScope :ng . IRootScopeService , public $location ) {
42- var url :string = window . location . href ;
43- var arr :string [ ] = url . split ( "/" ) ;
44- var result :string = arr [ 0 ] + "//" + arr [ 2 ] ;
45- if ( arr [ 0 ] === "http:" ) {
46- result = "ws://" + arr [ 2 ] ;
47- } else {
48- result = "wss://" + arr [ 2 ] ;
49- }
50- this . _url = result ;
51- console . log ( "WebSocketClient::onopen: connecting to " + result ) ;
52- this . _socketObject = new ReconnectingWebSocket ( result ) ;
53- this . _socketObject . onopen = ( this . onopen ) . bind ( this ) ;
54- this . _socketObject . onmessage = ( this . onmessage ) . bind ( this ) ;
55- this . _socketObject . onclose = ( this . onclose ) . bind ( this ) ;
56- this . _socketObject . onerror = ( this . onerror ) . bind ( this ) ;
57- WebSocketClient . instance = this ;
41+ constructor ( public $rootScope :ng . IRootScopeService , public $location , public $window :any ) {
42+ this . getJSON ( "/config" , async ( error :any , data :any ) => {
43+ console . debug ( "WebSocketClient::onopen: connecting to " + data . wshost ) ;
44+ this . _socketObject = new ReconnectingWebSocket ( data . wshost ) ;
45+ this . _socketObject . onopen = ( this . onopen ) . bind ( this ) ;
46+ this . _socketObject . onmessage = ( this . onmessage ) . bind ( this ) ;
47+ this . _socketObject . onclose = ( this . onclose ) . bind ( this ) ;
48+ this . _socketObject . onerror = ( this . onerror ) . bind ( this ) ;
49+ WebSocketClient . instance = this ;
50+ } ) ;
5851 }
5952 public connect ( ) :void {
6053 }
@@ -86,20 +79,13 @@ module openflow {
8679 private async onopen ( evt : Event ) :Promise < void > {
8780 console . log ( "WebSocketClient::onopen: connected" ) ;
8881 var me :WebSocketClient = WebSocketClient . instance ;
89- // me.communication = "Conenction opened, signing in" + "<br/>" + me.communication;
90- // var message:any = { command: "signin", data: {username: "az", password: "az"}};
91- // me._socketObject.send(JSON.stringify(message));
9282 var q :SigninMessage = new SigninMessage ( ) ;
9383 this . getJSON ( "/jwt" , async ( error :any , data :any ) => {
9484 try {
9585 if ( data === null || data === undefined || data . jwt === "" ) {
9686 if ( this . $location . path ( ) !== "/Login" ) {
9787 console . log ( "path: " + this . $location . path ( ) ) ;
9888 console . log ( "WebSocketClient::onopen: Not signed in, redirect /Login" ) ;
99- // var url:string = window.location.href;
100- // var arr:string[] = url.split("/");
101- // var result:string = arr[0] + "//" + arr[2];
102- // top.location.href = result + "/#Login";
10389 this . $location . path ( "/Login" ) ;
10490 this . $rootScope . $apply ( ) ;
10591 }
@@ -111,6 +97,7 @@ module openflow {
11197 } catch ( error ) {
11298 }
11399 q . jwt = data . jwt ;
100+ q . rawAssertion = data . rawAssertion ;
114101 q . realm = "browser" ;
115102 console . log ( "WebSocketClient::onopen: Validate jwt" ) ;
116103 if ( _android != null ) {
@@ -136,16 +123,14 @@ module openflow {
136123 console . error ( error ) ;
137124 this . $location . path ( "/Login" ) ;
138125 this . $rootScope . $apply ( ) ;
139- }
126+ }
140127 } ) ;
141128 }
142129 private onclose ( evt : CloseEvent ) :void {
143130 var me :WebSocketClient = WebSocketClient . instance ;
144- // me.communication = "Conenction Closed " + evt.code + " " + evt.type + "<br/>" + me.communication;
145131 }
146132 private onerror ( evt : ErrorEvent ) :void {
147133 var me :WebSocketClient = WebSocketClient . instance ;
148- // me.communication = "Error Occured " + evt.message + "<br/>" + me.communication;
149134 }
150135 private onmessage ( evt : MessageEvent ) :void {
151136 var me :WebSocketClient = WebSocketClient . instance ;
@@ -156,7 +141,7 @@ module openflow {
156141 public async Send < T > ( message : Message ) :Promise < T > {
157142 return new Promise < T > ( async ( resolve , reject ) => {
158143 this . _Send ( message , ( ( msg ) => {
159- if ( msg . error !== null && msg . error !== undefined ) { return reject ( msg . error ) ; }
144+ if ( msg . error !== null && msg . error !== undefined ) { console . log ( message ) ; return reject ( msg . error ) ; }
160145 resolve ( msg ) ;
161146 } ) . bind ( this ) ) ;
162147 } ) ;
@@ -179,9 +164,6 @@ module openflow {
179164 if ( message . replyto === null || message . replyto === undefined ) {
180165 this . messageQueue [ message . id ] = new QueuedMessage ( message , cb ) ;
181166 }
182- // setTimeout(() => {
183- // this.ProcessQueue();
184- // }, 500);
185167 this . ProcessQueue ( ) ;
186168 }
187169 public chunkString ( str : string , length : number ) : string [ ] {
0 commit comments