From e808ed3896292717915d18dab2257330644a2b48 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 17 Oct 2018 15:13:41 +0100 Subject: [PATCH 01/25] Hyperties updated to use new syncher.subscribe --- src/connector/Connector.hy.js | 14 ++++++++++++-- src/dtwebrtc/DTWebRTC.hy.js | 7 ++++++- src/hello-world/HelloWorldObserver.hy.js | 8 +++++++- src/wallet/Wallet.hy.js | 24 ++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/connector/Connector.hy.js b/src/connector/Connector.hy.js index e6b0c98..f247840 100755 --- a/src/connector/Connector.hy.js +++ b/src/connector/Connector.hy.js @@ -145,7 +145,12 @@ class Connector { console.info('---------------- Syncher Subscribe (Auto Subscribe) ---------------- \n'); console.info('Subscribe URL Object ', event); - syncher.subscribe(_this._objectDescURL, event.url).then(function(dataObjectObserver) { + let input = { + schema: _this._objectDescURL, + resource: event.url + }; + + syncher.subscribe(input).then(function(dataObjectObserver) { console.info('1. Return Subscribe Data Object Observer', dataObjectObserver); _this._controllers[event.from].dataObjectObserver = dataObjectObserver; }).catch(function(reason) { @@ -159,7 +164,12 @@ class Connector { console.info('---------------- Syncher Subscribe (Auto Accept) ---------------- \n'); console.info('Subscribe URL Object ', event); - syncher.subscribe(_this._objectDescURL, event.url ).then(function(dataObjectObserver) { + let input = { + schema: _this._objectDescURL, + resource: event.url + }; + + syncher.subscribe(input).then(function(dataObjectObserver) { console.info('1. Return Subscribe Data Object Observer', dataObjectObserver); let connectionController = new ConnectionController(syncher, _this._domain, _this._configuration, _this._removeController, _this, event.from); diff --git a/src/dtwebrtc/DTWebRTC.hy.js b/src/dtwebrtc/DTWebRTC.hy.js index 6d7eb26..6e14f0b 100644 --- a/src/dtwebrtc/DTWebRTC.hy.js +++ b/src/dtwebrtc/DTWebRTC.hy.js @@ -71,7 +71,12 @@ class DTWebRTC extends EventEmitter { // extends EventEmitter because we need to setTimeout( () => { // Subscribe to Object - this._syncher.subscribe(this._objectDescURL, event.url).then((objObserver) => { + let input = { + schema: this._objectDescURL, + resource: event.url + }; + + this._syncher.subscribe(input).then((objObserver) => { console.info("[DTWebRTC]: [_onNotification] objObserver ", objObserver); // if successful, we get an observer object back this.objObserver = objObserver diff --git a/src/hello-world/HelloWorldObserver.hy.js b/src/hello-world/HelloWorldObserver.hy.js index c9fc575..df9deeb 100644 --- a/src/hello-world/HelloWorldObserver.hy.js +++ b/src/hello-world/HelloWorldObserver.hy.js @@ -64,8 +64,14 @@ class HelloWorldObserver extends EventEmitter { // Acknowledge reporter about the Invitation was received event.ack(); + let input = { + schema: _this._objectDescURL, + resource: event.url, + store: true, + p2p: false + }; // Subscribe Hello World Object - _this._syncher.subscribe(_this._objectDescURL, event.url, true, false).then(function(helloObjtObserver) { + _this._syncher.subscribe(input).then(function(helloObjtObserver) { // Hello World Object was subscribed console.info(helloObjtObserver); diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 6a2f1ba..1001229 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -134,7 +134,17 @@ class Wallet { if (reply.body.code == 200) { if (! resumedPrivate) { console.log('[Wallet] subscribe private'); - _this.syncher.subscribe(_this.objectDescURL, reply.body.reporter_url, true, false, true, false, null).then(function (obj) { + let input = { + schema: _this._objectDescURL, + resource: reply.body.reporter_url, + store: true, + p2p: false, + mutual: true, + domain_subscription: false, + identity: null + }; + + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscribe result :', obj); let updateBalance = { @@ -178,7 +188,17 @@ class Wallet { if (! resumedPublic) { console.log('[Wallet] subscribe public'); - _this.syncher.subscribe(_this.objectDescURL, reply.body.publics_url, true, false, true, false, null).then(function (obj) { + let input = { + schema: _this._objectDescURL, + resource: reply.body.publics_url, + store: true, + p2p: false, + mutual: true, + domain_subscription: false, + identity: null + }; + + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscription result public wallets :', obj); let updateWallets = { field: 'wallets', From 35c9a7729b54af71b9c5182bec0e3c416ff74bc6 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Thu, 18 Oct 2018 18:07:33 +0100 Subject: [PATCH 02/25] Wallet: fixed issue with subscribe --- src/wallet/Wallet.hy.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 1001229..200786c 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -135,13 +135,13 @@ class Wallet { if (! resumedPrivate) { console.log('[Wallet] subscribe private'); let input = { - schema: _this._objectDescURL, + schema: _this.objectDescURL, resource: reply.body.reporter_url, store: true, p2p: false, mutual: true, - domain_subscription: false, - identity: null + domain_subscription: false +// identity: null }; _this.syncher.subscribe(input).then(function (obj) { @@ -194,8 +194,8 @@ class Wallet { store: true, p2p: false, mutual: true, - domain_subscription: false, - identity: null + domain_subscription: false +// identity: null }; _this.syncher.subscribe(input).then(function (obj) { From 5c05ff32b1d51e73bb4b6be6e651f7c3b85a2ea3 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Thu, 18 Oct 2018 22:20:22 +0100 Subject: [PATCH 03/25] Wallet: public wallet subscription fix --- src/wallet/Wallet.hy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 200786c..bdbebfd 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -189,7 +189,7 @@ class Wallet { if (! resumedPublic) { console.log('[Wallet] subscribe public'); let input = { - schema: _this._objectDescURL, + schema: _this.objectDescURL, resource: reply.body.publics_url, store: true, p2p: false, From 7c0f4eab2e92e389bfbf871c4e34faea00749c82 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Fri, 19 Oct 2018 04:21:01 +0100 Subject: [PATCH 04/25] SimpleChat: added offline option --- src/simple-chat/SimpleChat.hy.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/simple-chat/SimpleChat.hy.js b/src/simple-chat/SimpleChat.hy.js index 1bad456..f072436 100644 --- a/src/simple-chat/SimpleChat.hy.js +++ b/src/simple-chat/SimpleChat.hy.js @@ -37,7 +37,7 @@ import Search from '../utils/Search';*/ import { UserInfo } from './UserInfo';*/ /** -* Hyperty Group Chat Manager API (HypertyChat) +* Hyperty Simple Chat API (HypertyChat) * @author Vitor Silva [vitor-t-silva@telecom.pt] * @version 0.1.0 */ @@ -59,6 +59,7 @@ class SimpleChat { _this.hypertyURL = hypertyURL; _this._runtimeURL = configuration.runtimeURL; _this._bus = bus; + _this._manager.offline = configuration.offline ? configuration.offline : false; _this._syncher.onNotification(function (event) { console.log('[SimpleChat] onNotification:', event); @@ -328,7 +329,7 @@ class SimpleChat { * @param {array} users Array of users to be invited to join the Group Chat. Users are identified with reTHINK User URL, like this format user:/// * @return {ChatController} A ChatController object as a Promise. */ - create(name, users, extra = {}) { + create(name, users, extra = { mutual: false }) { return this._manager.create(name, users, extra); @@ -360,7 +361,7 @@ class SimpleChat { * @return {ChatController} It returns the ChatController object as a Promise */ join(invitationURL) { - return this._manager.join(invitationURL); + return this._manager.join(invitationURL, false, ); } From 282d2503da77d0c13c1993584b46a15ca556863b Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Sun, 21 Oct 2018 18:52:11 +0100 Subject: [PATCH 05/25] SimpleChat adapted to use SimpleChatManager lib --- examples/simple-chat/demo.js | 18 ++++++++--------- src/simple-chat/SimpleChat.hy.js | 31 ++++++++++++++---------------- src/simple-chat/SimpleChat.hy.json | 2 +- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/examples/simple-chat/demo.js b/examples/simple-chat/demo.js index 8900ce2..838a0a9 100644 --- a/examples/simple-chat/demo.js +++ b/examples/simple-chat/demo.js @@ -195,12 +195,12 @@ function addParticipantEvent(event) { let participantEl = '
' + '
' + ' ' + - ' ' + + ' ' + '
' + - '
' + +/* '
' + ' ' + ' ' + - '
' + + '
' +*/ '
'; participants.append(participantEl); @@ -263,7 +263,8 @@ function createRoomEvent(event) { getSectionTpl().then(() => { console.log('[SimpleChatDemo - Create Room] - Section Template ready:', name, participants); const CRMaddressTickets = 'hyperty://sharing-cities-dsm/crm/tickets'; - return simpleChat.create(name, [{ user: CRMaddressTickets }]); +// return simpleChat.create(name, [{ user: CRMaddressTickets }]); + return simpleChat.create(name, users); }).then((chatController) => { let isOwner = true; @@ -372,9 +373,9 @@ function prepareChat(chatController, isOwner, toReload = null) { console.log('[SimpleChatDemo ] onUserAdded Event:', event); const participantHypertyURL = event.hypertyURL; if (chatController._dataObjectReporter) { - debugger; - const objectUrl = chatController._dataObjectReporter._url; - simpleChat.newParticipant('hyperty://sharing-cities-dsm/crm', participantHypertyURL, objectUrl); +// debugger; +// const objectUrl = chatController._dataObjectReporter._url; +// simpleChat.newParticipant('hyperty://sharing-cities-dsm/crm', participantHypertyURL, objectUrl); } processNewUser(event); @@ -861,9 +862,8 @@ function closeChat(chatController) { console.log('Chat closed: ', result); const participantHypertyURL = event.hypertyURL; if (chatController._dataObjectReporter) { - debugger; const objectUrl = chatController._dataObjectReporter._url; - simpleChat.closeTicket('hyperty://sharing-cities-dsm/crm', participantHypertyURL, objectUrl); +// simpleChat.closeTicket('hyperty://sharing-cities-dsm/crm', participantHypertyURL, objectUrl); } let createRoomModal = $('.create-chat'); diff --git a/src/simple-chat/SimpleChat.hy.js b/src/simple-chat/SimpleChat.hy.js index f072436..99058fe 100644 --- a/src/simple-chat/SimpleChat.hy.js +++ b/src/simple-chat/SimpleChat.hy.js @@ -37,7 +37,7 @@ import Search from '../utils/Search';*/ import { UserInfo } from './UserInfo';*/ /** -* Hyperty Simple Chat API (HypertyChat) +* Hyperty Group Chat Manager API (HypertyChat) * @author Vitor Silva [vitor-t-silva@telecom.pt] * @version 0.1.0 */ @@ -50,16 +50,15 @@ class SimpleChat { _this._factory = factory; _this._syncher = factory.createSyncher(hypertyURL, bus, configuration); - _this._manager = factory.createChatManager(hypertyURL, bus, configuration, _this._syncher); + _this._manager = factory.createSimpleChatManager(hypertyURL, bus, configuration, _this._syncher); _this.discovery = _this._manager.discovery; _this.identityManager = _this._manager.identityManager; - _this.search = _this._manager.search; +// _this.search = _this._manager.search; _this._domain = _this._manager._domain; _this._myUrl = hypertyURL; _this.hypertyURL = hypertyURL; _this._runtimeURL = configuration.runtimeURL; _this._bus = bus; - _this._manager.offline = configuration.offline ? configuration.offline : false; _this._syncher.onNotification(function (event) { console.log('[SimpleChat] onNotification:', event); @@ -196,7 +195,7 @@ class SimpleChat { console.log('[SimpleChat.resumeReporter]: ', dataObjectReporterURL); - let chatController = _this._factory.createChatController(_this._syncher, _this.discovery, _this._domain, _this.search, identity, _this._manager); + let chatController = _this._factory.createChat(_this._syncher, _this._domain, identity, _this._manager); chatController.dataObjectReporter = reporters[dataObjectReporterURL]; // Save the chat controllers by dataObjectReporterURL @@ -206,7 +205,7 @@ class SimpleChat { console.log('[SimpleChat] chatController invitationsHandler: ', chatController.invitationsHandler); - chatController.invitationsHandler.resumeDiscoveries(_this._manager.discovery, chatController.dataObjectReporter); +// chatController.invitationsHandler.resumeDiscoveries(_this._manager.discovery, chatController.dataObjectReporter); }); @@ -240,17 +239,18 @@ class SimpleChat { let chatObserver = observers[dataObjectObserverURL]; - let chatController = _this._factory.createChatController(_this._syncher, _this._manager.discovery, _this._domain, _this.search, identity, _this._manager); +// let chatController = _this._factory.createChatController(_this._syncher, _this._manager.discovery, _this._domain, _this.search, identity, _this._manager); + let chatController = _this._factory.createChat(_this._syncher, _this._domain, identity, _this._manager); chatController.dataObjectObserver = chatObserver; // Save the chat controllers by dataObjectReporterURL this._manager._observersControllers[dataObjectObserverURL] = chatController; - let reporterStatus = _this._factory.createRegistrationStatus(chatObserver.url, _this._runtimeURL, _this._myUrl, _this._bus); +// let reporterStatus = _this._factory.createRegistrationStatus(chatObserver.url, _this._runtimeURL, _this._myUrl, _this._bus); // recursive function to sync with chat reporter - let reporterSync = function (observer, subscriber, status) { +/* let reporterSync = function (observer, subscriber, status) { let statusOfReporter = status; observer.sync().then((synched) => { @@ -266,7 +266,7 @@ class SimpleChat { }); }; - reporterSync(chatObserver, _this._myUrl, reporterStatus); + reporterSync(chatObserver, _this._myUrl, reporterStatus);*/ }); @@ -326,14 +326,11 @@ class SimpleChat { /** * This function is used to create a new Group Chat providing the name and the identifiers of users to be invited. * @param {string} name Is a string to identify the Group Chat - * @param {array} users Array of users to be invited to join the Group Chat. Users are identified with reTHINK User URL, like this format user:/// + * @param {array} users Array of users to be invited to join the Group Chat. Users are identified with reTHINK User URL, like this format user:/// * @return {ChatController} A ChatController object as a Promise. */ - create(name, users, extra = { mutual: false }) { - return this._manager.create(name, users, extra); - - - + create(name, hyperties, extra = {mutual: false, domain_registration: false}) { + return this._manager.create(name, hyperties, extra); } @@ -361,7 +358,7 @@ class SimpleChat { * @return {ChatController} It returns the ChatController object as a Promise */ join(invitationURL) { - return this._manager.join(invitationURL, false, ); + return this._manager.join(invitationURL, false); } diff --git a/src/simple-chat/SimpleChat.hy.json b/src/simple-chat/SimpleChat.hy.json index cd2293b..300ee64 100644 --- a/src/simple-chat/SimpleChat.hy.json +++ b/src/simple-chat/SimpleChat.hy.json @@ -1,7 +1,7 @@ { "language": "javascript", "signature": "", - "configuration": { }, + "configuration": { "domain_registration": false }, "hypertyType": [ "chat" ], From 29947e10e7e68a312c380f54c1e5cef252895d63 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Sun, 21 Oct 2018 21:19:55 +0100 Subject: [PATCH 06/25] Added routing_domain input option --- src/learning/ElearningPlayer.hy.js | 10 +++++++++- src/location/LocationReporter.hy.js | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/learning/ElearningPlayer.hy.js b/src/learning/ElearningPlayer.hy.js index 75469d2..96522aa 100644 --- a/src/learning/ElearningPlayer.hy.js +++ b/src/learning/ElearningPlayer.hy.js @@ -113,7 +113,15 @@ class ElearningPlayer { let _this = this; if (_this.reporter == null) { - _this.syncher.create(_this.objectDescURL, [], {}, true, false, 'elearning', {}, { resources: ['learning-context'], "domain_registration": false }) + + let input = { + resources: ['learning-context'], + "domain_registration": false, + "domain_routing": false + }; + + + _this.syncher.create(_this.objectDescURL, [], {}, true, false, 'elearning', {}, input) .then((reporter) => { _this.reporter = reporter; console.log('[ElearningPlayer] DataObjectReporter', _this.reporter); diff --git a/src/location/LocationReporter.hy.js b/src/location/LocationReporter.hy.js index 916cebc..6422763 100644 --- a/src/location/LocationReporter.hy.js +++ b/src/location/LocationReporter.hy.js @@ -144,7 +144,13 @@ class LocationHypertyFactory { startPositionBroadcast() { let _this = this; if (_this.reporter == null) { - _this.syncher.create(_this.objectDescURL, [], position(), true, false, 'location', {}, { resources: ['location-context'], "domain_registration": false }) + let input = { + resources: ['location-context'], + "domain_registration": false, + "domain_routing": false + }; + + _this.syncher.create(_this.objectDescURL, [], position(), true, false, 'location', {}, input) .then((reporter) => { _this.reporter = reporter; console.log('[LocationReporter] DataObjectReporter', _this.reporter); @@ -167,7 +173,13 @@ class LocationHypertyFactory { let _this = this; if (_this.reporter == null) { - _this.syncher.create(_this.objectDescURL, [], position(), true, false, 'location', {}, { resources: ['location-context'], "domain_registration": false }) + let input = { + resources: ['location-context'], + "domain_registration": false, + "domain_routing": false + }; + + _this.syncher.create(_this.objectDescURL, [], position(), true, false, 'location', {}, input) .then((reporter) => { _this.reporter = reporter; console.log('[LocationReporter] DataObjectReporter', _this.reporter); From 880e33dfe92b56c0ffb2202333dff5133375942e Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Tue, 23 Oct 2018 15:41:42 +0100 Subject: [PATCH 07/25] testing offline --- src/hello-world/HelloWorldReporter.hy.js | 2 ++ src/simple-chat/SimpleChat.hy.js | 4 ++-- src/simple-chat/SimpleChat.hy.json | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hello-world/HelloWorldReporter.hy.js b/src/hello-world/HelloWorldReporter.hy.js index baef075..3476ab0 100644 --- a/src/hello-world/HelloWorldReporter.hy.js +++ b/src/hello-world/HelloWorldReporter.hy.js @@ -72,6 +72,8 @@ class HelloWorldReporter { let input = Object.assign({resources: ['hello']}, {}); input.backup = _this._backup; input.reuseURL = true; + input.mutual = false; + input.domain_registration = false; syncher.create(_this._objectDescURL, [hypertyURL], hello, true, false, 'hello', {}, input).then(function(helloObjtReporter) { console.info('1. Return Created Hello World Data Object Reporter', helloObjtReporter); diff --git a/src/simple-chat/SimpleChat.hy.js b/src/simple-chat/SimpleChat.hy.js index 99058fe..7956f56 100644 --- a/src/simple-chat/SimpleChat.hy.js +++ b/src/simple-chat/SimpleChat.hy.js @@ -68,7 +68,7 @@ class SimpleChat { _this._resumeReporters(); _this._resumeObservers(); - + _this._manager.offline = configuration.offline ? configuration.offline : false; } @@ -329,7 +329,7 @@ class SimpleChat { * @param {array} users Array of users to be invited to join the Group Chat. Users are identified with reTHINK User URL, like this format user:/// * @return {ChatController} A ChatController object as a Promise. */ - create(name, hyperties, extra = {mutual: false, domain_registration: false}) { + create(name, hyperties, extra = {mutual: false, domain_registration: false, reuseURL: true }) { return this._manager.create(name, hyperties, extra); } diff --git a/src/simple-chat/SimpleChat.hy.json b/src/simple-chat/SimpleChat.hy.json index 300ee64..92faf0b 100644 --- a/src/simple-chat/SimpleChat.hy.json +++ b/src/simple-chat/SimpleChat.hy.json @@ -1,7 +1,10 @@ { "language": "javascript", "signature": "", - "configuration": { "domain_registration": false }, + "configuration": { + "domain_registration": false, + "offline": "hyperty://sharing-cities-dsm/offline-sub-mgr" + }, "hypertyType": [ "chat" ], From 789c785cc8f6e584b6a7816b5b960f2e734c7b3a Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Thu, 25 Oct 2018 18:45:44 +0100 Subject: [PATCH 08/25] SimpleChat: removed domain_registration = dalse from config --- examples/simple-chat/demo.js | 3 ++- src/group-chat-manager/GroupChatManager.hy.json | 2 -- src/simple-chat/SimpleChat.hy.js | 4 +++- src/simple-chat/SimpleChat.hy.json | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/simple-chat/demo.js b/examples/simple-chat/demo.js index 838a0a9..fca27d9 100644 --- a/examples/simple-chat/demo.js +++ b/examples/simple-chat/demo.js @@ -264,7 +264,8 @@ function createRoomEvent(event) { console.log('[SimpleChatDemo - Create Room] - Section Template ready:', name, participants); const CRMaddressTickets = 'hyperty://sharing-cities-dsm/crm/tickets'; // return simpleChat.create(name, [{ user: CRMaddressTickets }]); - return simpleChat.create(name, users); +return simpleChat.create(name, users); +//return simpleChat.create(name, participants); }).then((chatController) => { let isOwner = true; diff --git a/src/group-chat-manager/GroupChatManager.hy.json b/src/group-chat-manager/GroupChatManager.hy.json index 84f37a5..ba7a295 100644 --- a/src/group-chat-manager/GroupChatManager.hy.json +++ b/src/group-chat-manager/GroupChatManager.hy.json @@ -2,8 +2,6 @@ "language": "javascript", "signature": "", "configuration": { - "backup": true, - "heartBeat": 60 }, "hypertyType": [ "chat" diff --git a/src/simple-chat/SimpleChat.hy.js b/src/simple-chat/SimpleChat.hy.js index 7956f56..1327930 100644 --- a/src/simple-chat/SimpleChat.hy.js +++ b/src/simple-chat/SimpleChat.hy.js @@ -50,6 +50,7 @@ class SimpleChat { _this._factory = factory; _this._syncher = factory.createSyncher(hypertyURL, bus, configuration); +// _this._manager = factory.createSimpleChatManager(hypertyURL, bus, configuration, _this._syncher); _this._manager = factory.createSimpleChatManager(hypertyURL, bus, configuration, _this._syncher); _this.discovery = _this._manager.discovery; _this.identityManager = _this._manager.identityManager; @@ -330,7 +331,8 @@ class SimpleChat { * @return {ChatController} A ChatController object as a Promise. */ create(name, hyperties, extra = {mutual: false, domain_registration: false, reuseURL: true }) { - return this._manager.create(name, hyperties, extra); +// create(name, hyperties, extra = {mutual: false, reuseURL: true }) { + return this._manager.create(name, hyperties, extra); } diff --git a/src/simple-chat/SimpleChat.hy.json b/src/simple-chat/SimpleChat.hy.json index 92faf0b..a29c234 100644 --- a/src/simple-chat/SimpleChat.hy.json +++ b/src/simple-chat/SimpleChat.hy.json @@ -2,7 +2,8 @@ "language": "javascript", "signature": "", "configuration": { - "domain_registration": false, + "backup": true, + "heartBeat": 60, "offline": "hyperty://sharing-cities-dsm/offline-sub-mgr" }, "hypertyType": [ From ccabb0b628e12fdf07a34ffb699d05d347816062 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 31 Oct 2018 14:25:29 +0000 Subject: [PATCH 09/25] eLearningDemo updated to invite eLearning backend --- examples/learning/learningPlayerDemo.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/learning/learningPlayerDemo.js b/examples/learning/learningPlayerDemo.js index f1502c2..925225b 100644 --- a/examples/learning/learningPlayerDemo.js +++ b/examples/learning/learningPlayerDemo.js @@ -13,21 +13,29 @@ function hypertyLoaded(result) { console.info('[LearningPlayerDemo] quizzes: ', result); + elearningPlayer._resumeReporters().then((result) => { - }).catch((reason) => { - console.info('[LearningPlayerDemo] start failed | ', reason); - }); + console.log('[LearningPlayerDemo] resume ', result); - elearningPlayer._resumeReporters().then((result) => { + if (result.length === 0 ) { + elearningPlayer.invite('hyperty://sharing-cities-dsm/elearning').then(() => { + console.log('[LearningPlayerDemo] invited "hyperty://sharing-cities-dsm/elearning"'); + }); + } - elearningPlayer.initQuizSubmission(); - - + elearningPlayer.initQuizSubmission(); + + }).catch((reason) => { + console.info('[LearningPlayerDemo] start failed | ', reason); + }); + + }).catch((reason) => { console.info('[LearningPlayerDemo] start failed | ', reason); }); + } From 749fcb91de1f5a0574e058dc79b1db0ca150f700 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 31 Oct 2018 14:30:14 +0000 Subject: [PATCH 10/25] eLearning Player demo: fix invite --- examples/learning/learningPlayerDemo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/learning/learningPlayerDemo.js b/examples/learning/learningPlayerDemo.js index 925225b..ce3a911 100644 --- a/examples/learning/learningPlayerDemo.js +++ b/examples/learning/learningPlayerDemo.js @@ -17,7 +17,7 @@ function hypertyLoaded(result) { console.log('[LearningPlayerDemo] resume ', result); - if (result.length === 0 ) { + if (!result ) { elearningPlayer.invite('hyperty://sharing-cities-dsm/elearning').then(() => { console.log('[LearningPlayerDemo] invited "hyperty://sharing-cities-dsm/elearning"'); }); From 6dd9d315c0ade62067f983ba71b4a5a0a9ff4c12 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 31 Oct 2018 15:44:10 +0000 Subject: [PATCH 11/25] eLearning updates --- examples/learning/learningPlayerDemo.js | 25 +++++++---------------- src/learning/ElearningPlayer.hy.js | 27 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/examples/learning/learningPlayerDemo.js b/examples/learning/learningPlayerDemo.js index ce3a911..1967d90 100644 --- a/examples/learning/learningPlayerDemo.js +++ b/examples/learning/learningPlayerDemo.js @@ -5,31 +5,20 @@ let elearningPlayer; function hypertyLoaded(result) { - console.log('LearningPlayer hyperty loaded!! ', result); + console.log('ElearningPlayer hyperty loaded!! ', result); elearningPlayer = result.instance; elearningPlayer.retrieveQuizzes('data://sharing-cities-dsm/elearning').then((result) => { - console.info('[LearningPlayerDemo] quizzes: ', result); + console.info('[ElearningPlayerDemo] quizzes: ', result); - elearningPlayer._resumeReporters().then((result) => { + elearningPlayer.initQuizSubmission().then(()=>{ + elearningPlayer.invite('hyperty://sharing-cities-dsm/elearning').then(() => { + console.log('[ElearningPlayerDemo] invited "hyperty://sharing-cities-dsm/elearning"'); + }); - console.log('[LearningPlayerDemo] resume ', result); - - if (!result ) { - elearningPlayer.invite('hyperty://sharing-cities-dsm/elearning').then(() => { - console.log('[LearningPlayerDemo] invited "hyperty://sharing-cities-dsm/elearning"'); - }); - } - - - - elearningPlayer.initQuizSubmission(); - - }).catch((reason) => { - console.info('[LearningPlayerDemo] start failed | ', reason); - }); + }) }).catch((reason) => { diff --git a/src/learning/ElearningPlayer.hy.js b/src/learning/ElearningPlayer.hy.js index 96522aa..0f42cbb 100644 --- a/src/learning/ElearningPlayer.hy.js +++ b/src/learning/ElearningPlayer.hy.js @@ -87,7 +87,7 @@ class ElearningPlayer { return new Promise((resolve) => { - function keepTrying() { +/* function keepTrying() { _this.reporter.invitations = []; _this.reporter.inviteObservers([observer]); @@ -100,27 +100,39 @@ class ElearningPlayer { keepTrying(); }, 100); }); + }*/ + + if (_this.reporter) { + console.log('[ElearningPlayer.invite] reporter ', _this.reporter) + _this.reporter.inviteObservers([observer]) + console.info('[ElearningPlayer] invited: ', observer); + + resolve(); + + } else { + reject('[ElearningPlayer.invite] Reporter not created yet'); } - keepTrying(); }); } initQuizSubmission() { + let _this = this; + return new Promise((resolve) => { + _this._resumeReporters().then((result) => { - let _this = this; - if (_this.reporter == null) { + console.log('[ElearningPlayer] resume ', result); - let input = { + if (!result) { + let input = { resources: ['learning-context'], "domain_registration": false, "domain_routing": false }; - _this.syncher.create(_this.objectDescURL, [], {}, true, false, 'elearning', {}, input) .then((reporter) => { _this.reporter = reporter; @@ -135,7 +147,8 @@ class ElearningPlayer { resolve(true); } }); - } + }); +} answer(id, answers) { From 78ef1af52effe456745da70885ab533f034a9b63 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Mon, 5 Nov 2018 22:30:03 +0000 Subject: [PATCH 12/25] SimpleChat updated to support backup --- src/simple-chat/SimpleChat.hy.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/simple-chat/SimpleChat.hy.js b/src/simple-chat/SimpleChat.hy.js index 1327930..d99c60b 100644 --- a/src/simple-chat/SimpleChat.hy.js +++ b/src/simple-chat/SimpleChat.hy.js @@ -69,8 +69,12 @@ class SimpleChat { _this._resumeReporters(); _this._resumeObservers(); + console.log('[SimpleChat] configuration ', configuration); + _this._manager.offline = configuration.offline ? configuration.offline : false; + _this._manager.backup = configuration.backup ? configuration.backup : false; + } From fb008d4ed75e5193ea5c11790f24dfbbf4ecf6ee Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Mon, 12 Nov 2018 15:13:42 +0000 Subject: [PATCH 13/25] wallet example set cause --- examples/wallet/wallet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/wallet/wallet.js b/examples/wallet/wallet.js index cdbd835..433e3b9 100644 --- a/examples/wallet/wallet.js +++ b/examples/wallet/wallet.js @@ -31,7 +31,7 @@ function hypertyReady(result, identity) { } } - const profileInfo = { ageRange: '18-25', workplace: 'Lisbon', cause: '0', balance: 10 }; + const profileInfo = { ageRange: '18-25', workplace: 'Lisbon', cause: 'user-guid://school-0', balance: 10 }; identity.profile = profileInfo; result.instance.start(afterUpdate, identity); From 2980a6fd3776f129281cc5b3aa1de326fbdca9dc Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Sat, 17 Nov 2018 11:31:26 +0000 Subject: [PATCH 14/25] UserActivityObserverDemo: fixed log --- examples/user-activity/UserActivityObserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/user-activity/UserActivityObserver.js b/examples/user-activity/UserActivityObserver.js index 67627c4..14aa929 100644 --- a/examples/user-activity/UserActivityObserver.js +++ b/examples/user-activity/UserActivityObserver.js @@ -26,7 +26,7 @@ function hypertyLoaded(result, runtimeLoader = null) { runtimeLoader.authorise('google.com', 'user_activity_context').then(function(value) { }).catch(function(err) { - log.log(err); + console.log(err); }); From b90d8038e6490181825de542d495cbdf00163db0 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Tue, 20 Nov 2018 22:03:04 +0000 Subject: [PATCH 15/25] Wallet.start fix --- src/wallet/Wallet.hy.js | 334 ++++++++++++++++++++++------------------ 1 file changed, 181 insertions(+), 153 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index bdbebfd..6d5bc72 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -24,199 +24,227 @@ class Wallet { this.messageRetries = config.retries; } + _resumePrivateWallet(user, callback) { - start(callback, identity) { let _this = this; return new Promise((resolve, reject) => { - let userProfile; - let publicWallets = false; - if (identity.profile !== undefined) { - if (identity.profile.guid === 'user-guid://public-wallets') { - userProfile = identity.profile; - publicWallets = true; - } else { - userProfile = { userURL: identity.userURL, guid: identity.guid, info: identity.profile }; - } - } else { - userProfile = { userURL: identity.userURL, guid: identity.guid }; - } - _this.identity = { userProfile: userProfile }; + _this._resumeObservers(user).then(function (result) { + console.log('[Wallet] private Resume result :', result); + if (result) { + resumedPrivate = true; - let createMessage = { - type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, - identity: { userProfile: userProfile }, - body: { - type: 'create', - from: _this.hypertyURL, - resource: 'wallet' - } - }; - let resumedPrivate = false; - let resumedPublic = false; - _this._resumeObservers(_this.identity.userProfile.userURL).then(function (result) { - console.log('[Wallet] private Resume result :', result); - if (result != false) { - resumedPrivate = true; + let updateBalance = { + field: 'balance', + data: result.data.balance + }; + let updateTransactions = { + field: 'transactions', + data: result.data.transactions + }; - let updateBalance = { - field: 'balance', - data: result.data.balance - }; + let updateRanking = { + field: 'ranking', + data: result.data.ranking + }; - let updateTransactions = { - field: 'transactions', - data: result.data.transactions - }; + let updateBonusCredit = { + field: 'bonus-credit', + data: result.data['bonus-credit'] + }; - let updateRanking = { - field: 'ranking', - data: result.data.ranking - }; + callback(updateBalance); + callback(updateTransactions); + callback(updateRanking); + callback(updateBonusCredit); - let updateBonusCredit = { - field: 'bonus-credit', - data: result.data['bonus-credit'] - }; - callback(updateBalance); - callback(updateTransactions); - callback(updateRanking); - callback(updateBonusCredit); + result.onChange('*', (event) => { + console.log('[Wallet] New Change :', event); + callback(event); + }); + resolve(true); - result.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); - callback(event); - }); + } else resolve(false); - } + }).catch(function (error) { + console.log('[Wallet] ', error); + resolve(false); + }); + }); - }).catch(function (error) { - console.log('[Wallet] ', error); - }); + } - _this._resumeObservers(_this.pubsUrl).then(function (result) { + _resumePublicWallet(url, callback) { - console.log('[Wallet] public resume wallets :', result); - if (result != false) { - resumedPublic = true; + let _this = this; + + return new Promise((resolve, reject) => { + _this._resumeObservers(url).then(function (result) { + console.log('[Wallet] public resume wallets :', result); + if (result) { + let updateWallets = { field: 'wallets', data: result.data.wallets }; - + callback(updateWallets); - + result.onChange('*', (event) => { console.log('[Wallet] New Change :', event); callback(event); }); - } - + resolve(true); + } else resolve(false); + }).catch(function (error) { console.log('[Wallet] ', error); + resolve(false); }); + }); - console.log('[Wallet] create message', createMessage); - - _this.bus.postMessageWithRetries(createMessage, _this.messageRetries, (reply) => { - - // store address - _this.walletAddress = reply.body.wallet.address; - - console.log('[Wallet] create Reply', reply); - if (reply.body.code == 200) { - if (! resumedPrivate) { - console.log('[Wallet] subscribe private'); - let input = { - schema: _this.objectDescURL, - resource: reply.body.reporter_url, - store: true, - p2p: false, - mutual: true, - domain_subscription: false -// identity: null - }; - - _this.syncher.subscribe(input).then(function (obj) { - console.log('[Wallet] subscribe result :', obj); - - let updateBalance = { - field: 'balance', - data: obj.data.balance - }; - - let updateTransactions = { - field: 'transactions', - data: obj.data.transactions - }; - - let updateRanking = { - field: 'ranking', - data: obj.data.ranking - }; - - let updateBonusCredit = { - field: 'bonus-credit', - data: obj.data['bonus-credit'] - }; - - callback(updateBalance); - callback(updateTransactions); - callback(updateRanking); - callback(updateBonusCredit); - - obj.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); - callback(event); - }); - - - }).catch(function (error) { - console.log('[Wallet] error', error); - reject(); + } - }); - } - if (! resumedPublic) { - console.log('[Wallet] subscribe public'); - let input = { - schema: _this.objectDescURL, - resource: reply.body.publics_url, - store: true, - p2p: false, - mutual: true, - domain_subscription: false -// identity: null - }; - - _this.syncher.subscribe(input).then(function (obj) { - console.log('[Wallet] subscription result public wallets :', obj); - let updateWallets = { - field: 'wallets', - data: obj.data.wallets - }; - - callback(updateWallets); - - obj.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); - callback(event); - }); - }); - } + start(callback, identity) { + let _this = this; - resolve(reply); + return new Promise((resolve, reject) => { + let userProfile; + let publicWallets = false; + if (identity.profile !== undefined) { + if (identity.profile.guid === 'user-guid://public-wallets') { + userProfile = identity.profile; + publicWallets = true; + } else { + userProfile = { userURL: identity.userURL, guid: identity.guid, info: identity.profile }; + } + } else { + userProfile = { userURL: identity.userURL, guid: identity.guid }; + } + _this.identity = { userProfile: userProfile }; + let createMessage = { + type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, + identity: { userProfile: userProfile }, + body: { + type: 'create', + from: _this.hypertyURL, + resource: 'wallet' } + }; + let resumedPrivate = false; + let resumedPublic = false; + + _this._resumePrivateWallet(_this.identity.userProfile.userURL, callback).then((resumed)=>{ + resumedPrivate = resumed; + _this._resumePublicWallet(_this.pubsUrl, callback).then((resumed)=>{ + resumedPublic = resumed; + console.log('[Wallet] create message', createMessage); + + _this.bus.postMessageWithRetries(createMessage, _this.messageRetries, (reply) => { + + // store address + _this.walletAddress = reply.body.wallet.address; + + console.log('[Wallet] create Reply', reply); + if (reply.body.code == 200) { + if (! resumedPrivate) { + console.log('[Wallet] subscribe private'); + let input = { + schema: _this.objectDescURL, + resource: reply.body.reporter_url, + store: true, + p2p: false, + mutual: false, + domain_subscription: false + // identity: null + }; + + _this.syncher.subscribe(input).then(function (obj) { + console.log('[Wallet] subscribe result :', obj); + + let updateBalance = { + field: 'balance', + data: obj.data.balance + }; + + let updateTransactions = { + field: 'transactions', + data: obj.data.transactions + }; + + let updateRanking = { + field: 'ranking', + data: obj.data.ranking + }; + + let updateBonusCredit = { + field: 'bonus-credit', + data: obj.data['bonus-credit'] + }; + + callback(updateBalance); + callback(updateTransactions); + callback(updateRanking); + callback(updateBonusCredit); + + obj.onChange('*', (event) => { + console.log('[Wallet] New Change :', event); + callback(event); + }); + + + + }).catch(function (error) { + console.log('[Wallet] error', error); + reject(); + + }); + } + + if (! resumedPublic) { + console.log('[Wallet] subscribe public'); + let input = { + schema: _this.objectDescURL, + resource: reply.body.publics_url, + store: true, + p2p: false, + mutual: false, + domain_subscription: false + // identity: null + }; + + _this.syncher.subscribe(input).then(function (obj) { + console.log('[Wallet] subscription result public wallets :', obj); + let updateWallets = { + field: 'wallets', + data: obj.data.wallets + }; + + callback(updateWallets); + + obj.onChange('*', (event) => { + console.log('[Wallet] New Change :', event); + callback(event); + }); + }); + } + + resolve(reply); + + } + }); + + }); }); }); From e9e8c5ae66be6f2411d803e0760571cc4425fe2a Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Wed, 21 Nov 2018 10:46:48 +0000 Subject: [PATCH 16/25] fixed bug in resumePrivateWallet --- src/wallet/Wallet.hy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 6d5bc72..040bdc3 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -32,8 +32,6 @@ class Wallet { _this._resumeObservers(user).then(function (result) { console.log('[Wallet] private Resume result :', result); if (result) { - resumedPrivate = true; - let updateBalance = { field: 'balance', From 4444f871e368a29b891868f16f1be6098f994010 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 21 Nov 2018 13:46:34 +0000 Subject: [PATCH 17/25] wallet: logs added --- src/wallet/Wallet.hy.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 040bdc3..639dd82 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -60,7 +60,7 @@ class Wallet { result.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); + console.log('[Wallet] New Change on Private: ', event); callback(event); }); @@ -94,7 +94,7 @@ class Wallet { callback(updateWallets); result.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); + console.log('[Wallet] New Change on Public :', event); callback(event); }); resolve(true); @@ -168,7 +168,7 @@ class Wallet { }; _this.syncher.subscribe(input).then(function (obj) { - console.log('[Wallet] subscribe result :', obj); + console.log('[Wallet] subscribe private result :', obj); let updateBalance = { field: 'balance', @@ -196,14 +196,14 @@ class Wallet { callback(updateBonusCredit); obj.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); + console.log('[Wallet] Private New Change :', event); callback(event); }); }).catch(function (error) { - console.log('[Wallet] error', error); + console.log('[Wallet] Private error', error); reject(); }); @@ -231,7 +231,7 @@ class Wallet { callback(updateWallets); obj.onChange('*', (event) => { - console.log('[Wallet] New Change :', event); + console.log('[Wallet] Public New Change :', event); callback(event); }); }); From 24c5e797a8d4c2f1b473502778e62a98630ed5d7 Mon Sep 17 00:00:00 2001 From: Paulo Chainho Date: Wed, 21 Nov 2018 15:40:45 +0000 Subject: [PATCH 18/25] logs added --- src/wallet/Wallet.hy.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 639dd82..e6da20a 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -136,7 +136,9 @@ class Wallet { body: { type: 'create', from: _this.hypertyURL, - resource: 'wallet' + resource: 'wallet', + body: { mutual: false }, + mutual: false } }; let resumedPrivate = false; @@ -254,7 +256,7 @@ class Wallet { return new Promise((resolve, reject) => { - if (_this.identity != null ) { +/* if (_this.identity != null ) { let updateMessage = { type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, identity: _this.identity, @@ -270,13 +272,13 @@ class Wallet { _this.bus.postMessageWithRetries(updateMessage, _this.messageRetries, (reply) => { - console.log('[Wallet] update Reply', reply); + console.log('[Wallet] update Reply', reply);*/ resolve(true); - +/* }); } else { resolve(false); - } + }*/ }); From 9ddca2b59b5e73ed72b962e35f81706f76e552b5 Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Wed, 21 Nov 2018 16:08:13 +0000 Subject: [PATCH 19/25] wallet.accounts --- src/wallet/Wallet.hy.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 639dd82..630d657 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -53,10 +53,16 @@ class Wallet { data: result.data['bonus-credit'] }; + let updateAccounts = { + field: 'accounts', + data: result.data.accounts + }; + callback(updateBalance); callback(updateTransactions); callback(updateRanking); callback(updateBonusCredit); + callback(updateAccounts); result.onChange('*', (event) => { @@ -189,11 +195,17 @@ class Wallet { field: 'bonus-credit', data: obj.data['bonus-credit'] }; + + let updateAccounts = { + field: 'accounts', + data: obj.data.accounts + }; callback(updateBalance); callback(updateTransactions); callback(updateRanking); callback(updateBonusCredit); + callback(updateAccounts); obj.onChange('*', (event) => { console.log('[Wallet] Private New Change :', event); From 8ff311181044f7103ed85228f8b80652a60fda48 Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Thu, 22 Nov 2018 10:03:59 +0000 Subject: [PATCH 20/25] wallet example w/ accounts --- examples/wallet/Wallet.hbs | 1 + examples/wallet/wallet.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/wallet/Wallet.hbs b/examples/wallet/Wallet.hbs index 480d955..dc76365 100644 --- a/examples/wallet/Wallet.hbs +++ b/examples/wallet/Wallet.hbs @@ -6,6 +6,7 @@

- Tokens: -

- Ranking: -

- Bonus credit: -

+

- # Accounts: -

diff --git a/examples/wallet/wallet.js b/examples/wallet/wallet.js index 433e3b9..90ffbb0 100644 --- a/examples/wallet/wallet.js +++ b/examples/wallet/wallet.js @@ -21,11 +21,13 @@ function hypertyReady(result, identity) { console.log('Wallet new update', event); if (event.field == 'balance') { $('.token-value').text(event.data); - } else if (event.field == 'ranking') { $('.wallet-ranking').text(event.data); } + else if (event.field == 'accounts') { + $('.accounts').text(event.data.length); + } else if (event.field == 'bonus-credit') { $('.bonus-credit').text(event.data); } From 624475ff091123a426d9c135cda96d8110dee2df Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Mon, 26 Nov 2018 13:33:50 +0000 Subject: [PATCH 21/25] Wallet.readWallet() --- examples/wallet/Wallet.hbs | 1 + examples/wallet/wallet.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/examples/wallet/Wallet.hbs b/examples/wallet/Wallet.hbs index dc76365..2eb0e1a 100644 --- a/examples/wallet/Wallet.hbs +++ b/examples/wallet/Wallet.hbs @@ -9,5 +9,6 @@

- # Accounts: -

+ diff --git a/examples/wallet/wallet.js b/examples/wallet/wallet.js index 90ffbb0..5aac66a 100644 --- a/examples/wallet/wallet.js +++ b/examples/wallet/wallet.js @@ -45,6 +45,13 @@ function hypertyReady(result, identity) { }); + $('.wallet-read').click(function () { + result.instance.readWallet().then(function (result) { + console.log('Wallet read from DB: ', result); + }); + }); + + // get public wallets /* console.log('Wallet hyperty Ready', result, identity); From 0814c000228f68f78ac7db8e7a09e88298d1c15b Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Mon, 26 Nov 2018 13:34:26 +0000 Subject: [PATCH 22/25] Wallet.readWallet() --- src/wallet/Wallet.hy.js | 178 ++++++++++++++++++++++++---------------- 1 file changed, 109 insertions(+), 69 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 630d657..f06bc87 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -31,53 +31,53 @@ class Wallet { return new Promise((resolve, reject) => { _this._resumeObservers(user).then(function (result) { console.log('[Wallet] private Resume result :', result); - if (result) { + if (result) { - let updateBalance = { - field: 'balance', - data: result.data.balance - }; + let updateBalance = { + field: 'balance', + data: result.data.balance + }; - let updateTransactions = { - field: 'transactions', - data: result.data.transactions - }; + let updateTransactions = { + field: 'transactions', + data: result.data.transactions + }; - let updateRanking = { - field: 'ranking', - data: result.data.ranking - }; + let updateRanking = { + field: 'ranking', + data: result.data.ranking + }; - let updateBonusCredit = { - field: 'bonus-credit', - data: result.data['bonus-credit'] - }; + let updateBonusCredit = { + field: 'bonus-credit', + data: result.data['bonus-credit'] + }; - let updateAccounts = { - field: 'accounts', - data: result.data.accounts - }; + let updateAccounts = { + field: 'accounts', + data: result.data.accounts + }; - callback(updateBalance); - callback(updateTransactions); - callback(updateRanking); - callback(updateBonusCredit); - callback(updateAccounts); + callback(updateBalance); + callback(updateTransactions); + callback(updateRanking); + callback(updateBonusCredit); + callback(updateAccounts); - result.onChange('*', (event) => { - console.log('[Wallet] New Change on Private: ', event); - callback(event); - }); + result.onChange('*', (event) => { + console.log('[Wallet] New Change on Private: ', event); + callback(event); + }); - resolve(true); + resolve(true); - } else resolve(false); + } else resolve(false); - }).catch(function (error) { - console.log('[Wallet] ', error); - resolve(false); - }); + }).catch(function (error) { + console.log('[Wallet] ', error); + resolve(false); + }); }); } @@ -91,21 +91,21 @@ class Wallet { console.log('[Wallet] public resume wallets :', result); if (result) { - + let updateWallets = { field: 'wallets', data: result.data.wallets }; - + callback(updateWallets); - + result.onChange('*', (event) => { console.log('[Wallet] New Change on Public :', event); callback(event); }); resolve(true); } else resolve(false); - + }).catch(function (error) { console.log('[Wallet] ', error); resolve(false); @@ -145,23 +145,23 @@ class Wallet { resource: 'wallet' } }; - let resumedPrivate = false; - let resumedPublic = false; + let resumedPrivate = false; + let resumedPublic = false; - _this._resumePrivateWallet(_this.identity.userProfile.userURL, callback).then((resumed)=>{ + _this._resumePrivateWallet(_this.identity.userProfile.userURL, callback).then((resumed) => { resumedPrivate = resumed; - _this._resumePublicWallet(_this.pubsUrl, callback).then((resumed)=>{ + _this._resumePublicWallet(_this.pubsUrl, callback).then((resumed) => { resumedPublic = resumed; console.log('[Wallet] create message', createMessage); _this.bus.postMessageWithRetries(createMessage, _this.messageRetries, (reply) => { - + // store address _this.walletAddress = reply.body.wallet.address; - + console.log('[Wallet] create Reply', reply); if (reply.body.code == 200) { - if (! resumedPrivate) { + if (!resumedPrivate) { console.log('[Wallet] subscribe private'); let input = { schema: _this.objectDescURL, @@ -170,27 +170,27 @@ class Wallet { p2p: false, mutual: false, domain_subscription: false - // identity: null + // identity: null }; - + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscribe private result :', obj); - + let updateBalance = { field: 'balance', data: obj.data.balance }; - + let updateTransactions = { field: 'transactions', data: obj.data.transactions }; - + let updateRanking = { field: 'ranking', data: obj.data.ranking }; - + let updateBonusCredit = { field: 'bonus-credit', data: obj.data['bonus-credit'] @@ -200,28 +200,28 @@ class Wallet { field: 'accounts', data: obj.data.accounts }; - + callback(updateBalance); callback(updateTransactions); callback(updateRanking); callback(updateBonusCredit); callback(updateAccounts); - + obj.onChange('*', (event) => { console.log('[Wallet] Private New Change :', event); callback(event); }); - - - + + + }).catch(function (error) { console.log('[Wallet] Private error', error); reject(); - + }); } - - if (! resumedPublic) { + + if (!resumedPublic) { console.log('[Wallet] subscribe public'); let input = { schema: _this.objectDescURL, @@ -230,30 +230,30 @@ class Wallet { p2p: false, mutual: false, domain_subscription: false - // identity: null + // identity: null }; - + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscription result public wallets :', obj); let updateWallets = { field: 'wallets', data: obj.data.wallets }; - + callback(updateWallets); - + obj.onChange('*', (event) => { console.log('[Wallet] Public New Change :', event); callback(event); }); }); } - + resolve(reply); - + } }); - + }); }); @@ -266,7 +266,7 @@ class Wallet { return new Promise((resolve, reject) => { - if (_this.identity != null ) { + if (_this.identity != null) { let updateMessage = { type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, identity: _this.identity, @@ -322,6 +322,46 @@ class Wallet { } + readWallet() { + + let _this = this; + + return new Promise((resolve, reject) => { + + let readMessage = { + // type: 'forward', to: _this.walletAddress + '/subscription', from: _this.hypertyURL, + type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, + // identity: { userProfile: userProfile }, + body: { + type: 'read', + from: _this.hypertyURL, + to: _this.walletAddress + '/subscription', + body: { + resource: 'wallet', + value: _this.walletAddress, + from: _this.hypertyURL + }, + identity: {}, + resource: 'wallet', + value: _this.walletAddress + } + }; + + + console.log('[Wallet] read message', readMessage); + + _this.bus.postMessageWithRetries(readMessage, _this.messageRetries, (reply) => { + + console.log('[Wallet] read message Reply', reply.body.value); + resolve(reply.body.value); + + }); + + }) + + } + + _resumeObservers(walletURL) { let _this = this; From 41cf1bedfd8e05fc1f6ea7f1291e602f212222e3 Mon Sep 17 00:00:00 2001 From: RAFAEL SALGUEIRO FELGUEIRAS PINTO Date: Mon, 26 Nov 2018 17:05:57 +0000 Subject: [PATCH 23/25] fixed readWallet() --- src/wallet/Wallet.hy.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index f06bc87..1f87b56 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -335,13 +335,13 @@ class Wallet { body: { type: 'read', from: _this.hypertyURL, - to: _this.walletAddress + '/subscription', + to: _this.walletAddress, body: { resource: 'wallet', value: _this.walletAddress, from: _this.hypertyURL }, - identity: {}, + identity: { userProfile: { guid: 'user-guid://' + _this.walletAddress } }, resource: 'wallet', value: _this.walletAddress } @@ -353,7 +353,7 @@ class Wallet { _this.bus.postMessageWithRetries(readMessage, _this.messageRetries, (reply) => { console.log('[Wallet] read message Reply', reply.body.value); - resolve(reply.body.value); + resolve(reply.body.value.body.wallet); }); From 027f74f6863c2a5a6f4c9e78476c10abf66fd4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Wed, 28 Nov 2018 10:51:06 +0000 Subject: [PATCH 24/25] Revert "Accounts" --- examples/wallet/Wallet.hbs | 1 - examples/wallet/wallet.js | 7 -- src/wallet/Wallet.hy.js | 178 ++++++++++++++----------------------- 3 files changed, 69 insertions(+), 117 deletions(-) diff --git a/examples/wallet/Wallet.hbs b/examples/wallet/Wallet.hbs index 2eb0e1a..dc76365 100644 --- a/examples/wallet/Wallet.hbs +++ b/examples/wallet/Wallet.hbs @@ -9,6 +9,5 @@

- # Accounts: -

- diff --git a/examples/wallet/wallet.js b/examples/wallet/wallet.js index 5aac66a..90ffbb0 100644 --- a/examples/wallet/wallet.js +++ b/examples/wallet/wallet.js @@ -45,13 +45,6 @@ function hypertyReady(result, identity) { }); - $('.wallet-read').click(function () { - result.instance.readWallet().then(function (result) { - console.log('Wallet read from DB: ', result); - }); - }); - - // get public wallets /* console.log('Wallet hyperty Ready', result, identity); diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index f06bc87..630d657 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -31,53 +31,53 @@ class Wallet { return new Promise((resolve, reject) => { _this._resumeObservers(user).then(function (result) { console.log('[Wallet] private Resume result :', result); - if (result) { + if (result) { - let updateBalance = { - field: 'balance', - data: result.data.balance - }; + let updateBalance = { + field: 'balance', + data: result.data.balance + }; - let updateTransactions = { - field: 'transactions', - data: result.data.transactions - }; + let updateTransactions = { + field: 'transactions', + data: result.data.transactions + }; - let updateRanking = { - field: 'ranking', - data: result.data.ranking - }; + let updateRanking = { + field: 'ranking', + data: result.data.ranking + }; - let updateBonusCredit = { - field: 'bonus-credit', - data: result.data['bonus-credit'] - }; + let updateBonusCredit = { + field: 'bonus-credit', + data: result.data['bonus-credit'] + }; - let updateAccounts = { - field: 'accounts', - data: result.data.accounts - }; + let updateAccounts = { + field: 'accounts', + data: result.data.accounts + }; - callback(updateBalance); - callback(updateTransactions); - callback(updateRanking); - callback(updateBonusCredit); - callback(updateAccounts); + callback(updateBalance); + callback(updateTransactions); + callback(updateRanking); + callback(updateBonusCredit); + callback(updateAccounts); - result.onChange('*', (event) => { - console.log('[Wallet] New Change on Private: ', event); - callback(event); - }); + result.onChange('*', (event) => { + console.log('[Wallet] New Change on Private: ', event); + callback(event); + }); - resolve(true); + resolve(true); - } else resolve(false); + } else resolve(false); - }).catch(function (error) { - console.log('[Wallet] ', error); - resolve(false); - }); + }).catch(function (error) { + console.log('[Wallet] ', error); + resolve(false); + }); }); } @@ -91,21 +91,21 @@ class Wallet { console.log('[Wallet] public resume wallets :', result); if (result) { - + let updateWallets = { field: 'wallets', data: result.data.wallets }; - + callback(updateWallets); - + result.onChange('*', (event) => { console.log('[Wallet] New Change on Public :', event); callback(event); }); resolve(true); } else resolve(false); - + }).catch(function (error) { console.log('[Wallet] ', error); resolve(false); @@ -145,23 +145,23 @@ class Wallet { resource: 'wallet' } }; - let resumedPrivate = false; - let resumedPublic = false; + let resumedPrivate = false; + let resumedPublic = false; - _this._resumePrivateWallet(_this.identity.userProfile.userURL, callback).then((resumed) => { + _this._resumePrivateWallet(_this.identity.userProfile.userURL, callback).then((resumed)=>{ resumedPrivate = resumed; - _this._resumePublicWallet(_this.pubsUrl, callback).then((resumed) => { + _this._resumePublicWallet(_this.pubsUrl, callback).then((resumed)=>{ resumedPublic = resumed; console.log('[Wallet] create message', createMessage); _this.bus.postMessageWithRetries(createMessage, _this.messageRetries, (reply) => { - + // store address _this.walletAddress = reply.body.wallet.address; - + console.log('[Wallet] create Reply', reply); if (reply.body.code == 200) { - if (!resumedPrivate) { + if (! resumedPrivate) { console.log('[Wallet] subscribe private'); let input = { schema: _this.objectDescURL, @@ -170,27 +170,27 @@ class Wallet { p2p: false, mutual: false, domain_subscription: false - // identity: null + // identity: null }; - + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscribe private result :', obj); - + let updateBalance = { field: 'balance', data: obj.data.balance }; - + let updateTransactions = { field: 'transactions', data: obj.data.transactions }; - + let updateRanking = { field: 'ranking', data: obj.data.ranking }; - + let updateBonusCredit = { field: 'bonus-credit', data: obj.data['bonus-credit'] @@ -200,28 +200,28 @@ class Wallet { field: 'accounts', data: obj.data.accounts }; - + callback(updateBalance); callback(updateTransactions); callback(updateRanking); callback(updateBonusCredit); callback(updateAccounts); - + obj.onChange('*', (event) => { console.log('[Wallet] Private New Change :', event); callback(event); }); - - - + + + }).catch(function (error) { console.log('[Wallet] Private error', error); reject(); - + }); } - - if (!resumedPublic) { + + if (! resumedPublic) { console.log('[Wallet] subscribe public'); let input = { schema: _this.objectDescURL, @@ -230,30 +230,30 @@ class Wallet { p2p: false, mutual: false, domain_subscription: false - // identity: null + // identity: null }; - + _this.syncher.subscribe(input).then(function (obj) { console.log('[Wallet] subscription result public wallets :', obj); let updateWallets = { field: 'wallets', data: obj.data.wallets }; - + callback(updateWallets); - + obj.onChange('*', (event) => { console.log('[Wallet] Public New Change :', event); callback(event); }); }); } - + resolve(reply); - + } }); - + }); }); @@ -266,7 +266,7 @@ class Wallet { return new Promise((resolve, reject) => { - if (_this.identity != null) { + if (_this.identity != null ) { let updateMessage = { type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, identity: _this.identity, @@ -322,46 +322,6 @@ class Wallet { } - readWallet() { - - let _this = this; - - return new Promise((resolve, reject) => { - - let readMessage = { - // type: 'forward', to: _this.walletAddress + '/subscription', from: _this.hypertyURL, - type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, - // identity: { userProfile: userProfile }, - body: { - type: 'read', - from: _this.hypertyURL, - to: _this.walletAddress + '/subscription', - body: { - resource: 'wallet', - value: _this.walletAddress, - from: _this.hypertyURL - }, - identity: {}, - resource: 'wallet', - value: _this.walletAddress - } - }; - - - console.log('[Wallet] read message', readMessage); - - _this.bus.postMessageWithRetries(readMessage, _this.messageRetries, (reply) => { - - console.log('[Wallet] read message Reply', reply.body.value); - resolve(reply.body.value); - - }); - - }) - - } - - _resumeObservers(walletURL) { let _this = this; From bf44b4c3c38a25ebffb8cfed6500b35c4066c271 Mon Sep 17 00:00:00 2001 From: suil Date: Thu, 29 Nov 2018 09:27:20 +0000 Subject: [PATCH 25/25] new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8342525..da70548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dev-hyperty", - "version": "0.6.0", + "version": "0.7.0", "description": "Source code of hyperties", "main": ".eslintrc.js", "directories": {