Skip to content

Commit 4e66d55

Browse files
Gourav DwivediGourav Dwivedi
authored andcommitted
bug fixes:
1. Duplicate error messages. 2. Duplicate response printed on single call.
1 parent 79eafef commit 4e66d55

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/js/components/logic/lib/app.signalr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class SignalRApp {
3939
var self = this;
4040
self.connection.start()
4141
.then(function () {
42-
AppEvents.emit('OnConnect', { url: self.url });
42+
AppEvents.emit('OnConnected', { url: self.url });
4343
})
4444
.catch(function (err) {
45-
AppEvents.emit('Logger', err.toString());
45+
AppEvents.emit('ConnectionFailed', err.toString());
4646
return console.error(err.toString());
4747
});
4848
}

src/js/components/srform.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
305319
export 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

341356
export function Reset() {

0 commit comments

Comments
 (0)