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

feat: Add PubSub Hub Connection state monitoring instructions #4540

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/fragments/lib/pubsub/js/subunsub.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,25 @@ const sub1 = PubSub.subscribe('myTopicA').subscribe({

sub1.unsubscribe();
// You will no longer get messages for 'myTopicA'
```
```

## Subscription connection status updates

Now that your application is setup and using pubsub subscriptions, you may want to know when the subscription is finally up and running, or reflect to your users when the subscription isn't healthy. You can monitor the connection state for changes via Hub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to be more concrete like: you may want to know when the subscription is finally established, or reflect to ...

What do you think @stocaaro ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


```typescript
import { CONNECTION_STATE_CHANGE, ConnectionState } from '@aws-amplify/pubsub';
import { Hub } from 'aws-amplify';

Hub.listen('pubsub', (data: any) => {
const { payload } = data;
if (payload.event === CONNECTION_STATE_CHANGE) {
const connectionState = payload.data.connectionState as ConnectionState;
console.log(connectionState);
}
});
```

import jsConnectionStates from '/src/fragments/lib/pubsub/js/connection-states.mdx';

<Fragments fragments={{ js: jsConnectionStates }} />