Skip to content

Commit

Permalink
Merge pull request #291 from reTHINK-project/develop
Browse files Browse the repository at this point in the history
dev to master
  • Loading branch information
luistduarte committed May 23, 2019
2 parents b7347e3 + 525b852 commit 9629a3b
Show file tree
Hide file tree
Showing 36 changed files with 2,889 additions and 6,296 deletions.
33 changes: 30 additions & 3 deletions dist/PEP.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/ReThinkCtx.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/Runtime.js

Large diffs are not rendered by default.

33 changes: 3 additions & 30 deletions dist/Runtime.min.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/RuntimeCatalogue.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/StorageManager.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/minibus.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/rethink.js

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/sandbox.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = function(config) {
basePath: '',
frameworks: ['mocha', 'chai', 'sinon'],
files: [
'./test/*.spec.js'
'./test/SyncStorageManager.spec.js'
],
exclude: [
'./test/GraphConnector.spec.js',
Expand Down
2,313 changes: 1,547 additions & 766 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "runtime-core",
"version": "0.16.0",
"version": "0.17.0",
"description": "core runtime development",
"files": [
"dist"
Expand All @@ -10,7 +10,7 @@
"test": "karma start",
"test:lint": "eslint --config .eslintrc.yml ./src/",
"build:doc": "./node_modules/.bin/esdoc -c esdoc.json",
"build:dev": "cross-env MODE=dev webpack && cp -r dist ../dev-hyperty-toolkit/node_modules/runtime-core && cp -r dist ../dev-runtime-browser/node_modules/runtime-core && cp -r dist ../dev-dsm-app/node_modules/runtime-core",
"build:dev": "cross-env MODE=dev webpack && cp -r dist ../dev-hyperty-toolkit/node_modules/runtime-core && cp -r dist ../dev-dsm-app/node_modules/runtime-core",
"build:dev:monitor": "cross-env MODE=dev cross-env MONITOR=true webpack",
"build:prod": "cross-env MODE=prod webpack -p",
"build:light": "cross-env MODE=light webpack",
Expand Down Expand Up @@ -40,7 +40,8 @@
"@babel/polyfill": "^7.0.0",
"babel-plugin-dynamic-import-webpack": "^1.1.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"loglevel": "^1.5.1"
"loglevel": "^1.5.1",
"pouchdb": "^7.0.0"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
Expand All @@ -59,10 +60,9 @@
"cross-env": "^5.1.3",
"dexie": "^1.5.1",
"dexie-observable": "^1.0.0-beta.4",
"dexie-syncable": "^1.0.0-beta.4",
"esdoc": "^0.5.2",
"eslint": "^4.14.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-import": "^2.16.0",
"hex64": "^0.4.0",
"jsrsasign": "^7.2.2",
"karma": "^1.7.1",
Expand All @@ -71,7 +71,7 @@
"karma-coverage": "^1.1.2",
"karma-firefox-launcher": "^1.1.0",
"karma-html-reporter": "^0.2.7",
"karma-htmlfile-reporter": "^0.3.5",
"karma-htmlfile-reporter": "^0.3.8",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.4",
"karma-sinon": "^1.0.5",
Expand All @@ -85,8 +85,8 @@
"sync-client": "^1.0.0-beta.11",
"tv4": "^1.2.7",
"uglifyjs-webpack-plugin": "^1.1.5",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack": "^4.29.5",
"webpack-cli": "^3.2.3",
"webpack-monitor": "^1.0.14"
}
}
11 changes: 8 additions & 3 deletions src/bus/MessageBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class MessageBus extends Bus {
//1. message batch processing with setInterval
//2. resolve default gateway/protostub with register.resolve

constructor(registry) {
constructor(registry, runtimeUrl) {
super();
this._registry = registry;
this._forwards = {};
this._runtimeUrl = runtimeUrl;

this._pipelineIn = new Pipeline((error) => {
log.error('PIPELINE-ERROR: ', JSON.stringify(error));
Expand Down Expand Up @@ -83,7 +84,7 @@ class MessageBus extends Bus {
if (itemList) {
//do not publish on default address, because of loopback cycle
_this._publishOn(itemList, msg);
} else {
} else if (!msg.to.includes(_this._runtimeUrl)) {
//if there is no listener, send to external interface
_this._onPostMessage(msg);
}
Expand Down Expand Up @@ -179,7 +180,11 @@ class MessageBus extends Bus {
if (!refCount) {
let forwardListener = _this.addListener(from, (msg) => {
log.info('MB-PUBLISH: ( ' + from + ' )');
_this._onPostMessage(msg);
// hack to skip external routes for messages coming from external hosts
// and messages targeting internal core runtime components
if (!(msg.body && msg.body.source && msg.body.source.includes('/protostub/')) &&
!msg.to.includes(_this._runtimeUrl))
_this._onPostMessage(msg);
});

refCount = {
Expand Down
34 changes: 33 additions & 1 deletion src/chatManager/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Chat {
if (!dataObjectReporter) throw new Error('[ChatController] The data object reporter is necessary parameter ');
let _this = this;


_this.controllerMode = 'reporter';

// Handler to process received files
Expand Down Expand Up @@ -352,11 +353,14 @@ class Chat {
userProfile: _this.myIdentity
};

let input = {};
input.anonymous = true;


// TODO: change chatmessages to resource - chat, file
// TODO: change message to hypertyResource - https://github.com/reTHINK-project/dev-service-framework/tree/develop/docs/datamodel/data-objects/hyperty-resource
// TODO: handle with multiple resources - if the "message" will be different for each type of resources
dataObject.addChild(msg, sender).then(function(dataObjectChild) {
dataObject.addChild(msg, sender, input).then(function(dataObjectChild) {
console.log('[ChatManager.ChatController][addChild - Chat Message]: ', dataObjectChild);
//resolve(dataObjectChild);

Expand Down Expand Up @@ -422,6 +426,34 @@ class Chat {
_this._onMessage = callback;
}

/**
* This function is used to receive typing events.
* @param {Function} callback Function to handle typing event
*/

onTyping(callback) {
if (this._dataObjectReporter) this._dataObjectReporter.onEvent((event)=>{
if (event.value === 'typing') {
callback();
}
});
else this._dataObjectObserver.onEvent((event)=>{
if (event.value === 'typing') {
callback();
}
});
}

/**
* This function is used to trigger typing events.
*/

typing() {
if (this._dataObjectReporter) this._dataObjectReporter.sendEvent('typing');
else this._dataObjectObserver.sendEvent('typing');
}


/**
* [onUserAdded description]
* @param {Function} callback [description]
Expand Down
42 changes: 34 additions & 8 deletions src/chatManager/SimpleChatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import Chat from './Chat';
import { UserInfo } from './UserInfo';

/**
* Hyperty Simple Group Chat Manager API
* Hyperty Simple Group Chat Manager API
* @author Vitor Silva [vitor-t-silva@telecom.pt]
* @version 0.1.0
*/
class SimpleSimpleChatManager {
class SimpleChatManager {

constructor(myUrl, bus, configuration, syncher, factory) {
if (!myUrl) throw new Error('[SimpleChatManager.constructor] The myUrl is a needed parameter');
Expand All @@ -69,6 +69,7 @@ class SimpleSimpleChatManager {
_this._bus = bus;
_this._syncher = syncher;
_this._domain = domain;
_this._defaultStubTriggered = false;

// _this.discovery = discovery;
_this.identityManager = identityManager;
Expand Down Expand Up @@ -118,22 +119,28 @@ class SimpleSimpleChatManager {
// TODO: replace the 200 for Message.Response
event.ack(200);

_this._observersControllers[event.url].closeEvent = event;
if (_this._onNotification) { _this._onNotification(event); }

delete _this._observersControllers[event.url];
if ( _this._observersControllers[event.url]){
_this._observersControllers[event.url].closeEvent = event;

_this._observersControllers.closeEvent = event;
delete _this._observersControllers[event.url];

_this.communicationObject = communicationObject;
_this._observersControllers.closeEvent = event;

_this.communicationObject = communicationObject;

}


/*
for (let url in this._reportersControllers) {
this._reportersControllers[url].close(event);
}
for (let url in this._observersControllers) {
this._observersControllers[url].close(event);
}
}*/

}
}
Expand Down Expand Up @@ -252,6 +259,25 @@ class SimpleSimpleChatManager {
onInvitation(callback) {
let _this = this;
_this._onInvitation = callback;

_this._triggerDefaultStubDeployment();
}

// send message to trigger domain default stub to ensure incoming messages are received

_triggerDefaultStubDeployment(){
let pingMessage = { from: this._myUrl, to: this._domain, type: 'execute' };
if (!this._defaultStubTriggered) this._bus.postMessage(pingMessage);
this._defaultStubTriggered = true;
}

/**
* This function is used to handle notifications about incoming invitations to join a Group Chat.
* @param {Function} CreateEvent The CreateEvent fired by the Syncher when an invitaion is received
*/
onNotification(callback) {
let _this = this;
_this._onNotification = callback;
}

/**
Expand Down Expand Up @@ -303,4 +329,4 @@ class SimpleSimpleChatManager {

}

export default SimpleSimpleChatManager;
export default SimpleChatManager;
15 changes: 15 additions & 0 deletions src/identity/IdentityHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as logger from 'loglevel';
import Identities from './Identities';
import MsgBusHandlers from '../runtime/MsgBusHandlers';
let log = logger.getLogger('IdentityHandler');

class IdentityHandler {
Expand Down Expand Up @@ -41,11 +42,16 @@ class IdentityHandler {
return false;
}

if (message.type === 'event') {
return false;
}

// Signalling Messages between P2P Stubs don't have Identities. FFS
if (_from.includes('/p2prequester/') || _from.includes('/p2phandler/')) {
return false;
}


let splitFrom = (_from).split('://');
let fromSchema = splitFrom[0];
let isToIgnore = schemasToIgnore.indexOf(fromSchema) === -1;
Expand All @@ -62,6 +68,15 @@ class IdentityHandler {

if (!this._isToSetID(message)) return resolve(message);

if (message.body && message.body.value && message.body.value.anonymous){
if (message.body.identity && message.body.identity.guid)
message.body.identity = { userProfile: { guid: message.body.identity.guid } };
else message.body.identity = { userProfile: { guid: 'anonymous' } };
return resolve(message);

}


/* let from = message.from;
let sourceURL = undefined;
if ( message.hasOwnProperty('body') && message.body.hasOwnProperty('source')) {
Expand Down
2 changes: 1 addition & 1 deletion src/identity/IdentityModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ class IdentityModule {
if (res.body.code < 300) {
let result = res.body.value;
resolve(result);
} else resolve(res.body.value.body.params, identity);
} else resolve(oldIdentity);
});
} catch (err) {
reject('In sendRefreshMessage on postMessage error: ' + err);
Expand Down
2 changes: 1 addition & 1 deletion src/registry/Registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ class Registry {

if (url.includes(_this.runtimeURL) || url.includes('://sandbox/')) {
log.error('[Registry - resolve] URL to be resolved should have listeners ', url);
reject('[Registry - resolve] URL to be resolved should have listeners ', url);
return reject('[Registry - resolve] URL to be resolved should have listeners ', url);
}

// resolve the domain protostub in case of a message to global registry
Expand Down
2 changes: 1 addition & 1 deletion src/rethink/IdentitiesGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IdentitiesGUI {
let funcName = msg.body.method;
console.log('[IdentitiesGUI.listener] received msg: ' + msg);

if (funcName === 'openPopup') {
if (funcName === 'login') {
let urlreceived = msg.body.params.urlreceived;

_this._openPopup(urlreceived).then((returnedValue) => {
Expand Down
3 changes: 2 additions & 1 deletion src/rethink/rethink.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const rethink = {

let runtime = new RuntimeUA(runtimeDescriptor, runtimeFactory, domain);

// window.runtime = runtime;

window.rethink = runtime;

runtime.init(guid).then((result) => {

Expand Down
Loading

0 comments on commit 9629a3b

Please sign in to comment.