Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with connectionStatus #8

Closed
gilesbutler opened this issue Feb 26, 2017 · 4 comments
Closed

Issue with connectionStatus #8

gilesbutler opened this issue Feb 26, 2017 · 4 comments

Comments

@gilesbutler
Copy link

Hi,

I've been following the docs and get some unexpected behaviour when trying to monitor the connection status...

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

Firstly is there a typo, should it be case connectionStatus rather than case ConnectionStatus?

Secondly when I console log each case I get back a numbers 0 then 1 and then 2.
Does 0 represent connectionStatus.Uninitialized,
1 represent connectionStatus.Connecting,
and 2 represent connectionStatus.Online?
Or am I doing something wrong/missing something?

Thanks

@billba
Copy link
Member

billba commented Feb 26, 2017

The only problem with the sample code is that switch(connectionStatus) { .. } should be surrounded by curly brackets. I've fixed this in the README, thanks for the bug report.

To answer your question, ConnectionStatus is a TypeScript enum, which really just means that it's a plan old JavaScript object with values for each field. ConnectionStatus.Uninitialized === 0 and so on. If you want a more descriptive log, try console.log(ConnectionStatus[connectionStatus]) which will show the string value, e.g. "Uninitialized".

I'm closing this issue, but feel free to add more comments if you continue to see problems.

@billba billba closed this as completed Feb 26, 2017
@gilesbutler
Copy link
Author

Thanks for the quick response @billba 👍

Sorry but I'm still slightly confused because if I console.log(ConnectionStatus[connectionStatus]) I get 'ConnectionStatus' is not defined. Is that because I'm not using TypeScript or am I missing something here?

In the example in the docs I can't see where ConnectionStatus is supposed to be defined, is this an RX thing or something that I'm missing?

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

@billba
Copy link
Member

billba commented Feb 26, 2017

It's not an RxJS or TypeScript thing, just an object exported from the library. You need to import it. If you're using ES6 modules then you'll need to do something like:

import { DirectLine, ConnectionStatus } from 'botframework-directlinejs';

This is not necessarily obvious so I have updated the code samples with import statements.

@gilesbutler
Copy link
Author

Ahh that makes way more sense ha. Thanks @billba :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants