microsoft/BotFramework-DirectLineJS

Error in Connection Status

drfbwilliams opened this issue · 14 comments

Hi

The Connection Status is incorrectly stating that the connection has failed and ended. The bot is still active and able to send and receive activities. I note at no other time does the connection status appear to change.

The following image is the output directly when a connection is first initialised with

image

Version 0.11.6

Can you include the code you are using for building and running Direct Line (hiding any keys/secrets)?

Nothing non-standard as far as I understand - pretty much the minimum to connect?

var directLine = new DirectLine({    
    secret: "<<code>>",
});

directLine.connectionStatus$
    .subscribe(connectionStatus => {
        switch (connectionStatus) {
            case ConnectionStatus.Uninitialized:    // the status when the DirectLine object is first created/constructed
                console.log('Connection: Uninitialized');
            case ConnectionStatus.Connecting:       // currently trying to connect to the conversation
                console.log('Connection: Connecting');
            case ConnectionStatus.Online:           // successfully connected to the converstaion. Connection is healthy so far as we know.
                console.log('Connection: Online');
            case ConnectionStatus.ExpiredToken:     // last operation errored out with an expired token. Your app should supply a new one.
                console.log('Connection: Expired Token');
            case ConnectionStatus.FailedToConnect:  // the initial attempt to connect to the conversation failed. No recovery possible.
                console.log('Connection: Failed');
            case ConnectionStatus.Ended:            // the bot ended the conversation
                console.log('Connection: Ended');
        }
    });

Cheers

Don't know why the code tag published such an awful mess - clearly something with some quotes somewhere. Sorry.

@drfbwilliams, I'm having some trouble repro'ing this. Is there anything about the environment this is being called in? Is it just a simple JS file, with the above code, that is being run?

Hi @stevkan - this is the same behavior in both a plain old TS implementation as well as in a React component.

Maybe an issue with rxjs? just thinking out aloud at this point.

remember that I am still using v 0.11.6 as well - not sure if something changes since and a fix is in place.

Cheers

Hi @drfbwilliams, thank you for your patience. I will attempt to repro this today using the older version and let you know what I find.

@drfbwilliams, are you able to provide code for your TS and/or React implementations? If possible, this will allow me to more precisely duplicate your efforts and get a better sense of what is happening.

@drfbwilliams, just an fyi, I am still unable to repro the issue. Per the above, are you able to share files, at all?

@stevkan sorry for delay in response, it's on my to-do list, just smashed on time at present.

Thanks for chasing up

@stevkan - hi - I put a repro together and stuffed it into a private repo - you should have a collab invite for it?

Apologies, I checked in the modules directory and am short on time to remove etc. You will see the barest of bare bones react to run this.

I kept the package.json file exact to the other solutions this issue is reported against.

npm run build
output is to console as per the issue.

Hope this helps,
Cheers

@drfbwilliams, are you able to send the invite, again? Initially, I was able to visit the repo but not interact with it while also getting an unusual GH error. Researching around suggested it was a GH issue. The problem is now the repo has dropped away and I can't access it at all and following the invite says it expired / no longer exists.

No problems - should have got an invite again. Let me know if you keep having issues.

Cheers

Hi @drfbwilliams, I noticed in your app.tsx file that the ConnectionStatus case statement is lacking a break after each case statement. Without a break or return, each case statement will bleed into the next resulting in each value being printed starting with the matched value. This explains why to start you get the whole list of statuses but the list then changes as the subsequent runs thru the switch statement occurs. With the break statements added, this is what I'm getting:

image

You can test your code by changing to the below in your project?

directLine.connectionStatus$
    .subscribe(connectionStatus => {
        switch (connectionStatus) {
            case ConnectionStatus.Uninitialized:    // the status when the DirectLine object is first created/constructed
                console.log('Connection: Uninitialized');
                break;
            case ConnectionStatus.Connecting:       // currently trying to connect to the conversation
                console.log('Connection: Connecting');
                break;
            case ConnectionStatus.Online:           // successfully connected to the converstaion. Connection is healthy so far as we know.
                console.log('Connection: Online');
                break;
            case ConnectionStatus.ExpiredToken:     // last operation errored out with an expired token. Your app should supply a new one.
                console.log('Connection: Expired Token');
                break;
            case ConnectionStatus.FailedToConnect:  // the initial attempt to connect to the conversation failed. No recovery possible.
                console.log('Connection: Failed');
                break;
            case ConnectionStatus.Ended:            // the bot ended the conversation
                console.log('Connection: Ended');
                break;
        }
    });

Hi @stevkan - thanks for looking into this.

I can tell from your response without even testing that indeed this is the issue.

Stupidly in my haste to get something running, I blindly copied the getting started snippets from the docs - and as you will see, the section example code doesn't include the break points.

https://github.com/microsoft/BotFramework-DirectLineJS#monitor-connection-status

Thanks for coming back to me on it.

Have a great New Years!

Best,
Brennon