Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #97 from reTHINK-project/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
luistduarte authored Aug 31, 2018
2 parents a5daf9f + 00d38bb commit 147baa2
Show file tree
Hide file tree
Showing 50 changed files with 581 additions and 781 deletions.
40 changes: 35 additions & 5 deletions examples/device-manager/DeviceManager.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
<div cla'hyperties:descriptor'ss="result-pannel">
<H3>Wallet Hyperty Deployed</H3>
</div>
<div class="device-details">
<H3>Device Manager</H3>
<h5>Device Info</h5>
<button class="create-device-btn waves-effect waves-light btn"><i class="material-icons left"></i>Create Device</button>
<br>
<a class="device-data hide"></a>
<br>
<br>
<h5 class="streams-label hide">Streams Info</h5>
<h6 class="streams-label hide">List</h6>
<ul id="streams-list" class="streams-list"></ul>
<button class="create-stream-btn waves-effect waves-light btn hide"><i class="material-icons left"></i>Add new Stream</button>

<div class="create-stream hide">
<form class="form col s12">

<div class="row">
<div class="input-field col s12">
<input placeholder="Platform ID, for example edp" required aria-required="true" type="text" class="platformID" >
<label style="width: 100%;">Platform ID</label>
</div>
<div class="input-field col s12">
<input class="platformUID" name="platformUID" type="text">
<label for="platformUID">platform User ID</label>
</div>
</div>
<div class="row">
<div class="input-field col s8">
<button class="new-stream-btn waves-effect waves-light btn" type="submit">Create</button>
</div>
</div>
</form>
</div>

<a class="token-label">Wallet Tokens</a>
<a class="token-value">X</a>

</div>
102 changes: 100 additions & 2 deletions examples/device-manager/DeviceManagerDemo.js
Original file line number Diff line number Diff line change
@@ -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');
}
Expand All @@ -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 = $('<li/>')
.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 = $('<li/>')
.text(text);
var streams_list = creating.find('.streams-list');
streams_list.append($userAvailability);
createStreamBtn.addClass("hide");
debugger;
});
});
*/

});
});
}
2 changes: 1 addition & 1 deletion examples/user-availability/UserAvailabilityReporterDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions examples/wallet/Wallet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
<H3>Wallet Hyperty Deployed</H3>
</div>

<a class="token-label">Wallet Tokens</a>
<a class="token-value">X</a>
<a class="token-label">Wallet</a>
<p>- Tokens: <a class="token-value">-</a></p>
<p>- Ranking: <a class="wallet-ranking">-</a></p>
<p>- Bonus credit: <a class="bonus-credit">-</a></p>

<button class="wallet-delete">Delete</button>


19 changes: 16 additions & 3 deletions examples/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dev-hyperty",
"version": "0.4.0",
"version": "0.5.0",
"description": "Source code of hyperties",
"main": ".eslintrc.js",
"directories": {
Expand Down
24 changes: 12 additions & 12 deletions src/connector/Connector.hy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');
Expand All @@ -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) => {

Expand Down Expand Up @@ -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)
};

}
13 changes: 5 additions & 8 deletions src/connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/connector/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"name": "connector",
"version": "0.4.0",
"version": "0.5.0",
"description": "Hyperty to make webrtc call",
"main": "Connector.hy.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"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"
}
Expand Down
22 changes: 11 additions & 11 deletions src/device-manager/DeviceManager.hy.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
};
}
Loading

0 comments on commit 147baa2

Please sign in to comment.