cloudcms-server 4.0.0-beta.5 → 4.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,7 +16,8 @@ exports = module.exports = function()
|
|
|
16
16
|
|
|
17
17
|
var pluginPaths = [
|
|
18
18
|
"./plugins/editorial",
|
|
19
|
-
"./plugins/resources"
|
|
19
|
+
"./plugins/resources",
|
|
20
|
+
"./plugins/api_event"
|
|
20
21
|
];
|
|
21
22
|
var plugins = {};
|
|
22
23
|
|
|
@@ -149,21 +150,21 @@ exports = module.exports = function()
|
|
|
149
150
|
var r = {};
|
|
150
151
|
|
|
151
152
|
// allow plugins to bind on("connection") handlers
|
|
152
|
-
r.bindOnSocketConnection = function(socket, provider, callback)
|
|
153
|
+
r.bindOnSocketConnection = function(socket, provider, io, callback)
|
|
153
154
|
{
|
|
154
155
|
var fns = [];
|
|
155
156
|
for (var pluginPath in plugins)
|
|
156
157
|
{
|
|
157
158
|
var plugin = plugins[pluginPath];
|
|
158
159
|
|
|
159
|
-
var fn = function(pluginPath, plugin, socket) {
|
|
160
|
+
var fn = function(pluginPath, plugin, socket, io) {
|
|
160
161
|
return function(done) {
|
|
161
|
-
|
|
162
|
-
plugin.bindSocket(socket, provider);
|
|
162
|
+
|
|
163
|
+
plugin.bindSocket(socket, provider, io);
|
|
163
164
|
|
|
164
165
|
done();
|
|
165
166
|
}
|
|
166
|
-
}(pluginPath, plugin, socket);
|
|
167
|
+
}(pluginPath, plugin, socket, io);
|
|
167
168
|
fns.push(fn);
|
|
168
169
|
}
|
|
169
170
|
|
|
@@ -309,7 +310,7 @@ exports = module.exports = function()
|
|
|
309
310
|
});
|
|
310
311
|
|
|
311
312
|
// allow plugins to register more on() handlers if they wish
|
|
312
|
-
pluginProxy.bindOnSocketConnection(socket, provider, function() {
|
|
313
|
+
pluginProxy.bindOnSocketConnection(socket, provider, io, function() {
|
|
313
314
|
// done
|
|
314
315
|
});
|
|
315
316
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
this awareness plugin adds support for general purpose API events
|
|
4
|
+
the API in 4.0 supports passing API events forward via the message queue to the app server
|
|
5
|
+
the app server then converts these into notifications
|
|
6
|
+
|
|
7
|
+
the UI can register and event listener via socket.io ("onApiEvent").
|
|
8
|
+
a listener binds to an event type + an optional reference
|
|
9
|
+
|
|
10
|
+
when an event is received by the API, it triggers to socket.io emits (one for the general event and the other for the
|
|
11
|
+
event + the reference being acted upon)
|
|
12
|
+
*/
|
|
13
|
+
exports = module.exports = {};
|
|
14
|
+
|
|
15
|
+
var util = require("../../../util/util");
|
|
16
|
+
var socketUtil = require("../../../util/socket");
|
|
17
|
+
|
|
18
|
+
var subscriptionsBound = false;
|
|
19
|
+
|
|
20
|
+
var bindSubscriptions = function(io)
|
|
21
|
+
{
|
|
22
|
+
if (subscriptionsBound) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
subscriptionsBound = true;
|
|
27
|
+
|
|
28
|
+
// LISTEN: "api_event"
|
|
29
|
+
process.broadcast.subscribe("api_event", function (message, channel, done) {
|
|
30
|
+
|
|
31
|
+
if (!done) {
|
|
32
|
+
done = function () {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// the message
|
|
36
|
+
// {
|
|
37
|
+
// "applicationId": applicationId,
|
|
38
|
+
// "deploymentKey": deploymentKey,
|
|
39
|
+
// "host": host,
|
|
40
|
+
// "eventType": eventType,
|
|
41
|
+
// "eventId": eventId,
|
|
42
|
+
// "objectType": objectType,
|
|
43
|
+
// "objectId": objectId,
|
|
44
|
+
// "objectRef": objectRef,
|
|
45
|
+
// "object": object.object
|
|
46
|
+
// };
|
|
47
|
+
|
|
48
|
+
var apiEvent = {};
|
|
49
|
+
apiEvent.type = message.eventType;
|
|
50
|
+
apiEvent.id = message.eventId;
|
|
51
|
+
apiEvent.objectType = message.objectType;
|
|
52
|
+
apiEvent.objectId = message.objectId;
|
|
53
|
+
apiEvent.objectRef = message.objectRef;
|
|
54
|
+
apiEvent.object = message.object;
|
|
55
|
+
|
|
56
|
+
// dispatch for event + reference
|
|
57
|
+
if (apiEvent.objectRef)
|
|
58
|
+
{
|
|
59
|
+
try {
|
|
60
|
+
apiEvent.channelId = "apiEvent-" + apiEvent.type + "_" + apiEvent.objectRef;
|
|
61
|
+
//console.log("api_event -> " + apiEvent.channelId);
|
|
62
|
+
io.to(apiEvent.channelId).emit("apiEvent", apiEvent);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.log(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// dispatch for event
|
|
69
|
+
try {
|
|
70
|
+
apiEvent.channelId = "apiEvent-" + apiEvent.type;
|
|
71
|
+
//console.log("apiEvent -> " + apiEvent.channelId);
|
|
72
|
+
io.to(apiEvent.channelId).emit("apiEvent", apiEvent);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.log(e);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
exports.bindSocket = function(socket, provider, io)
|
|
82
|
+
{
|
|
83
|
+
bindSubscriptions(io);
|
|
84
|
+
|
|
85
|
+
socketUtil.bindGitana(socket, function() {
|
|
86
|
+
|
|
87
|
+
socket.on("onApiEvent", function(eventName, reference, callback) {
|
|
88
|
+
|
|
89
|
+
if (eventName)
|
|
90
|
+
{
|
|
91
|
+
var channelId = "apiEvent-" + eventName;
|
|
92
|
+
|
|
93
|
+
if (reference)
|
|
94
|
+
{
|
|
95
|
+
channelId = eventName + "-" + reference;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// join room for this event
|
|
99
|
+
socket.join(channelId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
callback();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
@@ -5,7 +5,7 @@ var socketUtil = require("../../../util/socket");
|
|
|
5
5
|
|
|
6
6
|
var subscriptionsBound = false;
|
|
7
7
|
|
|
8
|
-
var bindSubscriptions = function()
|
|
8
|
+
var bindSubscriptions = function(io)
|
|
9
9
|
{
|
|
10
10
|
if (subscriptionsBound) {
|
|
11
11
|
return;
|
|
@@ -45,14 +45,14 @@ var bindSubscriptions = function()
|
|
|
45
45
|
// fire to reference
|
|
46
46
|
try {
|
|
47
47
|
if (reference) {
|
|
48
|
-
|
|
48
|
+
io.to(reference).emit("watchResource", reference, watchObject);
|
|
49
49
|
}
|
|
50
50
|
} catch (e) { }
|
|
51
51
|
|
|
52
52
|
// fire to head reference
|
|
53
53
|
try {
|
|
54
54
|
if (headReference) {
|
|
55
|
-
|
|
55
|
+
io.to(headReference).emit("watchResource", headReference, watchObject);
|
|
56
56
|
}
|
|
57
57
|
} catch (e) { }
|
|
58
58
|
}
|
|
@@ -61,9 +61,9 @@ var bindSubscriptions = function()
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
exports.bindSocket = function(socket, provider)
|
|
64
|
+
exports.bindSocket = function(socket, provider, io)
|
|
65
65
|
{
|
|
66
|
-
bindSubscriptions();
|
|
66
|
+
bindSubscriptions(io);
|
|
67
67
|
|
|
68
68
|
socketUtil.bindGitana(socket, function() {
|
|
69
69
|
|
|
@@ -72,11 +72,11 @@ var handleNotificationMessages = function(items, callback) {
|
|
|
72
72
|
var fns = [];
|
|
73
73
|
for (var i = 0; i < items.length; i++)
|
|
74
74
|
{
|
|
75
|
-
var fn = function(item,
|
|
75
|
+
var fn = function(item, index) {
|
|
76
76
|
return function(done) {
|
|
77
77
|
|
|
78
78
|
//logFn("WORKING ON ITEM: " + i + ", item: " + JSON.stringify(item, null, " "));
|
|
79
|
-
console.log("WORKING ON ITEM: " +
|
|
79
|
+
console.log("WORKING ON ITEM: " + index + ", item: " + JSON.stringify(item, null, " "));
|
|
80
80
|
|
|
81
81
|
var operation = item.operation;
|
|
82
82
|
|
|
@@ -540,6 +540,8 @@ var handleNotificationMessages = function(items, callback) {
|
|
|
540
540
|
|
|
541
541
|
var host = determineHost(item);
|
|
542
542
|
|
|
543
|
+
var _fns = [];
|
|
544
|
+
|
|
543
545
|
var deployments = item.deployments;
|
|
544
546
|
if (deployments && deployments.length > 0)
|
|
545
547
|
{
|
|
@@ -554,17 +556,77 @@ var handleNotificationMessages = function(items, callback) {
|
|
|
554
556
|
"host": host,
|
|
555
557
|
"deployment": deployment
|
|
556
558
|
};
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
559
|
+
|
|
560
|
+
var _fn = function(message) {
|
|
561
|
+
return function(d) {
|
|
562
|
+
// broadcast event
|
|
563
|
+
process.broadcast.publish("deployment_synced", message, function(err) {
|
|
564
|
+
if (err) {
|
|
565
|
+
logInfo("published deployment_synced message. err:" + err + "\nmessage: " + JSON.stringify(message,null,2));
|
|
566
|
+
}
|
|
567
|
+
return done(err);
|
|
568
|
+
});
|
|
562
569
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
570
|
+
}(message);
|
|
571
|
+
_fns.push(_fn);
|
|
566
572
|
}
|
|
567
573
|
}
|
|
574
|
+
|
|
575
|
+
async.parallelLimit(_fns, 4, function(err) {
|
|
576
|
+
done(err);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
else if (operation === "api_event")
|
|
580
|
+
{
|
|
581
|
+
var eventType = item.type;
|
|
582
|
+
var eventId = item.id;
|
|
583
|
+
var objects = item.objects;
|
|
584
|
+
|
|
585
|
+
var host = determineHost(item);
|
|
586
|
+
|
|
587
|
+
var _fns = [];
|
|
588
|
+
if (objects && objects.length > 0)
|
|
589
|
+
{
|
|
590
|
+
for (var z = 0; z < objects.length; z++)
|
|
591
|
+
{
|
|
592
|
+
var object = objects[z];
|
|
593
|
+
|
|
594
|
+
var applicationId = object.applicationId;
|
|
595
|
+
var deploymentKey = item.deploymentKey;
|
|
596
|
+
|
|
597
|
+
var objectType = object.type; // sidekickMessage
|
|
598
|
+
var objectId = object.id;
|
|
599
|
+
var objectRef = object.ref;
|
|
600
|
+
|
|
601
|
+
var publishMessage = {
|
|
602
|
+
"applicationId": applicationId,
|
|
603
|
+
"deploymentKey": deploymentKey,
|
|
604
|
+
"host": host,
|
|
605
|
+
"eventType": eventType,
|
|
606
|
+
"eventId": eventId,
|
|
607
|
+
"objectType": objectType,
|
|
608
|
+
"objectId": objectId,
|
|
609
|
+
"objectRef": objectRef,
|
|
610
|
+
"object": object.object
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
var _fn = function(publishMessage) {
|
|
614
|
+
return function(d) {
|
|
615
|
+
// broadcast event
|
|
616
|
+
process.broadcast.publish("api_event", publishMessage, function(err) {
|
|
617
|
+
if (err) {
|
|
618
|
+
logInfo("published api_event message. err:" + err + "\nmessage: " + JSON.stringify(publishMessage,null,2));
|
|
619
|
+
}
|
|
620
|
+
return d(err);
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
}(publishMessage);
|
|
624
|
+
_fns.push(_fn);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
async.parallelLimit(_fns, 4, function(err) {
|
|
628
|
+
done(err);
|
|
629
|
+
});
|
|
568
630
|
}
|
|
569
631
|
else
|
|
570
632
|
{
|
package/package.json
CHANGED