-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQondrite.qml
110 lines (88 loc) · 3.03 KB
/
Qondrite.qml
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
99
100
101
102
103
104
105
106
107
108
109
110
import QtQml 2.0
import Qt.WebSockets 1.0
import "asteroid/dist/asteroid.qml.js" as Ast
import "qmlutils/Log.js" as Log
WebSocket {
property var ceres
property string meteor_url
signal close();
signal error();
signal open();
id: wsid
active: false
// Component.onCompleted: if (url !== undefined) _connect();
onMeteor_urlChanged: _connect();
// onUrlChanged: _connect();
function _connect() {
console.log("CEres " + meteor_url + " is a go");
// if (ceres !== undefined) {
console.log("X");
ceres = new Ast.Asteroid(wsid, meteor_url.toString(), false, function(event) { console.log("Asteroid:" + event.timestamp + ":" + event.type + ": " + event.message ); });
// delete ceres;
// }
console.log("done");
}
function subscribe(publishedName) {
var plSub;
var args = Array.prototype.slice.call(arguments);
console.log(Log.serialize(args));
var params = args.slice(2);
params.unshift(publishedName);
console.log(Log.serialize(params));
if (ceres !== undefined) {
plSub = ceres.subscribe.apply(ceres, params);
// plSub = ceres.subscribe(publishedName);
plSub.ready.then(args[1]);
}
return plSub;
}
function update(collection, id, data) {
if (collection !== undefined && id !== undefined) {
collection.update(id, data);
}
}
function getCollection(collection) {
var coll;
if (ceres !== undefined)
coll = ceres.getCollection(collection);
return coll;
}
function reactiveQuery(collectionHandle, selector) {
var rq = collectionHandle.reactiveQuery( selector === undefined ? {} : selector );
return rq;
}
function setInterval(callback, timeout) {
console.log("wsid.setInterval");
var obj = Qt.createQmlObject('import QtQuick 2.0; Timer {running: false; repeat: true; interval: ' + timeout + '}', wsid, "setTimeout");
obj.triggered.connect(callback);
obj.running = true;
return obj;
}
function setTimeout(callback, timeout) {
console.log("wsid.setTimeout");
var obj = Qt.createQmlObject('import QtQuick 2.0; Timer {running: false; repeat: false; interval: ' + timeout + '}', wsid, "setTimeout");
obj.triggered.connect(callback);
obj.running = true;
return obj;
}
function clearTimeout(timer) {
timer.running = false;
timer.destroy(1);
return timer;
}
function clearInterval(timer) {
clearTimeout(timer);
}
onStatusChanged: {
if (status === WebSocket.Open) {
console.log("WebSocket Open")
wsid.open();
} else if (status === WebSocket.Error) {
console.log("WebSocket error! " + wsid.errorString);
wsid.error();
} else if (status === WebSocket.Closed) {
console.log("WebSocket Closed");
wsid.close();
}
}
}