mirror of
https://github.com/status-im/status-go.git
synced 2025-02-11 14:26:53 +00:00
Updated Whisper Push Notifications (markdown)
parent
1869ac28a0
commit
30a3bb1a11
@ -56,7 +56,7 @@ Original workflow for discovery mechanism was introduced in:
|
|||||||
|
|
||||||
[![image](https://cloud.githubusercontent.com/assets/188194/24608168/19317cdc-187e-11e7-995e-2adadc17a91c.png)](https://cloud.githubusercontent.com/assets/188194/24608168/19317cdc-187e-11e7-995e-2adadc17a91c.png)
|
[![image](https://cloud.githubusercontent.com/assets/188194/24608168/19317cdc-187e-11e7-995e-2adadc17a91c.png)](https://cloud.githubusercontent.com/assets/188194/24608168/19317cdc-187e-11e7-995e-2adadc17a91c.png)
|
||||||
|
|
||||||
Everything starts with `Device A` willing to register with some Notification Service Provider, for that discovery request needs to be sent:
|
Everything starts with `Device A` willing to register with some Notification Service Provider. To do so, it sends/broadcasts discovery request:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var discoverServerTopic = '0x268302f3'; // DISCOVER_NOTIFICATION_SERVER
|
var discoverServerTopic = '0x268302f3'; // DISCOVER_NOTIFICATION_SERVER
|
||||||
@ -79,10 +79,39 @@ var sendDiscoveryRequest = function (identity) {
|
|||||||
var identity = web3.shh.newIdentity();
|
var identity = web3.shh.newIdentity();
|
||||||
sendDiscoveryRequest(identity);
|
sendDiscoveryRequest(identity);
|
||||||
```
|
```
|
||||||
Once that request is sent all capable wnodes respond back, so we need to watch for their responses, and select one provider (generally FIFO):
|
Once that request is sent all capable wnodes respond back, so we need to watch for their responses, and select one provider (generally FIFO). To watch:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
var proposeServerTopic = '0x08e3d8c0'; // PROPOSE_NOTIFICATION_SERVER
|
||||||
|
var watchProposeServerResponses = function (identity) {
|
||||||
|
// some notification servers will be able to serve, so they will send encrypted (to you)
|
||||||
|
// message, with a PROPOSE_NOTIFICATION_SERVER topic (for which we wait)
|
||||||
|
var filter = web3.shh.filter({
|
||||||
|
to: identity, // wait for anon. messages to ourselves
|
||||||
|
topics: [proposeServerTopic]
|
||||||
|
});
|
||||||
|
filter.watch(function (error, result) {
|
||||||
|
if (!error) {
|
||||||
|
console.log("Server proposal received: ", result);
|
||||||
|
// response will be in JSON, e.g. {"server": "0x81f34abd0df038e01a8f9c04bee7ce92925b7240e334dc8f2400dea7a2a6d829678be8b40e1d9b9988e25960552eafe2df7f928188e4143ba657a699519c438d"}
|
||||||
|
// which will give you serverID
|
||||||
|
var payload = JSON.parse(web3.toAscii(result.payload));
|
||||||
|
|
||||||
|
// no need to watch for the filter any more
|
||||||
|
filter.stopWatching();
|
||||||
|
|
||||||
|
// accept (in FIFO order) the server
|
||||||
|
// we need to make sure that only a single server is selected,
|
||||||
|
// as you will receive multiple proposals for different servers,
|
||||||
|
// and may accept more that one of those proposals (which will
|
||||||
|
// result in duplicate notifications)
|
||||||
|
sendAcceptServerRequest(identity, payload.server);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
watchProposeServerResponses(identity);
|
||||||
```
|
```
|
||||||
|
Now, whenever we receive server proposal and willing to accept it, `sendAcceptServerRequest()` message needs to be broadcasted (so that server knows we have selected it):
|
||||||
|
|
||||||
# Sharing the key
|
# Sharing the key
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user