@@ -41,6 +41,20 @@ export function Init() {
4141 }
4242 } ) ;
4343
44+ AppCommon . AppEvents . on ( 'Logger' , ( message ) => {
45+ var msg = "[" + new Date ( ) . toISOString ( ) + "] :: " + message ;
46+ document . getElementById ( "app-logs" ) . innerHTML += '<p>' + msg + '</p>' ;
47+ } ) ;
48+
49+ AppCommon . AppEvents . on ( 'ConnectionFailed' , ( message ) => {
50+ debugger ;
51+ isConnected = false ;
52+ alert ( 'Connection Failed: Not able to establised the connection. Please check the Url.' ) ;
53+ AppCommon . AppEvents . off ( 'ReceivedData' , HandleResponse ) ;
54+ } ) ;
55+
56+ AppCommon . AppEvents . on ( 'OnConnected' , OnConnected ) ;
57+
4458 NotConnected ( ) ;
4559 RigisterNavigationTabEvent ( ) ;
4660
@@ -279,29 +293,29 @@ export function OnConnect() {
279293 var urlElement = document . getElementById ( "inputUrl" ) ;
280294 connectToServer ( urlElement . value ) ;
281295
296+ }
297+
298+ export function OnConnected ( ) {
299+
300+ var isAdvanceView = ! window . appLogic . GetCurrentView ( ) ;
301+ var urlElement = document . getElementById ( "inputUrl" ) ;
282302 isConnected = true ;
283303 AppCommon . ShowElementByClassName ( 'onconnect' ) ;
284304
285305 AdvanceViewElements ( isAdvanceView ) ;
286306 //Hide Connect Button
287307 AppCommon . DisableElementByClassName ( 'connectbtn' ) ;
288- AppCommon . AppEvents . emit ( 'OnConnected' ) ;
289308 AddArguments ( ) ;
290309
291- AppCommon . AppEvents . on ( 'ReceivedData' , ( data ) => {
292- document . querySelector ( "#inputResponseData" ) . value += JSON . stringify ( data ) + '\n'
293- } ) ;
294-
295- AppCommon . AppEvents . on ( 'Logger' , ( message ) => {
296- debugger ;
297- var msg = "[" + new Date ( ) . toISOString ( ) + "] :: " + message ;
298- document . getElementById ( "app-logs" ) . innerHTML += '<p>' + msg + '</p>' ;
299- } ) ;
300-
310+ AppCommon . AppEvents . on ( 'ReceivedData' , HandleResponse ) ;
301311 //Disable Url
302312 urlElement . disabled = true ;
303313}
304314
315+ export function HandleResponse ( data ) {
316+ document . querySelector ( "#inputResponseData" ) . value = JSON . stringify ( data ) + '\n' + document . querySelector ( "#inputResponseData" ) . value ;
317+ }
318+
305319export function SetConnectionProtocol ( ) {
306320 var elements = document . querySelectorAll ( ".protocol-support" ) ;
307321
@@ -336,6 +350,7 @@ export function OnDisConnect() {
336350 AdvanceViewElements ( ! window . appLogic . GetCurrentView ( ) ) ;
337351 //Enable URL textBix
338352 document . getElementById ( "inputUrl" ) . disabled = false ;
353+ AppCommon . AppEvents . off ( 'ReceivedData' , HandleResponse ) ;
339354}
340355
341356export function Reset ( ) {
0 commit comments