diff --git a/Whisper-Push-Notifications.md b/Whisper-Push-Notifications.md index 599ef91..c4b1bfe 100644 --- a/Whisper-Push-Notifications.md +++ b/Whisper-Push-Notifications.md @@ -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