Skip to content

Commit

Permalink
Merge pull request #42 from FleekHQ/feature/ch17482/notification-subs…
Browse files Browse the repository at this point in the history
…cribe

ch17482/notificationSubscribe added to client
  • Loading branch information
SamueleA authored Jul 30, 2020
2 parents 858693f + ba20d9a commit 62cd19d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ Get the current public key generated by the daemon.
};
```

#### .notificationSubscribe()
Returns a ReadableStream that notifies about new notifications.
Notifications are triggered upon another member's interaction with a shared file or bucket, for example if he attempts to add a new file to a shared bucket.

```js
const notificationStream = client.notificationSubscribe();

notificationStream.on('data', (res) => {
const notification = res.getNotification();
console.log(notification);
});
```

## Example
You can check the example included in the `example` folder.
Expand Down
6 changes: 6 additions & 0 deletions example/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const client = new SpaceClient({
});


const notificationStream = client.notificationSubscribe();

notificationStream.on('data', (res) => {
console.log(`new notification: ${res.getNotification()}`);
});

const txlStream = client.txlSubscribe();

txlStream.on('data', (res) => {
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/client-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ client.instance = {
shareBucket: jest.fn(),
joinBucket: jest.fn(),
shareItemsToSelectGroup: jest.fn(),
notificationSubscribe: jest.fn(),
};

it('listDirectory makes the right requests', async () => {
Expand Down Expand Up @@ -211,3 +212,9 @@ it('should call shareItemsToSelectGroup', async () => {

expect(client.instance.shareItemsToSelectGroup).toHaveBeenCalledTimes(1);
});

it('notificationSubscribe makes the right requests', async () => {
client.notificationSubscribe({});

expect(client.instance.notificationSubscribe).toHaveBeenCalledTimes(1);
});
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
ThreadInfo,
GetPublicKeyRequest,
GetPublicKeyResponse,
NotificationEventResponse,
} from './definitions/space_pb';

export interface SpaceClientOpts {
Expand Down Expand Up @@ -453,6 +454,14 @@ class SpaceClient {
);
});
}

notificationSubscribe(
metadata: grpcWeb.Metadata = {},
): grpcWeb.ClientReadableStream<NotificationEventResponse> {
const request = new Empty();

return this.instance.notificationSubscribe(request, metadata);
}
}

export default SpaceClient;

0 comments on commit 62cd19d

Please sign in to comment.