forked from reTHINK-project/dev-hyperty-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWorldReporter.hy.js
98 lines (64 loc) · 2.19 KB
/
HelloWorldReporter.hy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* jshint undef: true */
import {Syncher} from 'service-framework/dist/Syncher';
import {divideURL} from '../utils/utils';
import hello from './hello';
/**
* Hyperty Connector;
* @author Paulo Chainho [[email protected]]
* @version 0.1.0
*/
class HelloWorldReporter {
/**
* Create a new HelloWorldReporter
* @param {Syncher} syncher - Syncher provided from the runtime core
*/
constructor(hypertyURL, bus, configuration) {
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');
let _this = this;
_this._domain = divideURL(hypertyURL).domain;
_this._objectDescURL = 'hyperty-catalogue://' + _this._domain + '/.well-known/dataschemas/HelloWorldDataSchema';
let syncher = new Syncher(hypertyURL, bus, configuration);
_this._syncher = syncher;
}
/**
* Create HelloWorld Data Object
* @param {HypertyURL} HypertyURL - Invited
*/
hello(hypertyURL) {
let _this = this;
let syncher = _this._syncher;
return new Promise(function(resolve, reject) {
syncher.create(_this._objectDescURL, [hypertyURL], hello).then(function(helloObjtReporter) {
console.info('1. Return Created Hello World Data Object Reporter', helloObjtReporter);
_this.helloObjtReporter = helloObjtReporter;
helloObjtReporter.onSubscription(function(event) {
console.info('-------- Hello World Reporter received subscription request --------- \n');
// All subscription requested are accepted
event.accept();
});
resolve(helloObjtReporter);
})
.catch(function(reason) {
console.error(reason);
reject(reason);
});
});
}
/**
* Update HelloWorld Data Object
*
*/
bye() {
let _this = this;
console.log('bye:', _this.helloObjtReporter );
_this.helloObjtReporter.data.hello = "Bye!!";
}
}
export default function activate(hypertyURL, bus, configuration) {
return {
name: 'HelloWorldReporter',
instance: new HelloWorldReporter(hypertyURL, bus, configuration)
};
}