Updated Whisper Push Notifications (markdown)

Victor Farazdagi 2017-04-11 15:30:56 +03:00
parent 27abccee13
commit 04430b1045
1 changed files with 27 additions and 0 deletions

@ -134,9 +134,36 @@ var sendAcceptServerRequest = function (identity, serverID) {
}
};
```
To complete discovery protocol, we need to receive ACK message from the Notification Server we selected. Server's ACK message will also include SymKey, which we will use to communicate securely with server down the line:
```js
var ackClientSubscriptionTopic = '0x93dafe28'; // ACK_NOTIFICATION_SERVER_SUBSCRIPTION
var watchServerAckResponses = function (identity) {
// if server we accepted is ok, it will send encrypted (to you)
// message, with a ACK_NOTIFICATION_SERVER_SUBSCRIPTION topic (for which we wait)
// This message completes the subscription process. At this point you should
// have topic and symkey necessary to manage your subscription.
var filter = web3.shh.filter({
to: identity, // wait for anon. messages to ourselves
topics: [ackClientSubscriptionTopic]
});
filter.watch(function (error, result) {
if (!error) {
console.log("Server ACK received: ", result);
// response will be in JSON, e.g. {"server": "0xdeadbeef", "key": "0xdeadbeef"}
// which will give you serverID
var payload = JSON.parse(web3.toAscii(result.payload));
console.log(payload);
// no need to watch for the filter any more
filter.stopWatching();
// this concludes discovery, and we can use obtained key to invoke chat sessions
createChatSession(payload.key)
}
});
};
```
### 2. Creating Chat session and registering device