diff --git a/examples/device-manager/DeviceManager.hbs b/examples/device-manager/DeviceManager.hbs index 3189786..66105ec 100644 --- a/examples/device-manager/DeviceManager.hbs +++ b/examples/device-manager/DeviceManager.hbs @@ -1,6 +1,36 @@ -
-

Wallet Hyperty Deployed

-
+
+

Device Manager

+
Device Info
+ +
+ +
+
+
Streams Info
+
List
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+
+
+
-Wallet Tokens -X + +
diff --git a/examples/device-manager/DeviceManagerDemo.js b/examples/device-manager/DeviceManagerDemo.js index f16f7fc..bc669d3 100644 --- a/examples/device-manager/DeviceManagerDemo.js +++ b/examples/device-manager/DeviceManagerDemo.js @@ -1,7 +1,7 @@ function hypertyLoaded(result, runtimeLoader = null) { - console.log('DeviceManager hyperty loaded', result.instance); + console.log('[DeviceManager] hyperty loaded', result.instance); if (runtimeLoader != null) { runtimeLoader.requireProtostub('sharing-cities-dsm'); } @@ -15,6 +15,104 @@ function hypertyLoaded(result, runtimeLoader = null) { function hypertyReady(result, identity) { - console.log('DeviceManager hyperty Ready', result, identity); + console.log('[DeviceManager] hyperty Ready', result, identity); result.instance.start(identity); + + var creating = $('.device-details'); + var createDeviceBtn = creating.find('.create-device-btn'); + var createStreamBtn = creating.find('.create-stream-btn'); + var streamsLable = creating.find('.streams-label'); + + + var deviceData = creating.find('.device-data'); + var createStream = creating.find('.create-stream'); + + var createStreamSection = creating.find('.create-stream'); + var searchForm = createStreamSection.find('.form'); + + createDeviceBtn.on('click', function(e) { + + result.instance.createDevice().then(function(result) { + console.log('[DeviceManager] createDevice result', result); + + var name; + if (result.body.code == 200) { + if (result.body.description == 'device already exist') { + name = 'reused Device with name: ' + result.body.device.name; + } else { + name = 'Device created with name: ' + result.body.device.name; + } + + streamsLable.removeClass("hide"); + createStreamBtn.removeClass("hide"); + createDeviceBtn.addClass("hide"); + + + var streamList = result.body.device.stream_list; + + + } else if (result.body.code == 408) { + name = 'Timeout creating Device'; + } + deviceData.text(name); + deviceData.removeClass("hide"); + + }); + + }); + + createStreamBtn.on('click', function(e) { + createStream.removeClass("hide"); + searchForm.removeClass("hide"); + }); + + + + + var inputPlatformID = searchForm.find('.platformID'); + var inputPlatformUID = searchForm.find('.platformUID'); + + + searchForm.on('submit', function(event) { + event.preventDefault(); + + var platformID = inputPlatformID.val(); + var platformUID = inputPlatformUID.val(); + + console.log('CREATing for: ', platformID, ' with id: ', platformUID); + result.instance.createEndpoint(platformID,platformUID).then(function(result) { + + var text = 'name: ' + result.body.stream.name + ' platform: ' + result.body.stream.platform; + var $userAvailability = $('
  • ') + .attr('url', 'test') + .text(text); + + var streams_list = creating.find('.streams-list'); + streams_list.append($userAvailability); + searchForm.addClass("hide"); +/* +createForm.on('submit', function(event) { + //event.preventDefault(); + + var platformID = inputPlatformID.val(); + var platformUID = inputPlatformUID.val(); + + console.log('CREATing for: ', platformID, ' with id: ', platformUID); + result.instance.createEndpoint(platformID,platformUID).then(function(result) { + + var text = 'name: ' + result.body.stream.name + ' platform: ' + result.body.stream.platform; + var $userAvailability = $('
  • ') + .text(text); + + var streams_list = creating.find('.streams-list'); + streams_list.append($userAvailability); + + createStreamBtn.addClass("hide"); + debugger; + }); +}); +*/ + + }); + }); } diff --git a/examples/user-availability/UserAvailabilityReporterDemo.js b/examples/user-availability/UserAvailabilityReporterDemo.js index 4063862..5c5beb5 100644 --- a/examples/user-availability/UserAvailabilityReporterDemo.js +++ b/examples/user-availability/UserAvailabilityReporterDemo.js @@ -65,7 +65,7 @@ function availabilityReady(availability) { let $myAvailability = $('.my_availability'); - userAvailabilityHy.addEventListener('myAvailability-context-update', function(event) { + userAvailabilityHy.context.addEventListener('myAvailability-context-update', function(event) { console.log('[UserAvailabilityReporterDemo.availabilityReady] Updated :', event); $myAvailability.text(event[0].value) diff --git a/examples/wallet/Wallet.hbs b/examples/wallet/Wallet.hbs index 3189786..480d955 100644 --- a/examples/wallet/Wallet.hbs +++ b/examples/wallet/Wallet.hbs @@ -2,5 +2,11 @@

    Wallet Hyperty Deployed

    -Wallet Tokens -X +Wallet +

    - Tokens: -

    +

    - Ranking: -

    +

    - Bonus credit: -

    + + + + diff --git a/examples/wallet/wallet.js b/examples/wallet/wallet.js index 268d176..cdbd835 100644 --- a/examples/wallet/wallet.js +++ b/examples/wallet/wallet.js @@ -6,7 +6,7 @@ function hypertyLoaded(result, runtimeLoader = null) { runtimeLoader.requireProtostub('sharing-cities-dsm'); } - result.instance.identityManager.discoverUserRegistered().then(function(identity) { + result.instance.identityManager.discoverUserRegistered().then(function (identity) { hypertyReady(result, identity); }); @@ -18,18 +18,31 @@ function hypertyReady(result, identity) { console.log('Wallet hyperty Ready', result, identity); function afterUpdate(event) { - console.log('WAllet new update', event); + 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 == 'bonus-credit') { + $('.bonus-credit').text(event.data); + } } - const profileInfo = { ageRange: '18-25', workplace: 'Lisbon', cause: '0' }; + const profileInfo = { ageRange: '18-25', workplace: 'Lisbon', cause: '0', balance: 10 }; identity.profile = profileInfo; result.instance.start(afterUpdate, identity); + $('.wallet-delete').click(function () { + result.instance.removeWallet().then(function (result) { + console.log('Wallet removed from DB'); + }); + }); + + // get public wallets /* console.log('Wallet hyperty Ready', result, identity); diff --git a/package.json b/package.json index 4c56540..24d8057 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dev-hyperty", - "version": "0.4.0", + "version": "0.5.0", "description": "Source code of hyperties", "main": ".eslintrc.js", "directories": { diff --git a/src/connector/Connector.hy.js b/src/connector/Connector.hy.js index e3c7a39..e6b0c98 100755 --- a/src/connector/Connector.hy.js +++ b/src/connector/Connector.hy.js @@ -24,12 +24,12 @@ /* jshint undef: true */ // Service Framework -import IdentityManager from 'service-framework/dist/IdentityManager'; -import {Discovery} from 'service-framework/dist/Discovery'; -import {Syncher} from 'service-framework/dist/Syncher'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import {Syncher} from 'service-framework/dist/Syncher'; // Utils -import {divideURL} from '../utils/utils'; +//import {divideURL} from '../utils/utils'; // Internals import ConnectionController from './ConnectionController'; @@ -45,7 +45,7 @@ class Connector { * Create a new Hyperty Connector * @param {Syncher} syncher - Syncher provided from the runtime core */ - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); @@ -55,25 +55,25 @@ class Connector { _this._hypertyURL = hypertyURL; _this._bus = bus; _this._configuration = configuration; - _this._domain = divideURL(hypertyURL).domain; + _this._domain = factory.divideURL(hypertyURL).domain; _this._objectDescURL = 'hyperty-catalogue://catalogue.' + _this._domain + '/.well-known/dataschema/Connection'; _this._controllers = {}; _this.connectionObject = connection; - let discovery = new Discovery(hypertyURL, configuration.runtimeURL, bus); - let identityManager = new IdentityManager(hypertyURL, configuration.runtimeURL, bus); + let discovery = factory.createDiscovery(hypertyURL, configuration.runtimeURL, bus); + let identityManager = factory.createIdentityManager(hypertyURL, configuration.runtimeURL, bus); _this.discovery = discovery; _this.identityManager = identityManager; - _this.search = new Search(discovery, identityManager); + _this.search = factory.createSearch(discovery, identityManager); console.log('Discover: ', discovery); console.log('Identity Manager: ', identityManager); - let syncher = new Syncher(hypertyURL, bus, configuration); + let syncher = factory.createSyncher(hypertyURL, bus, configuration); syncher.onNotification((event) => { @@ -295,11 +295,11 @@ class Connector { * @param {MiniBus} bus Minibus used to make the communication between hyperty and runtime; * @param {object} configuration configuration */ -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'Connector', - instance: new Connector(hypertyURL, bus, configuration) + instance: new Connector(hypertyURL, bus, configuration, factory) }; } diff --git a/src/connector/package-lock.json b/src/connector/package-lock.json index 1ebb0ea..a341a35 100644 --- a/src/connector/package-lock.json +++ b/src/connector/package-lock.json @@ -1,25 +1,22 @@ { "name": "connector", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { "sdp": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/sdp/-/sdp-2.7.4.tgz", - "integrity": "sha512-0+wTfgvUUEGcvvFoHIC0aiGbx6gzwAUm8FkKt5Oqqkjf9mEEDLgwnoDKX7MYTGXrNNwzikVbutJ+OVNAGmJBQw==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/sdp/-/sdp-2.8.0.tgz", + "integrity": "sha512-wRSES07rAwKWAR7aev9UuClT7kdf9ZTdeUK5gTgHue9vlhs19Fbm3ccNEGJO4y2IitH4/JzS4sdzyPl6H2KQLw==", "dev": true }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "webrtc-adapter": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/webrtc-adapter/-/webrtc-adapter-4.2.2.tgz", "integrity": "sha1-F4lsBHCE/UxWeVigzUMh4X8ydzw=", "dev": true, "requires": { - "sdp": "2.7.4" + "sdp": "^2.1.0" } } } diff --git a/src/connector/package.json b/src/connector/package.json index e6e383e..07d9c4e 100644 --- a/src/connector/package.json +++ b/src/connector/package.json @@ -1,6 +1,6 @@ { "name": "connector", - "version": "0.4.0", + "version": "0.5.0", "description": "Hyperty to make webrtc call", "main": "Connector.hy.js", "scripts": { @@ -8,9 +8,7 @@ }, "author": "vitor-t-silva@telecom.pt", "license": "ISC", - "dependencies": { - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" - }, + "dependencies": {}, "devDependencies": { "webrtc-adapter": "^4.2.2" } diff --git a/src/device-manager/DeviceManager.hy.js b/src/device-manager/DeviceManager.hy.js index fb11c60..8b12fc7 100644 --- a/src/device-manager/DeviceManager.hy.js +++ b/src/device-manager/DeviceManager.hy.js @@ -1,18 +1,18 @@ -import { Syncher } from 'service-framework/dist/Syncher'; +//import { Syncher } from 'service-framework/dist/Syncher'; import URI from 'urijs'; -import Search from '../utils/Search'; -import IdentityManager from 'service-framework/dist/IdentityManager'; -import { Discovery } from 'service-framework/dist/Discovery'; +//import Search from '../utils/Search'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import { Discovery } from 'service-framework/dist/Discovery'; class DeviceManager { - constructor(hypertyURL, bus, config) { + constructor(hypertyURL, bus, config, factory) { let uri = new URI(hypertyURL); this.objectDescURL = `hyperty-catalogue://catalogue.${uri.hostname()}/.well-known/dataschema/Context`; - this.syncher = new Syncher(hypertyURL, bus, config); - this.identityManager = new IdentityManager(hypertyURL, config.runtimeURL, bus); - this.discovery = new Discovery(hypertyURL, config.runtimeURL, bus); - this.search = new Search(this.discovery, this.identityManager); + this.syncher = factory.createSyncher(hypertyURL, bus, config); + this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, this.identityManager); this.currentPosition; this.bus = bus; this.hypertyURL = hypertyURL; @@ -139,9 +139,9 @@ class DeviceManager { } -export default function activate(hypertyURL, bus, config) { +export default function activate(hypertyURL, bus, config, factory) { return { name: 'DeviceManager', - instance: new DeviceManager(hypertyURL, bus, config) + instance: new DeviceManager(hypertyURL, bus, config, factory) }; } diff --git a/src/device-manager/package-lock.json b/src/device-manager/package-lock.json index 13c5c94..6894748 100644 --- a/src/device-manager/package-lock.json +++ b/src/device-manager/package-lock.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/device-manager/package.json b/src/device-manager/package.json index 1b74e74..317327b 100644 --- a/src/device-manager/package.json +++ b/src/device-manager/package.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Location is comprised by two Hyperties.", "main": "Wallet.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "Apache 2.0", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/dtwebrtc/DTWebRTC.hy.js b/src/dtwebrtc/DTWebRTC.hy.js index 0d4c72f..6d7eb26 100644 --- a/src/dtwebrtc/DTWebRTC.hy.js +++ b/src/dtwebrtc/DTWebRTC.hy.js @@ -1,30 +1,30 @@ /* jshint undef: true */ -import {Discovery} from 'service-framework/dist/Discovery'; -import {Syncher} from 'service-framework/dist/Syncher'; -import {divideURL} from '../utils/utils'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import {Syncher} from 'service-framework/dist/Syncher'; +//import {divideURL} from '../utils/utils'; import EventEmitter from '../utils/EventEmitter'; // for receiving -import Search from '../utils/Search'; +//import Search from '../utils/Search'; //import iceconfig from './stunTurnserverConfig'; -import IdentityManager from 'service-framework/dist/IdentityManager'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; import 'webrtc-adapter-test'; class DTWebRTC extends EventEmitter { // extends EventEmitter because we need to recieve events - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); if (!configuration) throw new Error('The configuration is a needed parameter'); super(); // call event emitter constructor to be able to receive things - this._domain = divideURL(hypertyURL).domain; + this._domain = factory.divideURL(hypertyURL).domain; this._objectDescURL = 'hyperty-catalogue://catalogue.' + this._domain + '/.well-known/dataschema/Connection'; - this._syncher = new Syncher(hypertyURL, bus, configuration); - this.discovery = new Discovery(hypertyURL, configuration.runtimeURL, bus); + this._syncher = factory.createSyncher(hypertyURL, bus, configuration); + this.discovery = factory.createDiscovery(hypertyURL, configuration.runtimeURL, bus); console.log("[DTWebRTC] [constructor] >>>>> Discovery object is:", this.discovery); - let identityManager = new IdentityManager(hypertyURL, configuration.runtimeURL, bus); - this.search = new Search(this.discovery, identityManager); + let identityManager = factory.createIdentityManager(hypertyURL, configuration.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, identityManager); this.objObserver; this.objReporter; this.callerIdentity; @@ -364,9 +364,9 @@ class DTWebRTC extends EventEmitter { // extends EventEmitter because we need to } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'DTWebRTC', - instance: new DTWebRTC(hypertyURL, bus, configuration) + instance: new DTWebRTC(hypertyURL, bus, configuration, factory) }; } diff --git a/src/dtwebrtc/package-lock.json b/src/dtwebrtc/package-lock.json index f0dd555..ab3217e 100644 --- a/src/dtwebrtc/package-lock.json +++ b/src/dtwebrtc/package-lock.json @@ -1,12 +1,9 @@ { "name": "dtwebrtc", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "webrtc-adapter-test": { "version": "0.2.10", "resolved": "https://registry.npmjs.org/webrtc-adapter-test/-/webrtc-adapter-test-0.2.10.tgz", diff --git a/src/dtwebrtc/package.json b/src/dtwebrtc/package.json index 538da52..5bea600 100644 --- a/src/dtwebrtc/package.json +++ b/src/dtwebrtc/package.json @@ -1,6 +1,6 @@ { "name": "dtwebrtc", - "version": "0.4.0", + "version": "0.5.0", "description": "", "main": "DTWebRTC.hy.js", "scripts": { @@ -9,7 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0", "webrtc-adapter-test": "^0.2.10" } } diff --git a/src/group-chat-manager/GroupChatManager.hy.js b/src/group-chat-manager/GroupChatManager.hy.js index 348c45a..41463a0 100644 --- a/src/group-chat-manager/GroupChatManager.hy.js +++ b/src/group-chat-manager/GroupChatManager.hy.js @@ -23,10 +23,10 @@ **/ // Service Framework -import IdentityManager from 'service-framework/dist/IdentityManager'; -import {ChatManager,ChatController} from 'service-framework/dist/ChatManager'; -import {Discovery, RegistrationStatus} from 'service-framework/dist/Discovery'; -import {Syncher} from 'service-framework/dist/Syncher'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import {ChatManager,ChatController} from 'runtime-core/dist/ChatManager'; +//import { RegistrationStatus} from 'service-framework/dist/Discovery'; +//import {Syncher} from 'service-framework/dist/Syncher'; // Utils /*import {divideURL} from '../utils/utils'; @@ -41,12 +41,23 @@ import { UserInfo } from './UserInfo';*/ * @author Vitor Silva [vitor-t-silva@telecom.pt] * @version 0.1.0 */ -class GroupChatManager extends ChatManager { +class GroupChatManager { - constructor(hypertyURL, bus, configuration) { - super(hypertyURL, bus, configuration); + constructor(hypertyURL, bus, configuration, factory) { +// super(hypertyURL, bus, configuration, factory); let _this = this; + _this._factory = factory; + _this._syncher = factory.createSyncher(hypertyURL, bus, configuration); + + _this._manager = factory.createChatManager(hypertyURL, bus, configuration, _this._syncher); + _this.discovery = _this._manager.discovery; + _this.identityManager = _this._manager.identityManager; + _this.search = _this._manager.search; + _this._domain = _this._manager._domain; + _this._myUrl = hypertyURL; + _this._runtimeURL = configuration.runtimeURL; + _this._bus = bus; _this._syncher.onNotification(function(event) { console.log('[GroupChatManager] onNotification:', event); @@ -65,11 +76,11 @@ class GroupChatManager extends ChatManager { return new Promise((resolve, reject) => { - if (_this.currentIdentity) { - resolve(_this.currentIdentity); + if (_this._manager.currentIdentity) { + resolve(_this._manager.currentIdentity); } else { // create a new chatController but first get identity - _this.identityManager.discoverUserRegistered().then((identity) => { + _this._manager.identityManager.discoverUserRegistered().then((identity) => { console.log('[GroupChatManager] GET MY IDENTITY:', identity); resolve(identity); }).catch((error) => { @@ -99,21 +110,21 @@ class GroupChatManager extends ChatManager { console.log('[GroupChatManager.resumeReporter]: ', dataObjectReporterURL); - let chatController = new ChatController(_this._syncher, _this.discovery, _this._domain, _this.search, identity, _this); + let chatController = _this._factory.createChatController(_this._syncher, _this.discovery, _this._domain, _this.search, identity, _this._manager); chatController.dataObjectReporter = reporters[dataObjectReporterURL]; // Save the chat controllers by dataObjectReporterURL - this._reportersControllers[dataObjectReporterURL] = chatController; + this._manager._reportersControllers[dataObjectReporterURL] = chatController; _this._resumeInterworking(chatController.dataObjectReporter); console.log('[GroupChatManager] chatController invitationsHandler: ', chatController.invitationsHandler); - chatController.invitationsHandler.resumeDiscoveries(_this.discovery, chatController.dataObjectReporter); + chatController.invitationsHandler.resumeDiscoveries(_this._manager.discovery, chatController.dataObjectReporter); }); - if (_this._onResumeReporter) _this._onResumeReporter(this._reportersControllers); + if (_this._onResumeReporter) _this._onResumeReporter(this._manager._reportersControllers); }); @@ -143,13 +154,13 @@ class GroupChatManager extends ChatManager { let chatObserver = observers[dataObjectObserverURL]; - let chatController = new ChatController(_this._syncher, _this.discovery, _this._domain, _this.search, identity, _this); + let chatController = _this._factory.createChatController(_this._syncher, _this._manager.discovery, _this._domain, _this.search, identity, _this._manager); chatController.dataObjectObserver = chatObserver; // Save the chat controllers by dataObjectReporterURL - this._observersControllers[dataObjectObserverURL] = chatController; + this._manager._observersControllers[dataObjectObserverURL] = chatController; - let reporterStatus = new RegistrationStatus(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 @@ -173,7 +184,7 @@ class GroupChatManager extends ChatManager { }); - if (_this._onResumeObserver) _this._onResumeObserver(this._observersControllers); + if (_this._onResumeObserver) _this._onResumeObserver(this._manager._observersControllers); }); @@ -233,7 +244,7 @@ class GroupChatManager extends ChatManager { * @return {ChatController} A ChatController object as a Promise. */ create(name, users, extra = {}) { - return super.create(name, users, extra); + return this._manager.create(name, users, extra); @@ -245,7 +256,7 @@ class GroupChatManager extends ChatManager { * @param {Function} CreateEvent The CreateEvent fired by the Syncher when an invitaion is received */ onInvitation(callback) { - return super.onInvitation(callback); + return this._manager.onInvitation(callback); } onResumeReporter(callback) { @@ -264,18 +275,45 @@ class GroupChatManager extends ChatManager { * @return {ChatController} It returns the ChatController object as a Promise */ join(invitationURL) { - return super.join(invitationURL); + return this._manager.join(invitationURL); + + + } + /** + * This function is used to retrieve my identity. + * @return {Identity} It returns the Identity object as a Promise + */ + myIdentity(identity) { + console.log('[GroupChatManager.myIdentity] ', identity); + return this._manager.myIdentity(identity); + + + } + /** + * This function is used to process incoming messages. + */ + processNotification(event) { + return this._manager.processNotification(event); + + + } + + /** + * This function is used to process incoming messages. + */ + onInvitation(callback) { + return this._manager.onInvitation(callback); } } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'GroupChatManager', - instance: new GroupChatManager(hypertyURL, bus, configuration) + instance: new GroupChatManager(hypertyURL, bus, configuration, factory) }; } diff --git a/src/group-chat-manager/package-lock.json b/src/group-chat-manager/package-lock.json index fd478f2..7a6a99b 100644 --- a/src/group-chat-manager/package-lock.json +++ b/src/group-chat-manager/package-lock.json @@ -1,420 +1,5 @@ { "name": "group-chat-manager", - "version": "0.4.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, - "builtin-modules": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "contains-path": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", - "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", - "dev": true - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "doctrine": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", - "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", - "dev": true, - "requires": { - "esutils": "2.0.2", - "isarray": "1.0.0" - } - }, - "error-ex": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", - "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", - "dev": true, - "requires": { - "is-arrayish": "0.2.1" - } - }, - "eslint-import-resolver-node": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz", - "integrity": "sha512-sfmTqJfPSizWu4aymbPr4Iidp5yKm8yDkHp+Ir3YiTHiiDfxh69mOUsmiqW6RZ9zRXFaF64GtYmN7e+8GHBv6Q==", - "dev": true, - "requires": { - "debug": "2.6.9", - "resolve": "1.8.1" - } - }, - "eslint-module-utils": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.2.0.tgz", - "integrity": "sha1-snA2LNiLGkitMIl2zn+lTphBF0Y=", - "dev": true, - "requires": { - "debug": "2.6.9", - "pkg-dir": "1.0.0" - } - }, - "eslint-plugin-import": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.13.0.tgz", - "integrity": "sha512-t6hGKQDMIt9N8R7vLepsYXgDfeuhp6ZJSgtrLEDxonpSubyxUZHjhm6LsAaZX8q6GYVxkbT3kTsV9G5mBCFR6A==", - "dev": true, - "requires": { - "contains-path": "0.1.0", - "debug": "2.6.9", - "doctrine": "1.5.0", - "eslint-import-resolver-node": "0.3.2", - "eslint-module-utils": "2.2.0", - "has": "1.0.3", - "lodash": "4.17.10", - "minimatch": "3.0.4", - "read-pkg-up": "2.0.0", - "resolve": "1.8.1" - } - }, - "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true - }, - "find-up": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", - "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", - "dev": true, - "requires": { - "path-exists": "2.1.0", - "pinkie-promise": "2.0.1" - } - }, - "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, - "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", - "dev": true - }, - "has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "requires": { - "function-bind": "1.1.1" - } - }, - "hosted-git-info": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", - "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", - "dev": true - }, - "is-arrayish": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", - "dev": true - }, - "is-builtin-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", - "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", - "dev": true, - "requires": { - "builtin-modules": "1.1.1" - } - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "load-json-file": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", - "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", - "dev": true, - "requires": { - "graceful-fs": "4.1.11", - "parse-json": "2.2.0", - "pify": "2.3.0", - "strip-bom": "3.0.0" - } - }, - "locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", - "dev": true, - "requires": { - "p-locate": "2.0.0", - "path-exists": "3.0.0" - }, - "dependencies": { - "path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true - } - } - }, - "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==", - "dev": true - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "1.1.11" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "normalize-package-data": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", - "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", - "dev": true, - "requires": { - "hosted-git-info": "2.7.1", - "is-builtin-module": "1.0.0", - "semver": "5.5.0", - "validate-npm-package-license": "3.0.3" - } - }, - "p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "dev": true, - "requires": { - "p-try": "1.0.0" - } - }, - "p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", - "dev": true, - "requires": { - "p-limit": "1.3.0" - } - }, - "p-try": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", - "dev": true - }, - "parse-json": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", - "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", - "dev": true, - "requires": { - "error-ex": "1.3.2" - } - }, - "path-exists": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", - "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", - "dev": true, - "requires": { - "pinkie-promise": "2.0.1" - } - }, - "path-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", - "dev": true - }, - "path-type": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", - "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", - "dev": true, - "requires": { - "pify": "2.3.0" - } - }, - "pify": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", - "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", - "dev": true - }, - "pinkie": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", - "dev": true - }, - "pinkie-promise": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", - "dev": true, - "requires": { - "pinkie": "2.0.4" - } - }, - "pkg-dir": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-1.0.0.tgz", - "integrity": "sha1-ektQio1bstYp1EcFb/TpyTFM89Q=", - "dev": true, - "requires": { - "find-up": "1.1.2" - } - }, - "read-pkg": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", - "integrity": "sha1-jvHAYjxqbbDcZxPEv6xGMysjaPg=", - "dev": true, - "requires": { - "load-json-file": "2.0.0", - "normalize-package-data": "2.4.0", - "path-type": "2.0.0" - } - }, - "read-pkg-up": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", - "integrity": "sha1-a3KoBImE4MQeeVEP1en6mbO1Sb4=", - "dev": true, - "requires": { - "find-up": "2.1.0", - "read-pkg": "2.0.0" - }, - "dependencies": { - "find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, - "requires": { - "locate-path": "2.0.0" - } - } - } - }, - "resolve": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", - "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", - "dev": true, - "requires": { - "path-parse": "1.0.5" - } - }, - "semver": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", - "dev": true - }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, - "spdx-correct": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", - "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", - "dev": true, - "requires": { - "spdx-expression-parse": "3.0.0", - "spdx-license-ids": "3.0.0" - } - }, - "spdx-exceptions": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", - "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==", - "dev": true - }, - "spdx-expression-parse": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", - "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", - "dev": true, - "requires": { - "spdx-exceptions": "2.1.0", - "spdx-license-ids": "3.0.0" - } - }, - "spdx-license-ids": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", - "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==", - "dev": true - }, - "strip-bom": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", - "dev": true - }, - "validate-npm-package-license": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz", - "integrity": "sha512-63ZOUnL4SIXj4L0NixR3L1lcjO38crAbgrTpl28t8jjrfuiOBL5Iygm+60qPs/KsZGzPNg6Smnc/oY16QTjF0g==", - "dev": true, - "requires": { - "spdx-correct": "3.0.0", - "spdx-expression-parse": "3.0.0" - } - } - } + "version": "0.5.0", + "lockfileVersion": 1 } diff --git a/src/group-chat-manager/package.json b/src/group-chat-manager/package.json index ac29d83..1cca8bb 100644 --- a/src/group-chat-manager/package.json +++ b/src/group-chat-manager/package.json @@ -1,14 +1,10 @@ { "name": "group-chat-manager", - "version": "0.4.0", + "version": "0.5.0", "description": "", "main": "GroupChatManager.hy.js", - "dependencies": { - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" - }, - "devDependencies": { - "eslint-plugin-import": "^2.12.0" - }, + "dependencies": {}, + "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/hello-world/HelloWorldObserver.hy.js b/src/hello-world/HelloWorldObserver.hy.js index b51c98f..4f622c7 100644 --- a/src/hello-world/HelloWorldObserver.hy.js +++ b/src/hello-world/HelloWorldObserver.hy.js @@ -1,7 +1,7 @@ /* jshint undef: true */ -import {Syncher} from 'service-framework/dist/Syncher'; -import {divideURL} from '../utils/utils'; +// import {Syncher} from 'service-framework/dist/Syncher'; +// import {divideURL} from '../utils/utils'; import EventEmitter from '../utils/EventEmitter'; /** @@ -15,21 +15,22 @@ class HelloWorldObserver extends EventEmitter { * Create a new HelloWorldObserver * @param {Syncher} syncher - Syncher provided from the runtime core */ - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); if (!configuration) throw new Error('The configuration is a needed parameter'); + if (!factory) throw new Error('The factory is a needed parameter'); super(); let _this = this; - let domain = divideURL(hypertyURL).domain; + let domain = factory.divideURL(hypertyURL).domain; _this._domain = domain; _this._objectDescURL = 'hyperty-catalogue://catalogue.' + domain + '/.well-known/dataschema/HelloWorldDataSchema'; - let syncher = new Syncher(hypertyURL, bus, configuration); + let syncher = factory.createSyncher(hypertyURL, bus, configuration); syncher.onNotification(function(event) { _this._onNotification(event); }); @@ -100,11 +101,11 @@ class HelloWorldObserver extends EventEmitter { } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'HelloWorldObserver', - instance: new HelloWorldObserver(hypertyURL, bus, configuration) + instance: new HelloWorldObserver(hypertyURL, bus, configuration, factory) }; } diff --git a/src/hello-world/HelloWorldReporter.hy.js b/src/hello-world/HelloWorldReporter.hy.js index d417fcc..2bb9ecc 100644 --- a/src/hello-world/HelloWorldReporter.hy.js +++ b/src/hello-world/HelloWorldReporter.hy.js @@ -1,7 +1,7 @@ /* jshint undef: true */ -import {Syncher} from 'service-framework/dist/Syncher'; -import {divideURL} from '../utils/utils'; +//import {Syncher} from 'service-framework/dist/Syncher'; +//import {divideURL} from '../utils/utils'; import hello from './hello'; /** @@ -15,20 +15,23 @@ class HelloWorldReporter { * Create a new HelloWorldReporter * @param {Syncher} syncher - Syncher provided from the runtime core */ - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); if (!configuration) throw new Error('The configuration is a needed parameter'); - + if (!factory) throw new Error('The factory is a needed parameter'); let _this = this; - let domain = divideURL(hypertyURL).domain; + let domain = factory.divideURL(hypertyURL).domain; _this._domain = domain; _this._objectDescURL = 'hyperty-catalogue://catalogue.' + domain + '/.well-known/dataschema/HelloWorldDataSchema'; + _this._factory = factory; + + console.log('HelloWorldReporter configuration', configuration); - let syncher = new Syncher(hypertyURL, bus, configuration); + let syncher = _this._factory.createSyncher(hypertyURL, bus, configuration); _this._syncher = syncher; @@ -127,11 +130,15 @@ class HelloWorldReporter { -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { + + // console.log('Hello World Activate', factory); +// debugger; + return { name: 'HelloWorldReporter', - instance: new HelloWorldReporter(hypertyURL, bus, configuration) + instance: new HelloWorldReporter(hypertyURL, bus, configuration, factory) }; } diff --git a/src/hello-world/package-lock.json b/src/hello-world/package-lock.json index 95cafad..5a441ec 100644 --- a/src/hello-world/package-lock.json +++ b/src/hello-world/package-lock.json @@ -1,11 +1,5 @@ { "name": "hello-world", - "version": "0.4.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - } - } + "version": "0.5.0", + "lockfileVersion": 1 } diff --git a/src/hello-world/package.json b/src/hello-world/package.json index 759db42..d571b9c 100644 --- a/src/hello-world/package.json +++ b/src/hello-world/package.json @@ -1,6 +1,6 @@ { "name": "hello-world", - "version": "0.4.0", + "version": "0.5.0", "description": "Two simple Hello World Hyperties are provided:", "main": "HelloWorldObserver.hy.js", "scripts": { @@ -8,7 +8,5 @@ }, "author": "", "license": "ISC", - "dependencies": { - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" - } + "dependencies": {} } diff --git a/src/learning/ElearningPlayer.hy.js b/src/learning/ElearningPlayer.hy.js index c831aae..75469d2 100644 --- a/src/learning/ElearningPlayer.hy.js +++ b/src/learning/ElearningPlayer.hy.js @@ -1,20 +1,20 @@ -import { Syncher } from 'service-framework/dist/Syncher'; +//import { Syncher } from 'service-framework/dist/Syncher'; import URI from 'urijs'; -import Search from '../utils/Search'; -import IdentityManager from 'service-framework/dist/IdentityManager'; -import { Discovery } from 'service-framework/dist/Discovery'; -import { callbackify } from 'util'; +//import Search from '../utils/Search'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import { Discovery } from 'service-framework/dist/Discovery'; +//import { callbackify } from 'util'; class ElearningPlayer { - constructor(hypertyURL, bus, config) { + constructor(hypertyURL, bus, config, factory) { let uri = new URI(hypertyURL); this.objectDescURL = `hyperty-catalogue://catalogue.${uri.hostname()}/.well-known/dataschema/Context`; - this.syncher = new Syncher(hypertyURL, bus, config); - this.identityManager = new IdentityManager(hypertyURL, config.runtimeURL, bus); - this.discovery = new Discovery(hypertyURL, config.runtimeURL, bus); - this.search = new Search(this.discovery, this.identityManager); + this.syncher = factory.createSyncher(hypertyURL, bus, config); + this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, this.identityManager); this.currentPosition = null; this.identity = null; this.bus = bus; @@ -165,9 +165,9 @@ class ElearningPlayer { } -export default function activate(hypertyURL, bus, config) { +export default function activate(hypertyURL, bus, config, factory) { return { name: 'ElearningPlayer', - instance: new ElearningPlayer(hypertyURL, bus, config) + instance: new ElearningPlayer(hypertyURL, bus, config, factory) }; } diff --git a/src/learning/ElearningPlayer.hy.json b/src/learning/ElearningPlayer.hy.json index 87ac44b..1ffa9ec 100644 --- a/src/learning/ElearningPlayer.hy.json +++ b/src/learning/ElearningPlayer.hy.json @@ -1,5 +1,6 @@ { - "configuration": { "domain_registration": false + "configuration": { "domain_registration": false, + "domain_routing": false }, "hypertyType": [ "location-context" diff --git a/src/learning/package-lock.json b/src/learning/package-lock.json index 27c276a..ea83f54 100644 --- a/src/learning/package-lock.json +++ b/src/learning/package-lock.json @@ -1,6 +1,6 @@ { "name": "location", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/learning/package.json b/src/learning/package.json index c27157e..47a8fe5 100644 --- a/src/learning/package.json +++ b/src/learning/package.json @@ -1,6 +1,6 @@ { "name": "location", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Location is comprised by two Hyperties.", "main": "LocationReporter.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "Apache 2.0", "dependencies": { - "bootstrap": "^4.0.0-beta.2", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.0.0-beta.2" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/location/LocationObserver.hy.js b/src/location/LocationObserver.hy.js index 093bc14..4c25890 100644 --- a/src/location/LocationObserver.hy.js +++ b/src/location/LocationObserver.hy.js @@ -1,15 +1,15 @@ -import { Syncher } from 'service-framework/dist/Syncher'; -import {Discovery} from 'service-framework/dist/Discovery'; -import URI from 'urijs' -import {ContextObserver} from 'service-framework/dist/ContextManager'; +//import { Syncher } from 'service-framework/dist/Syncher'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import URI from 'urijs' +//import {ContextObserver} from 'service-framework/dist/ContextManager'; -class LocationObserverHyperty extends ContextObserver { +class LocationObserverHyperty { - constructor(hypertyURL, bus, config) { + constructor(hypertyURL, bus, config, factory) { // this._domain = divideURL(hypertyURL).domain; - - super(hypertyURL, bus, config,['location-context']); + + this._context = factory.createContextObserver(hypertyURL, bus, config,['location-context']); /* let uri = new URI(hypertyURL); this._users2observe = []; @@ -23,28 +23,28 @@ class LocationObserverHyperty extends ContextObserver { start(callback) { console.log('[LocationObserver.start] '); - return super.start(); + return this._context.start(); } resumeDiscoveries() { - return super.resumeDiscoveries(); + return this._context.resumeDiscoveries(); } onResumeObserver(callback) { - return super.onResumeObserver(callback); + return this._context.onResumeObserver(callback); } discoverUsers(email,domain) { - return super.discoverUsers(email, domain); + return this._context.discoverUsers(email, domain); } observe(hyperty) { - return super.observe(hyperty); + return this._context.observe(hyperty); } unobserve(Context) { - return super.unobserve(Context); + return this._context.unobserve(Context); } @@ -90,10 +90,10 @@ class LocationObserverHyperty extends ContextObserver { } -export default function activate(hypertyURL, bus, config){ +export default function activate(hypertyURL, bus, config, factory){ return { name: 'LocationObserver', - instance: new LocationObserverHyperty(hypertyURL, bus, config) + instance: new LocationObserverHyperty(hypertyURL, bus, config, factory) }; } diff --git a/src/location/LocationReporter.hy.js b/src/location/LocationReporter.hy.js index 7388c59..853cd81 100644 --- a/src/location/LocationReporter.hy.js +++ b/src/location/LocationReporter.hy.js @@ -1,21 +1,21 @@ -import { Syncher } from 'service-framework/dist/Syncher'; +//import { Syncher } from 'service-framework/dist/Syncher'; import URI from 'urijs'; import position from './position'; -import Search from '../utils/Search'; -import IdentityManager from 'service-framework/dist/IdentityManager'; -import { Discovery } from 'service-framework/dist/Discovery'; -import { callbackify } from 'util'; +//import Search from '../utils/Search'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import { Discovery } from 'service-framework/dist/Discovery'; +//import { callbackify } from 'util'; class LocationHypertyFactory { - constructor(hypertyURL, bus, config) { + constructor(hypertyURL, bus, config, factory) { let uri = new URI(hypertyURL); this.objectDescURL = `hyperty-catalogue://catalogue.${uri.hostname()}/.well-known/dataschema/Context`; - this.syncher = new Syncher(hypertyURL, bus, config); - this.identityManager = new IdentityManager(hypertyURL, config.runtimeURL, bus); - this.discovery = new Discovery(hypertyURL, config.runtimeURL, bus); - this.search = new Search(this.discovery, this.identityManager); + this.syncher = factory.createSyncher(hypertyURL, bus, config); + this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, this.identityManager); this.currentPosition = null; this.identity = null; this.bus = bus; @@ -231,9 +231,21 @@ class LocationHypertyFactory { { name: 'longitude', unit: 'lon', value: longitude }, { name: 'checkin', unit: 'checkin', value: spotId } ]; + } + + collect(bonusID, spotID) { + let _this = this; + // let latitude = _this.currentPosition.coords.latitude; + // let longitude = _this.currentPosition.coords.longitude; + _this.reporter.data.values = [ + { name: 'bonus', unit: 'checkin', value: bonusID }, + { name: 'checkin', unit: 'checkin', value: spotID } + ]; } + + // can call with 'data://sharing-cities-dsm/shops' retrieveSpots(spotsURL) { @@ -262,9 +274,9 @@ class LocationHypertyFactory { } -export default function activate(hypertyURL, bus, config) { +export default function activate(hypertyURL, bus, config, factory) { return { name: 'LocationReporter', - instance: new LocationHypertyFactory(hypertyURL, bus, config) + instance: new LocationHypertyFactory(hypertyURL, bus, config, factory) }; } diff --git a/src/location/LocationReporter.hy.json b/src/location/LocationReporter.hy.json index 47e07d2..35a136d 100644 --- a/src/location/LocationReporter.hy.json +++ b/src/location/LocationReporter.hy.json @@ -1,6 +1,7 @@ { "configuration": { - "domain_registration": false + "domain_registration": false, + "domain_routing": false }, "hypertyType": [ "location-context" diff --git a/src/location/package-lock.json b/src/location/package-lock.json index 27c276a..ea83f54 100644 --- a/src/location/package-lock.json +++ b/src/location/package-lock.json @@ -1,6 +1,6 @@ { "name": "location", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/location/package.json b/src/location/package.json index c075759..c4c5572 100644 --- a/src/location/package.json +++ b/src/location/package.json @@ -1,6 +1,6 @@ { "name": "location", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Location is comprised by two Hyperties.", "main": "LocationReporter.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "Apache 2.0", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/node-hyperty/NodeHyperty.hy.js b/src/node-hyperty/NodeHyperty.hy.js index 09ceaf0..79bbad6 100644 --- a/src/node-hyperty/NodeHyperty.hy.js +++ b/src/node-hyperty/NodeHyperty.hy.js @@ -1,7 +1,7 @@ /* jshint undef: true */ import os from 'os'; -import {Syncher} from 'service-framework/dist/Syncher'; +//import {Syncher} from 'service-framework/dist/Syncher'; export function divideURL(url) { @@ -45,7 +45,7 @@ class NodeHyperty { * Create a new HelloWorldReporter * @param {Syncher} syncher - Syncher provided from the runtime core */ - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); @@ -57,8 +57,7 @@ class NodeHyperty { this._interval; - let syncher = new Syncher(hypertyURL, bus, configuration); - this.syncher = syncher; + this.syncher = factory.createSyncher(hypertyURL, bus, config); let mbTotal = bytesToSize(os.totalmem()); let mbFree = bytesToSize(os.freemem()); diff --git a/src/node-hyperty/NodeHypertyObserver.hy.js b/src/node-hyperty/NodeHypertyObserver.hy.js index 586f3df..8bab5d8 100644 --- a/src/node-hyperty/NodeHypertyObserver.hy.js +++ b/src/node-hyperty/NodeHypertyObserver.hy.js @@ -1,9 +1,9 @@ /* jshint undef: true */ // Service Framework -import IdentityManager from 'service-framework/dist/IdentityManager'; -import {Discovery} from 'service-framework/dist/Discovery'; -import {Syncher} from 'service-framework/dist/Syncher'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import {Syncher} from 'service-framework/dist/Syncher'; import {divideURL} from '../utils/utils'; import Search from '../utils/Search'; @@ -18,7 +18,7 @@ class NodeHypertyObserver { * Create a new HelloWorldReporter * @param {Syncher} syncher - Syncher provided from the runtime core */ - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { if (!hypertyURL) throw new Error('The hypertyURL is a needed parameter'); if (!bus) throw new Error('The MiniBus is a needed parameter'); @@ -30,25 +30,21 @@ class NodeHypertyObserver { _this._domain = domain; _this._objectDescURL = 'hyperty-catalogue://catalogue.' + domain + '/.well-known/dataschema/Connection'; - let discovery = new Discovery(hypertyURL, bus); - let identityManager = new IdentityManager(hypertyURL, configuration.runtimeURL, bus); + _this.syncher = factory.createSyncher(hypertyURL, bus, config); + _this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + _this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); - _this.discovery = discovery; - _this.identityManager = identityManager; _this.search = new Search(discovery, identityManager); - let syncher = new Syncher(hypertyURL, bus, configuration); console.log('HELLO: ', this._objectDescURL); - syncher.onNotification((event) => { + _this.syncher.onNotification((event) => { event.ack(); // this.join(event.url); }); - - _this.syncher = syncher; } /** diff --git a/src/node-hyperty/package-lock.json b/src/node-hyperty/package-lock.json index c07a156..3845571 100644 --- a/src/node-hyperty/package-lock.json +++ b/src/node-hyperty/package-lock.json @@ -1,11 +1,5 @@ { "name": "node-hyperty", - "version": "0.4.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - } - } + "version": "0.5.0", + "lockfileVersion": 1 } diff --git a/src/node-hyperty/package.json b/src/node-hyperty/package.json index a6e3739..15be9d7 100644 --- a/src/node-hyperty/package.json +++ b/src/node-hyperty/package.json @@ -1,14 +1,11 @@ { "name": "node-hyperty", - "version": "0.4.0", + "version": "0.5.0", "description": "Node Hyperty", "main": "NodeHypertyObserver.hy.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC", - "dependencies": { - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" - } + "license": "ISC" } diff --git a/src/observer-kwh/UserKwhObserver.hy.js b/src/observer-kwh/UserKwhObserver.hy.js index 5255155..ea70c04 100644 --- a/src/observer-kwh/UserKwhObserver.hy.js +++ b/src/observer-kwh/UserKwhObserver.hy.js @@ -1,16 +1,16 @@ -import IdentityManager from 'service-framework/dist/IdentityManager'; -import {Syncher} from 'service-framework/dist/Syncher'; -import {Discovery} from 'service-framework/dist/Discovery'; -import {ContextObserver} from 'service-framework/dist/ContextManager'; -import {divideURL} from '../utils/utils'; -import Search from '../utils/Search'; -import EventEmitter from '../utils/EventEmitter'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import {Syncher} from 'service-framework/dist/Syncher'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import {ContextObserver} from 'service-framework/dist/ContextManager'; +//import {divideURL} from '../utils/utils'; +//import Search from '../utils/Search'; +//import EventEmitter from '../utils/EventEmitter'; -class UserKwhObserver extends ContextObserver { +class UserKwhObserver { - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { - super(hypertyURL, bus, configuration, ['availability_context']); + this._context = factory.createContextObserver(hypertyURL, bus, configuration,['availability_context']); } @@ -26,22 +26,22 @@ class UserKwhObserver extends ContextObserver { let resumedInit = [{value: 'unavailable'}]; - return super.start(resumedInit, resumedCallback); + return this._context.start(resumedInit, resumedCallback); } resumeDiscoveries() { - return super.resumeDiscoveries(); + return this._context.resumeDiscoveries(); } onResumeObserver(callback) { - return super.onResumeObserver(callback); + return this._context.onResumeObserver(callback); } discoverUsers(email,domain) { - return super.discoverUsers(email,domain); + return this._context.discoverUsers(email,domain); } @@ -53,7 +53,7 @@ resumeDiscoveries() { observe(hyperty) { - return super.observe(hyperty); + return this._context.observe(hyperty); } @@ -65,15 +65,15 @@ resumeDiscoveries() { unobserve(availability) { - return super.unobserve(availability); + return this._context.unobserve(availability); } } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'UserKwhObserver', - instance: new UserKwhObserver(hypertyURL, bus, configuration) + instance: new UserKwhObserver(hypertyURL, bus, configuration, factory) }; } diff --git a/src/observer-kwh/package-lock.json b/src/observer-kwh/package-lock.json index 274dcc7..be4c8a1 100644 --- a/src/observer-kwh/package-lock.json +++ b/src/observer-kwh/package-lock.json @@ -1,6 +1,6 @@ { "name": "user-availability", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/observer-kwh/package.json b/src/observer-kwh/package.json index 8ab6c05..9582a7f 100644 --- a/src/observer-kwh/package.json +++ b/src/observer-kwh/package.json @@ -1,6 +1,6 @@ { "name": "user-availability", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Availability is comprised by two Hyperties.", "main": "UserKwhObserver.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "ISC", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/user-activity/UserActivityObserver.hy.js b/src/user-activity/UserActivityObserver.hy.js index 300b762..d3d89bb 100644 --- a/src/user-activity/UserActivityObserver.hy.js +++ b/src/user-activity/UserActivityObserver.hy.js @@ -1,9 +1,9 @@ //import { Syncher } from 'service-framework/dist/Syncher'; import URI from 'urijs'; //import Search from '../utils/Search'; -import IdentityManager from 'service-framework/dist/IdentityManager'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; //import { Discovery } from 'service-framework/dist/Discovery'; -import { ContextObserver } from 'service-framework/dist/ContextManager'; +//import { ContextObserver } from 'service-framework/dist/ContextManager'; /** @@ -11,23 +11,25 @@ import { ContextObserver } from 'service-framework/dist/ContextManager'; * These functions are only required to be used once. * By default, the Hyperty automatically connects and starts reading sources that were connected the last time. */ -class UserActivityObserver extends ContextObserver { +class UserActivityObserver { - constructor(hypertyURL, bus, config) { - super(hypertyURL, bus, config, ['availability_context']); + constructor(hypertyURL, bus, config, factory) { +// super(hypertyURL, bus, config, ['availability_context'], factory); + this._context = factory.createContextObserver(hypertyURL, bus, config,['availability_context']); let uri = new URI(hypertyURL); this.objectDescURL = `hyperty-catalogue://catalogue.${uri.hostname()}/.well-known/dataschema/Context`; -// this.syncher = new Syncher(hypertyURL, bus, config); - this.identityManager = new IdentityManager(hypertyURL, config.runtimeURL, bus); -// this.discovery = new Discovery(hypertyURL, config.runtimeURL, bus); -// this.search = new Search(this.discovery, this.identityManager); +// this.syncher = factory.createSyncher(hypertyURL, bus, config); + this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, this.identityManager); this.bus = bus; this.hypertyURL = hypertyURL; bus.addListener(hypertyURL, (msg) => { console.log('[UserActivityObserver] new msg', msg); }); + this.callback = null; } /** @@ -75,9 +77,8 @@ class UserActivityObserver extends ContextObserver { start(callback, identity) { let _this = this; - + _this.callback = callback; // get GFit access token (token received by protostub) - _this.bus.postMessage({ type: 'create', from: _this.hypertyURL, @@ -91,6 +92,16 @@ class UserActivityObserver extends ContextObserver { }, (reply) => { if (reply.body.code === 200) { console.log('[UserActivityObserver] GFit auth granted'); + console.log(_this); + let googleStubUrlStatus = reply.body.runtimeURL + '/status' + console.log('[UserActivityObserver] listener added on ', googleStubUrlStatus); + _this.bus.addListener(googleStubUrlStatus, newMsg => { + console.log('[UserActivityObserver] googleStatusChanged', newMsg); + if (newMsg.hasOwnProperty('body') && newMsg.body.hasOwnProperty('desc') && newMsg.body.desc.hasOwnProperty('error') ){ + callback(newMsg.body.desc.error); + } + + }); callback(true); } else { console.log('[UserActivityObserver] GFit auth not granted'); @@ -117,7 +128,7 @@ class UserActivityObserver extends ContextObserver { } - /* + /* Stop GoogleProtoStub from querying sessions. */ stop() { @@ -140,9 +151,9 @@ class UserActivityObserver extends ContextObserver { } } -export default function activate(hypertyURL, bus, config) { +export default function activate(hypertyURL, bus, config, factory) { return { name: 'UserActivityObserver', - instance: new UserActivityObserver(hypertyURL, bus, config) + instance: new UserActivityObserver(hypertyURL, bus, config, factory) }; } diff --git a/src/user-activity/UserActivityObserver.hy.json b/src/user-activity/UserActivityObserver.hy.json index 69b1872..02d49a7 100644 --- a/src/user-activity/UserActivityObserver.hy.json +++ b/src/user-activity/UserActivityObserver.hy.json @@ -1,7 +1,8 @@ { "configuration": { "discoveryProviders": ["fitness.google.com"], - "domain_registration": false + "domain_registration": false, + "domain_routing": false }, "hypertyType": [ "user_activity_context" diff --git a/src/user-activity/package-lock.json b/src/user-activity/package-lock.json index 13c5c94..6894748 100644 --- a/src/user-activity/package-lock.json +++ b/src/user-activity/package-lock.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/user-activity/package.json b/src/user-activity/package.json index 1b74e74..317327b 100644 --- a/src/user-activity/package.json +++ b/src/user-activity/package.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Location is comprised by two Hyperties.", "main": "Wallet.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "Apache 2.0", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/user-availability/UserAvailabilityObserver.hy.js b/src/user-availability/UserAvailabilityObserver.hy.js index 5e00971..c19f621 100644 --- a/src/user-availability/UserAvailabilityObserver.hy.js +++ b/src/user-availability/UserAvailabilityObserver.hy.js @@ -1,17 +1,17 @@ -import IdentityManager from 'service-framework/dist/IdentityManager'; -import {Syncher} from 'service-framework/dist/Syncher'; -import {Discovery} from 'service-framework/dist/Discovery'; -import {ContextObserver} from 'service-framework/dist/ContextManager'; -import {divideURL} from '../utils/utils'; -import Search from '../utils/Search'; -import EventEmitter from '../utils/EventEmitter'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import {Syncher} from 'service-framework/dist/Syncher'; +//import {Discovery} from 'service-framework/dist/Discovery'; +//import {ContextObserver} from 'service-framework/dist/ContextManager'; +//import {divideURL} from '../utils/utils'; +//import Search from '../utils/Search'; +//import EventEmitter from '../utils/EventEmitter'; -class UserAvailabilityObserver extends ContextObserver { +class UserAvailabilityObserver { - constructor(hypertyURL, bus, configuration) { - - super(hypertyURL, bus, configuration, ['availability_context']); + constructor(hypertyURL, bus, configuration, factory) { +// super(hypertyURL, bus, configuration, ['availability_context'], factory); + this._context = factory.createContextObserver(hypertyURL, bus, configuration,['availability_context']); } @@ -26,22 +26,22 @@ class UserAvailabilityObserver extends ContextObserver { let resumedInit = [{value: 'unavailable'}]; - return super.start(resumedInit, resumedCallback); + return this._context.start(resumedInit, resumedCallback); } resumeDiscoveries() { - return super.resumeDiscoveries(); + return this._context.resumeDiscoveries(); } onResumeObserver(callback) { - return super.onResumeObserver(callback); + return this._context.onResumeObserver(callback); } discoverUsers(email,domain) { - return super.discoverUsers(email,domain); + return this._context.discoverUsers(email,domain); } @@ -53,7 +53,7 @@ resumeDiscoveries() { observe(hyperty) { - return super.observe(hyperty); + return this._context.observe(hyperty); } @@ -65,15 +65,15 @@ resumeDiscoveries() { unobserve(availability) { - return super.unobserve(availability); + return this._context.unobserve(availability); } } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'UserAvailabilityObserver', - instance: new UserAvailabilityObserver(hypertyURL, bus, configuration) + instance: new UserAvailabilityObserver(hypertyURL, bus, configuration, factory) }; } diff --git a/src/user-availability/UserAvailabilityReporter.hy.js b/src/user-availability/UserAvailabilityReporter.hy.js index e376503..b91bc5b 100644 --- a/src/user-availability/UserAvailabilityReporter.hy.js +++ b/src/user-availability/UserAvailabilityReporter.hy.js @@ -23,9 +23,9 @@ // Service Framework //import {Discovery} from 'service-framework/dist/Discovery'; -import IdentityManager from 'service-framework/dist/IdentityManager'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; //import {Syncher} from 'service-framework/dist/Syncher'; -import {ContextReporter} from 'service-framework/dist/ContextManager'; +//import {ContextReporter} from 'service-framework/dist/ContextManager'; // Utils //import EventEmitter from '../utils/EventEmitter.js'; @@ -39,11 +39,11 @@ import availability from './availability.js'; * @author Paulo Chainho [paulo-g-chainho@alticelabs.com] * @version 0.1.0 */ -class UserAvailabilityReporter extends ContextReporter { +class UserAvailabilityReporter { - constructor(hypertyURL, bus, configuration) { + constructor(hypertyURL, bus, configuration, factory) { - super(hypertyURL, bus, configuration); + this._context = factory.createContextReporter(hypertyURL, bus, configuration); let _this = this; console.info('[UserAvailabilityReporter] started with url: ', hypertyURL); @@ -51,7 +51,7 @@ class UserAvailabilityReporter extends ContextReporter { // this.syncher = new Syncher(hypertyURL, bus, configuration); // this.discovery = new Discovery(hypertyURL, bus); - this.identityManager = new IdentityManager(hypertyURL, configuration.runtimeURL, bus); + this.identityManager = factory.createIdentityManager(hypertyURL, configuration.runtimeURL, bus); /* this.domain = divideURL(hypertyURL).domain; this.userAvailabilityyDescURL = 'hyperty-catalogue://catalogue.' + this.domain + '/.well-known/dataschema/Context'; @@ -59,9 +59,9 @@ class UserAvailabilityReporter extends ContextReporter { // this.heartbeat = []; - this.syncher.onNotification((event) => { + this.context.syncher.onNotification((event) => { let _this = this; - _this.processNotification(event); + _this.context.processNotification(event); }); @@ -75,13 +75,17 @@ class UserAvailabilityReporter extends ContextReporter { } +get context() { + return this._context; +} + start(){ let _this = this; return new Promise((resolve, reject) => { console.log('[UserAvailabilityReporter.starting]' ); - this.syncher.resumeReporters({store: true}).then((reporters) => { + _this.context.syncher.resumeReporters({store: true}).then((reporters) => { let reportersList = Object.keys(reporters); @@ -89,18 +93,18 @@ start(){ //TODO: filter from contexts instead of returning context[0] - _this.contexts['myAvailability'] = _this._filterResumedContexts(reporters); + _this.context.contexts['myAvailability'] = _this._filterResumedContexts(reporters); - console.log('[UserAvailabilityReporter.start] resuming ', _this.contexts['myAvailability']); + console.log('[UserAvailabilityReporter.start] resuming ', _this.context.contexts['myAvailability']); // set availability to available - _this._onSubscription(_this.contexts['myAvailability']); + _this.context._onSubscription(_this.context.contexts['myAvailability']); /* _this.userAvailability = reporters[reportersList[0]]; _this._onSubscription(_this.userAvailability);*/ - resolve(_this.contexts['myAvailability']); + resolve(_this.context.contexts['myAvailability']); } else { console.log('[UserAvailabilityReporter.start] nothing to resume ', reporters); let name = 'myAvailability'; @@ -121,7 +125,7 @@ _filterResumedContexts(reporters) { let last = 0; return Object.keys(reporters) - .filter(reporter => reporters[reporter].metadata.reporter === this.syncher._owner) + .filter(reporter => reporters[reporter].metadata.reporter === this.context.syncher._owner) .reduce((obj, key) => { if (Date.parse(reporters[key].metadata.lastModified) > last) obj = reporters[key]; return obj; @@ -130,7 +134,7 @@ _filterResumedContexts(reporters) { onResumeReporter(callback) { let _this = this; - _this._onResumeReporter = callback; + _this.context._onResumeReporter = callback; } /* onNotification(event) { @@ -148,7 +152,7 @@ onResumeReporter(callback) { * @return {Promise} */ create(id, init, resources, name = 'myContext') { - return super.create(id, init, resources, name); + return this.context.create(id, init, resources, name); } /* _onSubscription(userAvailability){ @@ -161,17 +165,17 @@ onResumeReporter(callback) { setStatus(newStatus) { // _this.contexts[id].data.values[0].value; let newContext = [{value: newStatus}]; - return super.setContext('myAvailability', newContext); + return this._context.setContext('myAvailability', newContext); } } -export default function activate(hypertyURL, bus, configuration) { +export default function activate(hypertyURL, bus, configuration, factory) { return { name: 'UserAvailabilityReporter', - instance: new UserAvailabilityReporter(hypertyURL, bus, configuration) + instance: new UserAvailabilityReporter(hypertyURL, bus, configuration, factory) }; } diff --git a/src/user-availability/package-lock.json b/src/user-availability/package-lock.json index 274dcc7..be4c8a1 100644 --- a/src/user-availability/package-lock.json +++ b/src/user-availability/package-lock.json @@ -1,6 +1,6 @@ { "name": "user-availability", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/user-availability/package.json b/src/user-availability/package.json index 94da6a2..77811f1 100644 --- a/src/user-availability/package.json +++ b/src/user-availability/package.json @@ -1,6 +1,6 @@ { "name": "user-availability", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Availability is comprised by two Hyperties.", "main": "UserAvailabilityObserver.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "ISC", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0" diff --git a/src/wallet/Wallet.hy.js b/src/wallet/Wallet.hy.js index 58051e2..078ef1a 100644 --- a/src/wallet/Wallet.hy.js +++ b/src/wallet/Wallet.hy.js @@ -1,18 +1,18 @@ -import { Syncher } from 'service-framework/dist/Syncher'; +//import { Syncher } from 'service-framework/dist/Syncher'; import URI from 'urijs'; -import Search from '../utils/Search'; -import IdentityManager from 'service-framework/dist/IdentityManager'; -import { Discovery } from 'service-framework/dist/Discovery'; +//import Search from '../utils/Search'; +//import IdentityManager from 'service-framework/dist/IdentityManager'; +//import { Discovery } from 'service-framework/dist/Discovery'; class Wallet { - constructor(hypertyURL, bus, config) { + constructor(hypertyURL, bus, config, factory) { let uri = new URI(hypertyURL); this.objectDescURL = `hyperty-catalogue://catalogue.${uri.hostname()}/.well-known/dataschema/WalletData`; - this.syncher = new Syncher(hypertyURL, bus, config); - this.identityManager = new IdentityManager(hypertyURL, config.runtimeURL, bus); - this.discovery = new Discovery(hypertyURL, config.runtimeURL, bus); - this.search = new Search(this.discovery, this.identityManager); + this.syncher = factory.createSyncher(hypertyURL, bus, config); + this.identityManager = factory.createIdentityManager(hypertyURL, config.runtimeURL, bus); + this.discovery = factory.createDiscovery(hypertyURL, config.runtimeURL, bus); + this.search = factory.createSearch(this.discovery, this.identityManager); this.currentPosition; this.bus = bus; this.hypertyURL = hypertyURL; @@ -22,10 +22,11 @@ class Wallet { this.messageRetries = config.retries; } + start(callback, identity) { let _this = this; - return new Promise( (resolve, reject) => { + return new Promise((resolve, reject) => { let userProfile; let publicWallets = false; if (identity.profile !== undefined) { @@ -38,8 +39,8 @@ class Wallet { } else { userProfile = { userURL: identity.userURL, guid: identity.guid }; } - - + + let createMessage = { type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, identity: { userProfile: userProfile }, @@ -49,7 +50,7 @@ class Wallet { resource: 'wallet' } }; - + /*Create Message should be like THIS * * let createMessage = { @@ -59,114 +60,167 @@ class Wallet { * */ 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) { - _this._resumeObservers(reply.body.reporter_url).then(function(result) { - + _this._resumeObservers(reply.body.reporter_url).then(function (result) { + if (result != false) { console.log('[Wallet] Resume result :', result); - + let updateBalance = { field: 'balance', data: result.data.balance }; - + let updateTransactions = { field: 'transactions', data: result.data.transactions }; - + + let updateRanking = { + field: 'ranking', + data: result.data.ranking + }; + + 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(); - + } else { - - _this.syncher.subscribe(_this.objectDescURL, reply.body.reporter_url, true, false, true, false, null).then(function(obj) { + + _this.syncher.subscribe(_this.objectDescURL, reply.body.reporter_url, true, false, true, false, null).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); }); resolve(); - - }).catch(function(error) { + + }).catch(function (error) { console.log('[Wallet] error', error); reject(); }); } - - _this._resumeObservers(reply.body.publics_url).then(function(result) { + + _this._resumeObservers(reply.body.publics_url).then(function (result) { if (result != false) { console.log('[Wallet] Resume public wallets :', result); - + let updateWallets = { field: 'wallets', data: result.data.wallets }; - + callback(updateWallets); - + result.onChange('*', (event) => { console.log('[Wallet] New Change :', event); callback(event); }); - + } else { - _this.syncher.subscribe(_this.objectDescURL, reply.body.publics_url, true, false, true, false, null).then(function(obj) { + _this.syncher.subscribe(_this.objectDescURL, reply.body.publics_url, true, false, true, false, null).then(function (obj) { console.log('[Wallet] subscription result public wallets :', result); let updateWallets = { field: 'wallets', data: obj.data.wallets }; - + callback(updateWallets); - + obj.onChange('*', (event) => { console.log('[Wallet] New Change :', event); callback(event); }); }); } - + }); - - }).catch(function(error) { - + + }).catch(function (error) { + }); - - + + } }); }); } + removeWallet() { + + let _this = this; + + return new Promise((resolve, reject) => { + + let deleteMessage = { + type: 'forward', to: 'hyperty://sharing-cities-dsm/wallet-manager', from: _this.hypertyURL, + // identity: { userProfile: userProfile }, + body: { + type: 'delete', + from: _this.hypertyURL, + resource: 'wallet', + value: _this.walletAddress, + } + }; + + console.log('[Wallet] delete message', deleteMessage); + + _this.bus.postMessage(deleteMessage, _this.messageRetries); + resolve(true); + + }) + + } + _resumeObservers(walletURL) { let _this = this; @@ -199,9 +253,9 @@ class Wallet { } } -export default function activate(hypertyURL, bus, config) { +export default function activate(hypertyURL, bus, config, factory) { return { name: 'Wallet', - instance: new Wallet(hypertyURL, bus, config) + instance: new Wallet(hypertyURL, bus, config, factory) }; } diff --git a/src/wallet/Wallet.hy.json b/src/wallet/Wallet.hy.json index 2d35734..407b98e 100644 --- a/src/wallet/Wallet.hy.json +++ b/src/wallet/Wallet.hy.json @@ -1,6 +1,7 @@ { "configuration": { "domain_registration": false, + "domain_routing": false, "retries": 10 }, "hypertyType": [ diff --git a/src/wallet/package-lock.json b/src/wallet/package-lock.json index 518cfd1..6894748 100644 --- a/src/wallet/package-lock.json +++ b/src/wallet/package-lock.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.3.0", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,9 +9,6 @@ "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz", "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w==" }, - "service-framework": { - "version": "github:rethink-project/dev-service-framework#940a85a84cf8722e71d978f7e8c28d52579723ba" - }, "urijs": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.1.tgz", diff --git a/src/wallet/package.json b/src/wallet/package.json index 1b74e74..317327b 100644 --- a/src/wallet/package.json +++ b/src/wallet/package.json @@ -1,6 +1,6 @@ { "name": "Wallet", - "version": "0.4.0", + "version": "0.5.0", "description": "The User Location is comprised by two Hyperties.", "main": "Wallet.hy.js", "scripts": { @@ -9,8 +9,7 @@ "author": "", "license": "Apache 2.0", "dependencies": { - "bootstrap": "^4.1.1", - "service-framework": "github:rethink-project/dev-service-framework#v0.9.0" + "bootstrap": "^4.1.1" }, "devDependencies": { "urijs": "^1.19.0"