@interopio/fdc3 2.1.0 → 2.1.2
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.
- package/changelog.md +8 -0
- package/dist/fdc3.electron.es.js +807 -488
- package/dist/fdc3.electron.umd.js +807 -488
- package/dist/fdc3.es.js +807 -488
- package/dist/fdc3.umd.js +807 -488
- package/package.json +3 -3
package/dist/fdc3.umd.js
CHANGED
|
@@ -113,17 +113,95 @@
|
|
|
113
113
|
const defaultChannelsProps = ["id", "type", "broadcast", "addContextListener", "getCurrentContext"];
|
|
114
114
|
const defaultContextProps = ["type"];
|
|
115
115
|
const defaultGlue42APIs = ["contexts", "channels", "interop", "intents", "appManager", "windows"];
|
|
116
|
-
const responseInteropMethodPrefix = "T42.FDC3.Open.Listener.Response";
|
|
117
116
|
const glueChannelNamePrefix = "___channel___";
|
|
118
117
|
const fdc3NothingContextType = "fdc3.nothing";
|
|
119
118
|
const Glue42EnterpriseNoAppWindow = "no-app-window";
|
|
120
119
|
const RaiseTimeoutMs = 75 * 1000;
|
|
121
|
-
const IntentsMethodPrefix = "Tick42.FDC3.Intents.";
|
|
120
|
+
const IntentsMethodPrefix = "Tick42.FDC3.Intents.";
|
|
121
|
+
const Fdc3SupportedIntentTypes = {
|
|
122
|
+
"CreateInteraction": [
|
|
123
|
+
"fdc3.contactList",
|
|
124
|
+
"fdc3.interaction"
|
|
125
|
+
],
|
|
126
|
+
"StartCall": [
|
|
127
|
+
"fdc3.contact",
|
|
128
|
+
"fdc3.contactList"
|
|
129
|
+
],
|
|
130
|
+
"StartChat": [
|
|
131
|
+
"fdc3.contact",
|
|
132
|
+
"fdc3.contactList",
|
|
133
|
+
"fdc3.chat.initSettings"
|
|
134
|
+
],
|
|
135
|
+
"StartEmail": [
|
|
136
|
+
"fdc3.email"
|
|
137
|
+
],
|
|
138
|
+
"SendChatMessage": [
|
|
139
|
+
"fdc3.chat.message"
|
|
140
|
+
],
|
|
141
|
+
"ViewAnalysis": [
|
|
142
|
+
"fdc3.instrument",
|
|
143
|
+
"fdc3.organization",
|
|
144
|
+
"fdc3.portfolio"
|
|
145
|
+
],
|
|
146
|
+
"ViewChat": [
|
|
147
|
+
"fdc3.chat.room",
|
|
148
|
+
"fdc3.contact",
|
|
149
|
+
"fdc3.contactList"
|
|
150
|
+
],
|
|
151
|
+
"ViewChart": [
|
|
152
|
+
"fdc3.chart",
|
|
153
|
+
"fdc3.instrument",
|
|
154
|
+
"fdc3.instrumentList",
|
|
155
|
+
"fdc3.portfolio",
|
|
156
|
+
"fdc3.position"
|
|
157
|
+
],
|
|
158
|
+
"ViewHoldings": [
|
|
159
|
+
"fdc3.instrument",
|
|
160
|
+
"fdc3.instrumentList",
|
|
161
|
+
"fdc3.organization"
|
|
162
|
+
],
|
|
163
|
+
"ViewInstrument": [
|
|
164
|
+
"fdc3.instrument"
|
|
165
|
+
],
|
|
166
|
+
"ViewInteractions": [
|
|
167
|
+
"fdc3.contact",
|
|
168
|
+
"fdc3.instrument",
|
|
169
|
+
"fdc3.organization"
|
|
170
|
+
],
|
|
171
|
+
"ViewMessages": [
|
|
172
|
+
"fdc3.chat.searchCriteria"
|
|
173
|
+
],
|
|
174
|
+
"ViewNews": [
|
|
175
|
+
"fdc3.country",
|
|
176
|
+
"fdc3.instrument",
|
|
177
|
+
"fdc3.instrumentList",
|
|
178
|
+
"fdc3.organization",
|
|
179
|
+
"fdc3.portfolio"
|
|
180
|
+
],
|
|
181
|
+
"ViewOrders": [
|
|
182
|
+
"fdc3.contact",
|
|
183
|
+
"fdc3.instrument",
|
|
184
|
+
"fdc3.organization"
|
|
185
|
+
],
|
|
186
|
+
"ViewProfile": [
|
|
187
|
+
"fdc3.contact",
|
|
188
|
+
"fdc3.organization"
|
|
189
|
+
],
|
|
190
|
+
"ViewQuote": [
|
|
191
|
+
"fdc3.instrument"
|
|
192
|
+
],
|
|
193
|
+
"ViewResearch": [
|
|
194
|
+
"fdc3.contact",
|
|
195
|
+
"fdc3.instrument",
|
|
196
|
+
"fdc3.organization"
|
|
197
|
+
]
|
|
198
|
+
};
|
|
122
199
|
|
|
123
|
-
const
|
|
200
|
+
const ioConnectFDC3SystemMethod = "FDC3.Collaborate";
|
|
124
201
|
const PrivateChannelPrefix = "___privateFDC3Channel___";
|
|
125
202
|
var PrivateChannelEventMethods;
|
|
126
203
|
(function (PrivateChannelEventMethods) {
|
|
204
|
+
PrivateChannelEventMethods["ListenerAdded"] = "listenerAdded";
|
|
127
205
|
PrivateChannelEventMethods["OnAddContextListener"] = "onAddContextListener";
|
|
128
206
|
PrivateChannelEventMethods["OnUnsubscribe"] = "onUnsubscribe";
|
|
129
207
|
PrivateChannelEventMethods["OnDisconnect"] = "onDisconnect";
|
|
@@ -876,7 +954,7 @@
|
|
|
876
954
|
/** See `Decoder.number` */
|
|
877
955
|
var number = Decoder.number;
|
|
878
956
|
/** See `Decoder.boolean` */
|
|
879
|
-
|
|
957
|
+
Decoder.boolean;
|
|
880
958
|
/** See `Decoder.anyJson` */
|
|
881
959
|
var anyJson = Decoder.anyJson;
|
|
882
960
|
/** See `Decoder.unknownJson` */
|
|
@@ -948,31 +1026,35 @@
|
|
|
948
1026
|
const optionalTargetApp = optional(appIdentifierDecoder);
|
|
949
1027
|
const optionalAppIdentifier = optional(targetAppDecoder);
|
|
950
1028
|
const optionalNonEmptyStringDecoder = optional(nonEmptyStringDecoder);
|
|
951
|
-
const
|
|
952
|
-
const
|
|
953
|
-
channelId: nonEmptyStringDecoder,
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
replayContextTypes: optional(array(string()))
|
|
1029
|
+
const SystemMethodActionDecoder = oneOf(constant("joinPrivateChannel"), constant("publishOnPrivateChannel"), constant("addedContextListenerOnPrivateChannel"), constant("removedContextListenerOnPrivateChannel"), constant("disconnectedFromPrivateChannel"), constant("startupContextOpened"));
|
|
1030
|
+
const CollaborationObjectDecoder = object({
|
|
1031
|
+
channelId: optional(nonEmptyStringDecoder),
|
|
1032
|
+
contextType: optional(nonEmptyStringDecoder),
|
|
1033
|
+
payload: optional(contextDecoder)
|
|
957
1034
|
});
|
|
958
1035
|
const SystemMethodInvocationArgumentDecoder = object({
|
|
959
|
-
action:
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
const ContextListenerResponseDecoder = object({
|
|
963
|
-
listenerInvoked: optional(boolean())
|
|
1036
|
+
action: SystemMethodActionDecoder,
|
|
1037
|
+
correlationId: nonEmptyStringDecoder,
|
|
1038
|
+
collaborationObject: optional(CollaborationObjectDecoder)
|
|
964
1039
|
});
|
|
965
|
-
object({
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1040
|
+
const FDC3StartupContextDecoder = object({
|
|
1041
|
+
fdc3: object({
|
|
1042
|
+
collaborationId: nonEmptyStringDecoder,
|
|
1043
|
+
openApp: object({
|
|
1044
|
+
appId: nonEmptyStringDecoder,
|
|
1045
|
+
instanceId: nonEmptyStringDecoder
|
|
1046
|
+
}),
|
|
1047
|
+
context: object({
|
|
1048
|
+
contextType: optional(string()),
|
|
1049
|
+
payload: contextDecoder
|
|
1050
|
+
})
|
|
1051
|
+
})
|
|
970
1052
|
});
|
|
971
1053
|
|
|
972
1054
|
class GlueController {
|
|
973
1055
|
constructor(channelsParser) {
|
|
974
1056
|
this.channelsParser = channelsParser;
|
|
975
|
-
this.defaultGluePromiseTimeout =
|
|
1057
|
+
this.defaultGluePromiseTimeout = 120 * 1000;
|
|
976
1058
|
}
|
|
977
1059
|
get gluePromise() {
|
|
978
1060
|
return this.glueInitPromise.then(this.initializeLogger.bind(this));
|
|
@@ -1028,6 +1110,15 @@
|
|
|
1028
1110
|
return this.glue.intents.raise(request);
|
|
1029
1111
|
});
|
|
1030
1112
|
}
|
|
1113
|
+
getMyWindowContext() {
|
|
1114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1115
|
+
const myWin = this.getMyWindow();
|
|
1116
|
+
if (!myWin) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
return myWin.getContext();
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1031
1122
|
addIntentListener(intent, handler) {
|
|
1032
1123
|
const registerMethodExists = this.glue.intents.register;
|
|
1033
1124
|
return registerMethodExists
|
|
@@ -1049,20 +1140,15 @@
|
|
|
1049
1140
|
}
|
|
1050
1141
|
updateContextWithLatestFdc3Type(contextId, context) {
|
|
1051
1142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
data: this.channelsParser.parseFDC3ContextToGlueContexts(context),
|
|
1056
|
-
latest_fdc3_type: this.channelsParser.mapFDC3TypeToChannelsDelimiter(context.type)
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
return this.updateContext(contextId, Object.assign(Object.assign({}, prevContextData), { data: Object.assign(Object.assign({}, prevContextData.data), this.channelsParser.parseFDC3ContextToGlueContexts(context)), latest_fdc3_type: this.channelsParser.mapFDC3TypeToChannelsDelimiter(context.type) }));
|
|
1143
|
+
const { path, value } = this.channelsParser.parseFDC3ContextToGlueContexts(context);
|
|
1144
|
+
const latestTypePathValue = { path: "latest_fdc3_type", value: this.channelsParser.mapFDC3TypeToChannelsDelimiter(context.type) };
|
|
1145
|
+
yield this.contextsSetPaths(contextId, [{ path: `data.${path}`, value: value }, latestTypePathValue]);
|
|
1060
1146
|
});
|
|
1061
1147
|
}
|
|
1062
1148
|
channelsUpdate(channelId, context) {
|
|
1063
1149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1064
|
-
const
|
|
1065
|
-
return this.glue.channels.publish(
|
|
1150
|
+
const { path, value } = this.channelsParser.parseFDC3ContextToGlueContexts(context);
|
|
1151
|
+
return this.glue.channels.publish({ [path]: value }, channelId);
|
|
1066
1152
|
});
|
|
1067
1153
|
}
|
|
1068
1154
|
joinChannel(channelId) {
|
|
@@ -1100,8 +1186,8 @@
|
|
|
1100
1186
|
const win = this.glue.windows.my();
|
|
1101
1187
|
return isValidNonEmptyObject(win) ? win : undefined;
|
|
1102
1188
|
}
|
|
1103
|
-
|
|
1104
|
-
return this.glue.interop.instance
|
|
1189
|
+
getMyInteropInstance() {
|
|
1190
|
+
return this.glue.interop.instance;
|
|
1105
1191
|
}
|
|
1106
1192
|
getGlueVersion() {
|
|
1107
1193
|
var _a;
|
|
@@ -1110,21 +1196,14 @@
|
|
|
1110
1196
|
registerOnInstanceStopped(cb) {
|
|
1111
1197
|
return this.glue.appManager.onInstanceStopped(cb);
|
|
1112
1198
|
}
|
|
1113
|
-
invokeMethod(methodName, instance, argumentObj) {
|
|
1114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1115
|
-
const args = ContextListenerResponseDecoder.runWithException(argumentObj);
|
|
1116
|
-
return this.glue.interop.invoke(methodName, args, { instance });
|
|
1117
|
-
});
|
|
1118
|
-
}
|
|
1119
1199
|
unregisterMethod(methodName) {
|
|
1120
1200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1121
1201
|
return this.glue.interop.unregister(methodName);
|
|
1122
1202
|
});
|
|
1123
1203
|
}
|
|
1124
|
-
invokeSystemMethod(argumentObj) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
return this.glue.interop.invoke(Glue42FDC3SystemMethod, args, { instance: target });
|
|
1204
|
+
invokeSystemMethod(argumentObj, target) {
|
|
1205
|
+
SystemMethodInvocationArgumentDecoder.runWithException(argumentObj);
|
|
1206
|
+
return this.glue.interop.invoke(ioConnectFDC3SystemMethod, argumentObj, { instance: target });
|
|
1128
1207
|
}
|
|
1129
1208
|
registerMethod(name, handler) {
|
|
1130
1209
|
return this.glue.interop.register(name, handler);
|
|
@@ -1132,22 +1211,17 @@
|
|
|
1132
1211
|
getInteropMethods(filter) {
|
|
1133
1212
|
return this.glue.interop.methods(filter);
|
|
1134
1213
|
}
|
|
1135
|
-
channelsSubscribe(callback) {
|
|
1214
|
+
channelsSubscribe(callback, contextType) {
|
|
1136
1215
|
const didReplay = { replayed: false };
|
|
1137
|
-
return this.glue.channels.subscribe((_,
|
|
1138
|
-
if (this.isUpdateFromMe(updaterId) || !
|
|
1139
|
-
return;
|
|
1140
|
-
}
|
|
1141
|
-
const contextData = yield this.glue.contexts.get(`${glueChannelNamePrefix}${context.name}`);
|
|
1142
|
-
if (!contextData.latest_fdc3_type) {
|
|
1216
|
+
return this.glue.channels.subscribe((_, contextData, updaterId) => __awaiter(this, void 0, void 0, function* () {
|
|
1217
|
+
if (this.isUpdateFromMe(updaterId) || !contextData || !contextData.latest_fdc3_type) {
|
|
1143
1218
|
return;
|
|
1144
1219
|
}
|
|
1145
|
-
if (
|
|
1146
|
-
this.
|
|
1147
|
-
didReplay.replayed = true;
|
|
1148
|
-
return;
|
|
1220
|
+
if (didReplay.replayed) {
|
|
1221
|
+
return this.parseDataAndInvokeSubscribeCallback({ callback, contextData, metadata: this.getContextMetadata(updaterId), contextType });
|
|
1149
1222
|
}
|
|
1150
|
-
this.
|
|
1223
|
+
this.invokePreviouslyBroadcastedData({ callback, contextData, metadata: this.getContextMetadata(updaterId), contextType });
|
|
1224
|
+
didReplay.replayed = true;
|
|
1151
1225
|
}));
|
|
1152
1226
|
}
|
|
1153
1227
|
contextsSubscribe(contextName, callback) {
|
|
@@ -1159,7 +1233,7 @@
|
|
|
1159
1233
|
if (!this.checkIfAppChannelShouldInvokeInitialReplay(didReplay, contextData)) {
|
|
1160
1234
|
return;
|
|
1161
1235
|
}
|
|
1162
|
-
this.parseDataAndInvokeSubscribeCallback(callback, contextData, this.getContextMetadata(extraData === null || extraData === void 0 ? void 0 : extraData.updaterId));
|
|
1236
|
+
this.parseDataAndInvokeSubscribeCallback({ callback, contextData, metadata: this.getContextMetadata(extraData === null || extraData === void 0 ? void 0 : extraData.updaterId) });
|
|
1163
1237
|
});
|
|
1164
1238
|
}
|
|
1165
1239
|
getInteropServers(methodFilter) {
|
|
@@ -1168,14 +1242,12 @@
|
|
|
1168
1242
|
initSubLogger(name) {
|
|
1169
1243
|
return this.logger.subLogger(name);
|
|
1170
1244
|
}
|
|
1171
|
-
invokePreviouslyBroadcastedData(callback, contextData, metadata) {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
callback(parsedData, metadata);
|
|
1178
|
-
});
|
|
1245
|
+
invokePreviouslyBroadcastedData({ callback, contextData, metadata, contextType }) {
|
|
1246
|
+
const invokeForType = contextType || this.channelsParser.mapChannelsDelimiterToFDC3Type(contextData.latest_fdc3_type);
|
|
1247
|
+
const dataForContextType = this.getLatestBroadcastedDataByContextType(contextData, invokeForType);
|
|
1248
|
+
if (dataForContextType) {
|
|
1249
|
+
callback(dataForContextType, metadata);
|
|
1250
|
+
}
|
|
1179
1251
|
}
|
|
1180
1252
|
isUpdateFromMe(updaterId) {
|
|
1181
1253
|
return this.glue.interop.instance.peerId === updaterId;
|
|
@@ -1195,9 +1267,34 @@
|
|
|
1195
1267
|
initializeLogger() {
|
|
1196
1268
|
this._logger = this.glue.logger;
|
|
1197
1269
|
}
|
|
1198
|
-
parseDataAndInvokeSubscribeCallback(callback,
|
|
1199
|
-
|
|
1200
|
-
|
|
1270
|
+
parseDataAndInvokeSubscribeCallback({ callback, contextData, metadata, contextType }) {
|
|
1271
|
+
if (!contextType) {
|
|
1272
|
+
const parsedData = this.channelsParser.parseContextsDataToInitialFDC3Data({ data: contextData.data, latest_fdc3_type: contextData.latest_fdc3_type });
|
|
1273
|
+
callback(parsedData, metadata);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
const latestPublishedType = this.channelsParser.mapChannelsDelimiterToFDC3Type(contextData.latest_fdc3_type);
|
|
1277
|
+
if (latestPublishedType !== contextType) {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
const dataForContextType = this.getLatestBroadcastedDataByContextType(contextData, contextType);
|
|
1281
|
+
if (dataForContextType) {
|
|
1282
|
+
callback(dataForContextType, metadata);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
getLatestBroadcastedDataByContextType(contextData, contextType) {
|
|
1286
|
+
let foundData;
|
|
1287
|
+
Object.entries(contextData.data).find(([key, value]) => {
|
|
1288
|
+
if (!this.channelsParser.isFdc3DataKey(key)) {
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
const parsedType = this.channelsParser.revertGlueParsedTypeToInitialFDC3Type(key);
|
|
1292
|
+
if (parsedType !== contextType) {
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
foundData = Object.assign({ type: parsedType }, value);
|
|
1296
|
+
});
|
|
1297
|
+
return foundData;
|
|
1201
1298
|
}
|
|
1202
1299
|
checkIfAppChannelShouldInvokeInitialReplay(didReplay, contextData) {
|
|
1203
1300
|
if (!didReplay.replayed) {
|
|
@@ -1209,6 +1306,11 @@
|
|
|
1209
1306
|
}
|
|
1210
1307
|
return true;
|
|
1211
1308
|
}
|
|
1309
|
+
contextsSetPaths(name, paths) {
|
|
1310
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1311
|
+
yield this.glue.contexts.setPaths(name, paths);
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1212
1314
|
}
|
|
1213
1315
|
|
|
1214
1316
|
const GLUE42_EVENT_NAME = "Glue42";
|
|
@@ -1244,6 +1346,7 @@
|
|
|
1244
1346
|
}
|
|
1245
1347
|
toApi() {
|
|
1246
1348
|
const api = {
|
|
1349
|
+
getStartupContext: this.getStartupContext.bind(this),
|
|
1247
1350
|
addContextListener: this.addContextListener.bind(this),
|
|
1248
1351
|
addIntentListener: this.addIntentListener.bind(this),
|
|
1249
1352
|
broadcast: this.broadcast.bind(this),
|
|
@@ -1356,6 +1459,11 @@
|
|
|
1356
1459
|
return this.intentsController.addIntentListener({ commandId: generateCommandId(), intent, handler });
|
|
1357
1460
|
});
|
|
1358
1461
|
}
|
|
1462
|
+
getStartupContext() {
|
|
1463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1464
|
+
return this.channelsController.getStartupContext();
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1359
1467
|
getOrCreateChannel(channelId) {
|
|
1360
1468
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1361
1469
|
nonEmptyStringDecoder.runWithException(channelId);
|
|
@@ -1461,7 +1569,7 @@
|
|
|
1461
1569
|
parseFDC3ContextToGlueContexts(context) {
|
|
1462
1570
|
const { type } = context, rest = __rest$1(context, ["type"]);
|
|
1463
1571
|
const parsedType = this.mapFDC3TypeToChannelsDelimiter(type);
|
|
1464
|
-
return {
|
|
1572
|
+
return { path: `${this.channelsFdc3DataPrefix}${parsedType}`, value: rest };
|
|
1465
1573
|
}
|
|
1466
1574
|
mapFDC3TypeToChannelsDelimiter(type) {
|
|
1467
1575
|
return type.split(".").join(this.fdc3Delimiter);
|
|
@@ -1478,76 +1586,60 @@
|
|
|
1478
1586
|
* SPDX-License-Identifier: Apache-2.0
|
|
1479
1587
|
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
1480
1588
|
*/
|
|
1481
|
-
|
|
1482
1589
|
/** Constants representing the errors that can be encountered when calling the `open` method on the DesktopAgent object (`fdc3`). */
|
|
1483
1590
|
var OpenError;
|
|
1484
|
-
|
|
1485
1591
|
(function (OpenError) {
|
|
1486
1592
|
/** Returned if the specified application is not found.*/
|
|
1487
1593
|
OpenError["AppNotFound"] = "AppNotFound";
|
|
1488
1594
|
/** Returned if the specified application fails to launch correctly.*/
|
|
1489
|
-
|
|
1490
1595
|
OpenError["ErrorOnLaunch"] = "ErrorOnLaunch";
|
|
1491
1596
|
/** Returned if the specified application launches but fails to add a context listener in order to receive the context passed to the `fdc3.open` call.*/
|
|
1492
|
-
|
|
1493
1597
|
OpenError["AppTimeout"] = "AppTimeout";
|
|
1494
1598
|
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1495
|
-
|
|
1496
1599
|
OpenError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1600
|
+
/** Returned if a call to the `open` function is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1601
|
+
OpenError["MalformedContext"] = "MalformedContext";
|
|
1497
1602
|
})(OpenError || (OpenError = {}));
|
|
1498
1603
|
/** Constants representing the errors that can be encountered when calling the `findIntent`, `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the DesktopAgent (`fdc3`). */
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
1604
|
var ResolveError;
|
|
1502
|
-
|
|
1503
1605
|
(function (ResolveError) {
|
|
1504
1606
|
/** SHOULD be returned if no apps are available that can resolve the intent and context combination.*/
|
|
1505
1607
|
ResolveError["NoAppsFound"] = "NoAppsFound";
|
|
1506
1608
|
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1507
|
-
|
|
1508
1609
|
ResolveError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1509
1610
|
/** Returned if the user cancelled the resolution request, for example by closing or cancelling a resolver UI.*/
|
|
1510
|
-
|
|
1511
1611
|
ResolveError["UserCancelled"] = "UserCancelledResolution";
|
|
1512
1612
|
/** SHOULD be returned if a timeout cancels an intent resolution that required user interaction. Please use `ResolverUnavailable` instead for situations where a resolver UI or similar fails.*/
|
|
1513
|
-
|
|
1514
1613
|
ResolveError["ResolverTimeout"] = "ResolverTimeout";
|
|
1515
1614
|
/** Returned if a specified target application is not available or a new instance of it cannot be opened. */
|
|
1516
|
-
|
|
1517
1615
|
ResolveError["TargetAppUnavailable"] = "TargetAppUnavailable";
|
|
1518
1616
|
/** Returned if a specified target application instance is not available, for example because it has been closed. */
|
|
1519
|
-
|
|
1520
1617
|
ResolveError["TargetInstanceUnavailable"] = "TargetInstanceUnavailable";
|
|
1521
1618
|
/** Returned if the intent and context could not be delivered to the selected application or instance, for example because it has not added an intent handler within a timeout.*/
|
|
1522
|
-
|
|
1523
1619
|
ResolveError["IntentDeliveryFailed"] = "IntentDeliveryFailed";
|
|
1620
|
+
/** Returned if a call to one of the `raiseIntent` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1621
|
+
ResolveError["MalformedContext"] = "MalformedContext";
|
|
1524
1622
|
})(ResolveError || (ResolveError = {}));
|
|
1525
|
-
|
|
1526
1623
|
var ResultError;
|
|
1527
|
-
|
|
1528
1624
|
(function (ResultError) {
|
|
1529
|
-
/** Returned if the intent handler exited without returning a
|
|
1625
|
+
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
|
|
1530
1626
|
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
1531
1627
|
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
|
|
1532
|
-
|
|
1533
1628
|
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
1534
1629
|
})(ResultError || (ResultError = {}));
|
|
1535
|
-
|
|
1536
1630
|
var ChannelError;
|
|
1537
|
-
|
|
1538
1631
|
(function (ChannelError) {
|
|
1539
1632
|
/** Returned if the specified channel is not found when attempting to join a channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).*/
|
|
1540
1633
|
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
1541
1634
|
/** SHOULD be returned when a request to join a user channel or to a retrieve a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods of the DesktopAgent (`fdc3`) object is denied. */
|
|
1542
|
-
|
|
1543
1635
|
ChannelError["AccessDenied"] = "AccessDenied";
|
|
1544
1636
|
/** SHOULD be returned when a channel cannot be created or retrieved via the `getOrCreateChannel` method of the DesktopAgent (`fdc3`).*/
|
|
1545
|
-
|
|
1546
1637
|
ChannelError["CreationFailed"] = "CreationFailed";
|
|
1638
|
+
/** Returned if a call to the `broadcast` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1639
|
+
ChannelError["MalformedContext"] = "MalformedContext";
|
|
1547
1640
|
})(ChannelError || (ChannelError = {}));
|
|
1548
1641
|
|
|
1549
1642
|
var ContextTypes;
|
|
1550
|
-
|
|
1551
1643
|
(function (ContextTypes) {
|
|
1552
1644
|
ContextTypes["Chart"] = "fdc3.chart";
|
|
1553
1645
|
ContextTypes["ChatInitSettings"] = "fdc3.chat.initSettings";
|
|
@@ -1568,13 +1660,13 @@
|
|
|
1568
1660
|
|
|
1569
1661
|
// To parse this data:
|
|
1570
1662
|
//
|
|
1571
|
-
// import { Convert,
|
|
1663
|
+
// import { Convert, Chart, ChatInitSettings, Contact, ContactList, Context, Country, Currency, Email, Instrument, InstrumentList, Nothing, Organization, Portfolio, Position, TimeRange, Valuation } from "./file";
|
|
1572
1664
|
//
|
|
1573
|
-
// const context = Convert.toContext(json);
|
|
1574
1665
|
// const chart = Convert.toChart(json);
|
|
1575
1666
|
// const chatInitSettings = Convert.toChatInitSettings(json);
|
|
1576
1667
|
// const contact = Convert.toContact(json);
|
|
1577
1668
|
// const contactList = Convert.toContactList(json);
|
|
1669
|
+
// const context = Convert.toContext(json);
|
|
1578
1670
|
// const country = Convert.toCountry(json);
|
|
1579
1671
|
// const currency = Convert.toCurrency(json);
|
|
1580
1672
|
// const email = Convert.toEmail(json);
|
|
@@ -1590,7 +1682,6 @@
|
|
|
1590
1682
|
// These functions will throw an error if the JSON doesn't
|
|
1591
1683
|
// match the expected interface, even if the JSON is valid.
|
|
1592
1684
|
var Style;
|
|
1593
|
-
|
|
1594
1685
|
(function (Style) {
|
|
1595
1686
|
Style["Bar"] = "bar";
|
|
1596
1687
|
Style["Candle"] = "candle";
|
|
@@ -1602,10 +1693,9 @@
|
|
|
1602
1693
|
Style["Pie"] = "pie";
|
|
1603
1694
|
Style["Scatter"] = "scatter";
|
|
1604
1695
|
Style["StackedBar"] = "stacked-bar";
|
|
1605
|
-
})(Style || (Style = {}));
|
|
1696
|
+
})(Style || (Style = {}));
|
|
1606
1697
|
|
|
1607
1698
|
var Intents;
|
|
1608
|
-
|
|
1609
1699
|
(function (Intents) {
|
|
1610
1700
|
Intents["StartCall"] = "StartCall";
|
|
1611
1701
|
Intents["StartChat"] = "StartChat";
|
|
@@ -1681,15 +1771,11 @@
|
|
|
1681
1771
|
const isContext = (data) => {
|
|
1682
1772
|
return defaultContextProps.every(prop => Object.keys(data).includes(prop));
|
|
1683
1773
|
};
|
|
1684
|
-
const isChannelMetadata = (data) => {
|
|
1685
|
-
return typeof data === "object" && data.isChannel;
|
|
1686
|
-
};
|
|
1687
1774
|
const extractChannelMetadata = (channel) => {
|
|
1688
1775
|
return {
|
|
1689
1776
|
id: channel.id,
|
|
1690
1777
|
type: channel.type,
|
|
1691
|
-
displayMetadata: channel.displayMetadata
|
|
1692
|
-
isChannel: true
|
|
1778
|
+
displayMetadata: channel.displayMetadata
|
|
1693
1779
|
};
|
|
1694
1780
|
};
|
|
1695
1781
|
const parseContextHandler = (handler, contextType) => {
|
|
@@ -1706,10 +1792,11 @@
|
|
|
1706
1792
|
};
|
|
1707
1793
|
|
|
1708
1794
|
class IntentsController {
|
|
1709
|
-
constructor(glueController, channelsController, channelsFactory) {
|
|
1795
|
+
constructor(glueController, channelsController, channelsFactory, glueEventsController) {
|
|
1710
1796
|
this.glueController = glueController;
|
|
1711
1797
|
this.channelsController = channelsController;
|
|
1712
1798
|
this.channelsFactory = channelsFactory;
|
|
1799
|
+
this.glueEventsController = glueEventsController;
|
|
1713
1800
|
}
|
|
1714
1801
|
get logger() {
|
|
1715
1802
|
if (!this._logger) {
|
|
@@ -1801,11 +1888,33 @@
|
|
|
1801
1888
|
});
|
|
1802
1889
|
}
|
|
1803
1890
|
addIntentListener({ commandId, intent, handler }) {
|
|
1891
|
+
var _a, _b;
|
|
1804
1892
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1805
1893
|
yield this.glueController.gluePromise;
|
|
1806
1894
|
this.logger.info(`[${commandId}] - addIntentListener() invoked for intent ${intent}`);
|
|
1807
1895
|
const wrappedHandler = this.getWrappedIntentHandler(handler);
|
|
1808
|
-
|
|
1896
|
+
const myInstance = this.glueController.getMyInteropInstance();
|
|
1897
|
+
const myApplication = this.glueController.getApplication(myInstance.applicationName);
|
|
1898
|
+
let appConfigIntentDef;
|
|
1899
|
+
const globalBrowserNamespace = window.glue42core || window.iobrowser;
|
|
1900
|
+
const globalDesktopNamespace = window.glue42gd || window.iodesktop;
|
|
1901
|
+
if (globalBrowserNamespace) {
|
|
1902
|
+
appConfigIntentDef = (_a = myApplication === null || myApplication === void 0 ? void 0 : myApplication.userProperties.intents) === null || _a === void 0 ? void 0 : _a.find((appIntent) => appIntent.name === intent);
|
|
1903
|
+
}
|
|
1904
|
+
if (globalDesktopNamespace) {
|
|
1905
|
+
const appConfig = yield myApplication.getConfiguration();
|
|
1906
|
+
appConfigIntentDef = (_b = appConfig === null || appConfig === void 0 ? void 0 : appConfig.intents) === null || _b === void 0 ? void 0 : _b.find((appIntent) => appIntent.name === intent);
|
|
1907
|
+
}
|
|
1908
|
+
const intentRequest = {
|
|
1909
|
+
intent,
|
|
1910
|
+
displayName: appConfigIntentDef === null || appConfigIntentDef === void 0 ? void 0 : appConfigIntentDef.displayName,
|
|
1911
|
+
description: appConfigIntentDef === null || appConfigIntentDef === void 0 ? void 0 : appConfigIntentDef.description,
|
|
1912
|
+
contextTypes: (appConfigIntentDef === null || appConfigIntentDef === void 0 ? void 0 : appConfigIntentDef.contexts) || Fdc3SupportedIntentTypes[intent],
|
|
1913
|
+
resultType: appConfigIntentDef === null || appConfigIntentDef === void 0 ? void 0 : appConfigIntentDef.resultType
|
|
1914
|
+
};
|
|
1915
|
+
Object.keys(intentRequest)
|
|
1916
|
+
.forEach((key) => intentRequest[key] === undefined && delete intentRequest[key]);
|
|
1917
|
+
return this.glueController.addIntentListener(intentRequest, wrappedHandler);
|
|
1809
1918
|
});
|
|
1810
1919
|
}
|
|
1811
1920
|
filterGlueIntentHandlers({ commandId, intent, context, target }) {
|
|
@@ -1825,7 +1934,7 @@
|
|
|
1825
1934
|
this.logger.info(`[${commandId}] - Checking if application with name ${appName} exists`);
|
|
1826
1935
|
const app = this.glueController.getApplication(appName);
|
|
1827
1936
|
const serverInstances = this.serverInstanceAsIntentHandler(intent.name);
|
|
1828
|
-
if (!app && (typeof target === "string" || !serverInstances.length)) {
|
|
1937
|
+
if (!app && (typeof target === "string" || !target.instanceId || !serverInstances.length)) {
|
|
1829
1938
|
throw { message: ResolveError.TargetAppUnavailable, reason: `There's no app with appId ${appName}` };
|
|
1830
1939
|
}
|
|
1831
1940
|
this.logger.info(`[${commandId}] - target app ${appName} found. Filtering handlers by applicationName: ${appName}`);
|
|
@@ -1871,23 +1980,33 @@
|
|
|
1871
1980
|
if (!isValidNonEmptyObject(result)) {
|
|
1872
1981
|
return;
|
|
1873
1982
|
}
|
|
1874
|
-
|
|
1875
|
-
if (!isResultChannelMetadata) {
|
|
1983
|
+
if (!result.fdc3intentChannel && !result.fdc3intentContext) {
|
|
1876
1984
|
return result;
|
|
1877
1985
|
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
}
|
|
1986
|
+
if (result.fdc3intentContext) {
|
|
1987
|
+
return result.fdc3intentContext;
|
|
1988
|
+
}
|
|
1989
|
+
const { fdc3intentChannel } = result;
|
|
1990
|
+
if (fdc3intentChannel.type === "user") {
|
|
1991
|
+
const glueChannel = (yield this.glueController.listAllChannels()).find(ch => ch.name === fdc3intentChannel.displayMetadata.name);
|
|
1992
|
+
return this.channelsFactory.buildModel(Object.assign(Object.assign({}, fdc3intentChannel), { displayMetadata: Object.assign(Object.assign({}, fdc3intentChannel.displayMetadata), { glueChannel }) }));
|
|
1993
|
+
}
|
|
1994
|
+
if (fdc3intentChannel.type !== "private") {
|
|
1995
|
+
return this.channelsFactory.buildModel(fdc3intentChannel);
|
|
1996
|
+
}
|
|
1997
|
+
yield this.glueEventsController.initializeCollaborateMethod();
|
|
1998
|
+
const channel = this.channelsController.buildPrivateChannel(fdc3intentChannel.id, commandId, false);
|
|
1999
|
+
channel.setCollaborator({ appId: glueIntentResult.handler.applicationName, instanceId: glueIntentResult.handler.instanceId }, commandId);
|
|
2000
|
+
const joinChannelArgs = {
|
|
2001
|
+
action: "joinPrivateChannel",
|
|
2002
|
+
correlationId: channel.id,
|
|
2003
|
+
collaborationObject: {
|
|
2004
|
+
channelId: channel.id
|
|
2005
|
+
}
|
|
2006
|
+
};
|
|
2007
|
+
yield this.glueController.invokeSystemMethod(joinChannelArgs, glueIntentResult.handler.instanceId);
|
|
1889
2008
|
this.logger.info(`[${commandId}] - returning private channel`);
|
|
1890
|
-
return channel;
|
|
2009
|
+
return channel.toApi();
|
|
1891
2010
|
});
|
|
1892
2011
|
}
|
|
1893
2012
|
convertGlue42IntentToFDC3Intent(glueIntent) {
|
|
@@ -1922,15 +2041,23 @@
|
|
|
1922
2041
|
throw new Error("Async handler function should return a promise that resolves to a Context or Channel");
|
|
1923
2042
|
}
|
|
1924
2043
|
getWrappedIntentHandler(handler) {
|
|
1925
|
-
const wrappedHandler = (glue42Context) => __awaiter(this, void 0, void 0, function* () {
|
|
1926
|
-
const
|
|
2044
|
+
const wrappedHandler = (glue42Context, caller) => __awaiter(this, void 0, void 0, function* () {
|
|
2045
|
+
const contextMetadata = caller
|
|
2046
|
+
? {
|
|
2047
|
+
source: {
|
|
2048
|
+
appId: caller.application || caller.applicationName || "",
|
|
2049
|
+
instanceId: caller.instance
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
: undefined;
|
|
2053
|
+
const handlerResult = yield handler(Object.assign(Object.assign({}, glue42Context.data), { type: glue42Context.type || "" }), contextMetadata);
|
|
1927
2054
|
if (!handlerResult) {
|
|
1928
2055
|
return;
|
|
1929
2056
|
}
|
|
1930
2057
|
const handlerResultType = this.getResultType(handlerResult);
|
|
1931
2058
|
return handlerResultType === IntentHandlerResultTypes.Channel
|
|
1932
|
-
? extractChannelMetadata(handlerResult)
|
|
1933
|
-
: handlerResult;
|
|
2059
|
+
? { fdc3intentChannel: extractChannelMetadata(handlerResult) }
|
|
2060
|
+
: { fdc3intentContext: handlerResult };
|
|
1934
2061
|
});
|
|
1935
2062
|
return wrappedHandler;
|
|
1936
2063
|
}
|
|
@@ -1977,13 +2104,14 @@
|
|
|
1977
2104
|
}
|
|
1978
2105
|
}
|
|
1979
2106
|
|
|
1980
|
-
var version = "2.1.
|
|
2107
|
+
var version = "2.1.2";
|
|
1981
2108
|
|
|
1982
2109
|
class ApplicationsController {
|
|
1983
|
-
constructor(glueController) {
|
|
2110
|
+
constructor(glueController, appsStateStore, glueEventsController) {
|
|
1984
2111
|
this.glueController = glueController;
|
|
1985
|
-
this.
|
|
1986
|
-
this.
|
|
2112
|
+
this.appsStateStore = appsStateStore;
|
|
2113
|
+
this.glueEventsController = glueEventsController;
|
|
2114
|
+
this.defaultContextListenerInvokedPromiseTimeout = 120 * 1000;
|
|
1987
2115
|
}
|
|
1988
2116
|
get logger() {
|
|
1989
2117
|
if (!this._logger) {
|
|
@@ -2001,6 +2129,7 @@
|
|
|
2001
2129
|
throw { message: OpenError.AppNotFound, reason: `Cannot find targeted ${name} application` };
|
|
2002
2130
|
}
|
|
2003
2131
|
if (context) {
|
|
2132
|
+
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2004
2133
|
this.logger.info(`[${commandId}] - opening app ${app} with startup context`);
|
|
2005
2134
|
return this.openAppWithContext(app, context);
|
|
2006
2135
|
}
|
|
@@ -2055,7 +2184,7 @@
|
|
|
2055
2184
|
this.logger.info(`${commandId} - getInfo() invoked`);
|
|
2056
2185
|
const appMetadata = yield this.getCurrentAppMetadata();
|
|
2057
2186
|
return {
|
|
2058
|
-
provider: "
|
|
2187
|
+
provider: "io.Connect",
|
|
2059
2188
|
providerVersion: version,
|
|
2060
2189
|
fdc3Version: "2.0",
|
|
2061
2190
|
optionalFeatures: {
|
|
@@ -2116,41 +2245,39 @@
|
|
|
2116
2245
|
}
|
|
2117
2246
|
openAppWithContext(app, context) {
|
|
2118
2247
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2119
|
-
const
|
|
2120
|
-
const startContext = this.
|
|
2121
|
-
const
|
|
2122
|
-
this.
|
|
2248
|
+
const guid = nanoid();
|
|
2249
|
+
const startContext = this.buildStartContext(context, guid);
|
|
2250
|
+
const wrappedPromise = this.createContextListenerWrappedPromise(app);
|
|
2251
|
+
this.appsStateStore.addOpenAppPromise(guid, wrappedPromise);
|
|
2123
2252
|
try {
|
|
2124
|
-
yield
|
|
2125
|
-
yield
|
|
2253
|
+
const glueInst = yield app.start(startContext);
|
|
2254
|
+
yield wrappedPromise.promise;
|
|
2255
|
+
this.appsStateStore.removeOpenAppPromise(guid);
|
|
2126
2256
|
return this.parseGlueInstToAppIdentifier(glueInst);
|
|
2127
2257
|
}
|
|
2128
2258
|
catch (error) {
|
|
2129
|
-
|
|
2259
|
+
this.appsStateStore.removeOpenAppPromise(guid);
|
|
2130
2260
|
throw { message: OpenError.AppTimeout, reason: typeof error === "string" ? error : JSON.stringify(error) };
|
|
2131
2261
|
}
|
|
2132
2262
|
});
|
|
2133
2263
|
}
|
|
2134
|
-
|
|
2264
|
+
buildStartContext(fdc3Context, guid) {
|
|
2265
|
+
const myInteropInstance = this.glueController.getMyInteropInstance();
|
|
2135
2266
|
return {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2267
|
+
fdc3: {
|
|
2268
|
+
collaborationId: guid,
|
|
2269
|
+
openApp: {
|
|
2270
|
+
appId: myInteropInstance.application || myInteropInstance.applicationName || "",
|
|
2271
|
+
instanceId: myInteropInstance.instance
|
|
2272
|
+
},
|
|
2273
|
+
context: {
|
|
2274
|
+
contextType: fdc3Context.type,
|
|
2275
|
+
payload: fdc3Context
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2141
2278
|
};
|
|
2142
2279
|
}
|
|
2143
|
-
|
|
2144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2145
|
-
const methodName = this.buildInteropMethodName();
|
|
2146
|
-
yield this.glueController.registerMethod(methodName, this.contextListenerResponseHandler.bind(this));
|
|
2147
|
-
return methodName;
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
|
-
buildInteropMethodName() {
|
|
2151
|
-
return `${responseInteropMethodPrefix}.${nanoid()}`;
|
|
2152
|
-
}
|
|
2153
|
-
createContextListenerResponsePromise(instance, methodName) {
|
|
2280
|
+
createContextListenerWrappedPromise(app) {
|
|
2154
2281
|
let resolve = () => { };
|
|
2155
2282
|
let reject = () => { };
|
|
2156
2283
|
const promise = promisePlus(() => {
|
|
@@ -2158,50 +2285,32 @@
|
|
|
2158
2285
|
resolve = res;
|
|
2159
2286
|
reject = rej;
|
|
2160
2287
|
});
|
|
2161
|
-
}, this.defaultContextListenerInvokedPromiseTimeout, `Timeout of ${this.defaultContextListenerInvokedPromiseTimeout}ms hit waiting for application with appId: ${
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2164
|
-
contextListenerResponseHandler(args, callerId) {
|
|
2165
|
-
const result = ContextListenerResponseDecoder.run(args);
|
|
2166
|
-
if (!result.ok) {
|
|
2167
|
-
const contextListenerPromise = this.contextListenerInvokedPromises[callerId.instance];
|
|
2168
|
-
if (!contextListenerPromise) {
|
|
2169
|
-
return;
|
|
2170
|
-
}
|
|
2171
|
-
contextListenerPromise.reject(`Method invoked with invalid argument - ${result.error.message}`);
|
|
2172
|
-
return;
|
|
2173
|
-
}
|
|
2174
|
-
const contextListenerPromise = this.contextListenerInvokedPromises[callerId.instance];
|
|
2175
|
-
if (!contextListenerPromise) {
|
|
2176
|
-
return;
|
|
2177
|
-
}
|
|
2178
|
-
contextListenerPromise.resolve();
|
|
2179
|
-
}
|
|
2180
|
-
unregisterContextListenerPromise(instanceId) {
|
|
2181
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2182
|
-
const { methodName } = this.contextListenerInvokedPromises[instanceId];
|
|
2183
|
-
yield this.glueController.unregisterMethod(methodName);
|
|
2184
|
-
delete this.contextListenerInvokedPromises[instanceId];
|
|
2185
|
-
});
|
|
2288
|
+
}, this.defaultContextListenerInvokedPromiseTimeout, `Timeout of ${this.defaultContextListenerInvokedPromiseTimeout}ms hit waiting for application with appId: ${app.name} to register context listener`);
|
|
2289
|
+
return { promise, resolve, reject };
|
|
2186
2290
|
}
|
|
2187
2291
|
}
|
|
2188
2292
|
|
|
2189
2293
|
class ChannelsController {
|
|
2190
|
-
constructor(glueController, channelsStateStore, channelsParser, channelsFactory,
|
|
2294
|
+
constructor(glueController, channelsStateStore, channelsParser, channelsFactory, glueEventsController) {
|
|
2191
2295
|
this.glueController = glueController;
|
|
2192
2296
|
this.channelsStateStore = channelsStateStore;
|
|
2193
2297
|
this.channelsParser = channelsParser;
|
|
2194
2298
|
this.channelsFactory = channelsFactory;
|
|
2195
|
-
this.
|
|
2299
|
+
this.glueEventsController = glueEventsController;
|
|
2196
2300
|
this.invokeContextHandlerWithStartupContext = true;
|
|
2197
2301
|
this.initDonePromise = this.initialize();
|
|
2198
|
-
this.initDonePromise.catch(() => {
|
|
2302
|
+
this.initDonePromise.catch((err) => {
|
|
2303
|
+
var _a;
|
|
2304
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(err);
|
|
2305
|
+
});
|
|
2199
2306
|
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2307
|
+
getStartupContext() {
|
|
2308
|
+
var _a, _b;
|
|
2309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2310
|
+
yield this.initDonePromise;
|
|
2311
|
+
const fdc3StartupContext = yield this.glueController.getMyWindowContext();
|
|
2312
|
+
return ((_b = (_a = fdc3StartupContext === null || fdc3StartupContext === void 0 ? void 0 : fdc3StartupContext.fdc3) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.payload) || null;
|
|
2313
|
+
});
|
|
2205
2314
|
}
|
|
2206
2315
|
addContextListener({ commandId, handler, contextType, channelId }) {
|
|
2207
2316
|
var _a;
|
|
@@ -2239,14 +2348,14 @@
|
|
|
2239
2348
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2240
2349
|
yield this.initDonePromise;
|
|
2241
2350
|
this.logger.info(`[${commandId}] - getOrCreateChannel() invoked for channel with id ${channelId}`);
|
|
2242
|
-
const isPrivateChannel = this.isPrivateChannel(channelId);
|
|
2243
|
-
if (isPrivateChannel) {
|
|
2244
|
-
throw { message: ChannelError.AccessDenied, reason: "Cannot retrieve a private channel" };
|
|
2245
|
-
}
|
|
2246
2351
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2247
2352
|
if (isUserChannel) {
|
|
2248
2353
|
throw { message: ChannelError.AccessDenied, reason: "There's an already existing system channel with passed id. Retrieve it using fdc3.getSystemChannels() or create a new app channel with a different id" };
|
|
2249
2354
|
}
|
|
2355
|
+
const isPrivateChannel = this.channelsStateStore.getPrivateChannelById(channelId);
|
|
2356
|
+
if (isPrivateChannel) {
|
|
2357
|
+
throw { message: ChannelError.AccessDenied, reason: "Cannot retrieve a private channel" };
|
|
2358
|
+
}
|
|
2250
2359
|
return this.getOrCreateAppChannel(commandId, channelId);
|
|
2251
2360
|
});
|
|
2252
2361
|
}
|
|
@@ -2324,26 +2433,28 @@
|
|
|
2324
2433
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2325
2434
|
yield this.initDonePromise;
|
|
2326
2435
|
this.logger.info(`[${commandId}] - createPrivateChannel() invoked`);
|
|
2327
|
-
const
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
return channel;
|
|
2436
|
+
const channelId = `${PrivateChannelPrefix}${nanoid()}`;
|
|
2437
|
+
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2438
|
+
const pc = this.buildPrivateChannel(channelId, commandId, true);
|
|
2439
|
+
return pc.toApi();
|
|
2332
2440
|
});
|
|
2333
2441
|
}
|
|
2334
|
-
|
|
2442
|
+
removePrivateChannelFromStoreById(id) {
|
|
2335
2443
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2336
|
-
|
|
2337
|
-
this.logger.info(`[${commandId}] - disconnect() invoked on channel with id ${channelId}`);
|
|
2338
|
-
yield this.glueController.updateContext(channelId, { disconnected: true });
|
|
2339
|
-
this.logger.info(`[${commandId}] - glue context for ${channelId} updated with disconnected flag`);
|
|
2340
|
-
const closedInstanceId = instanceId || this.glueController.getMyInteropInstanceId();
|
|
2341
|
-
const targetInstance = yield this.getOtherInstanceIdFromClosedOne(channelId, closedInstanceId);
|
|
2342
|
-
const replayContextTypes = yield this.getContextTypesForPrivateChannel(channelId);
|
|
2343
|
-
this.logger.info(`[${commandId}] - invoking onDisconnect callback for instance ${targetInstance}`);
|
|
2344
|
-
this.invokeSystemMethod(targetInstance, PrivateChannelEventMethods.OnDisconnect, { clientId: targetInstance, channelId, replayContextTypes });
|
|
2444
|
+
this.channelsStateStore.removePrivateChannelById(id);
|
|
2345
2445
|
});
|
|
2346
2446
|
}
|
|
2447
|
+
invokeSystemMethod(args, target) {
|
|
2448
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2449
|
+
if (!target) {
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
return this.glueController.invokeSystemMethod(args, target);
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
getMyServerInstance() {
|
|
2456
|
+
return this.glueController.getMyInteropInstance();
|
|
2457
|
+
}
|
|
2347
2458
|
addClientToPrivateChannel(commandId, channelId, clientId) {
|
|
2348
2459
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2349
2460
|
this.logger.info(`[${commandId}] - client with id ${clientId} added to private channel with id ${channelId}`);
|
|
@@ -2357,28 +2468,22 @@
|
|
|
2357
2468
|
return !!context.disconnected;
|
|
2358
2469
|
});
|
|
2359
2470
|
}
|
|
2360
|
-
|
|
2361
|
-
this.logger.info(`[${commandId}] -
|
|
2362
|
-
const handler = (instance) => __awaiter(this, void 0, void 0, function* () {
|
|
2363
|
-
const { clientId, creatorId } = yield this.glueController.getContext(channelId);
|
|
2364
|
-
if (instance.id !== clientId && instance.id !== creatorId) {
|
|
2365
|
-
return;
|
|
2366
|
-
}
|
|
2367
|
-
this.logger.info(`[${commandId}] - calling onDisconnect callback for channel with id ${channelId}`);
|
|
2368
|
-
yield this.announceDisconnect(commandId, channelId, instance.id);
|
|
2369
|
-
});
|
|
2471
|
+
subscribeOnInstanceStop(channelId, handler, commandId) {
|
|
2472
|
+
this.logger.info(`[${commandId}] - subscribing onInstanceStopped callback for channel with id ${channelId}`);
|
|
2370
2473
|
return this.glueController.registerOnInstanceStopped(handler.bind(this));
|
|
2371
2474
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2475
|
+
buildPrivateChannel(channelId, commandId, isCreator) {
|
|
2476
|
+
const logger = this.glueController.initSubLogger(channelId);
|
|
2477
|
+
const channel = this.buildChannel(ChannelTypes.Private, { id: channelId, logger, isCreator });
|
|
2478
|
+
this.logger.info(`[${commandId}] - private channel with id ${channelId} created. Adding it to the store`);
|
|
2479
|
+
this.channelsStateStore.addPrivateChannel(channel);
|
|
2480
|
+
return channel;
|
|
2481
|
+
}
|
|
2482
|
+
get logger() {
|
|
2483
|
+
if (!this._logger) {
|
|
2484
|
+
this._logger = this.glueController.initSubLogger("fdc3.channels.controller");
|
|
2485
|
+
}
|
|
2486
|
+
return this._logger;
|
|
2382
2487
|
}
|
|
2383
2488
|
initialize() {
|
|
2384
2489
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2427,39 +2532,43 @@
|
|
|
2427
2532
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2428
2533
|
const myWindow = this.glueController.getMyWindow();
|
|
2429
2534
|
if (!myWindow) {
|
|
2430
|
-
this.logger.
|
|
2535
|
+
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
2431
2536
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2432
2537
|
return;
|
|
2433
2538
|
}
|
|
2434
2539
|
const windowContext = yield myWindow.getContext();
|
|
2435
|
-
if (!
|
|
2436
|
-
this.logger.
|
|
2540
|
+
if (!windowContext) {
|
|
2541
|
+
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
2437
2542
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2438
2543
|
return;
|
|
2439
2544
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked`);
|
|
2545
|
+
if (!isValidNonEmptyObject(windowContext) || !windowContext.fdc3) {
|
|
2546
|
+
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked - startup context is empty`);
|
|
2547
|
+
this.invokeContextHandlerWithStartupContext = false;
|
|
2444
2548
|
return;
|
|
2445
2549
|
}
|
|
2446
|
-
this.
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
const
|
|
2451
|
-
if (!
|
|
2452
|
-
this.logger.info(`[${commandId}] -
|
|
2550
|
+
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2551
|
+
FDC3StartupContextDecoder.runWithException(windowContext);
|
|
2552
|
+
const { fdc3 } = windowContext;
|
|
2553
|
+
this.logger.trace(`[${commandId}] - received FDC3 startup context from ${JSON.stringify(fdc3.openApp)} for contextType ${fdc3.context.contextType}`);
|
|
2554
|
+
const isSameContextType = contextType ? fdc3.context.contextType === contextType : true;
|
|
2555
|
+
if (!isSameContextType) {
|
|
2556
|
+
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked for contextType ${contextType} for startup context with type: ${fdc3.context.contextType}`);
|
|
2453
2557
|
return;
|
|
2454
2558
|
}
|
|
2455
|
-
this.logger.info(`[${commandId}] - invoking
|
|
2456
|
-
|
|
2559
|
+
this.logger.info(`[${commandId}] - invoking addContextListener handler with startup context with type ${fdc3.context.contextType}`);
|
|
2560
|
+
try {
|
|
2561
|
+
handler(fdc3.context.payload, { source: fdc3.openApp });
|
|
2562
|
+
}
|
|
2563
|
+
catch (error) {
|
|
2564
|
+
this.logger.error(typeof error === "string" ? error : error.message ? JSON.stringify(error.message) : JSON.stringify(error));
|
|
2565
|
+
}
|
|
2566
|
+
this.invokeContextHandlerWithStartupContext = false;
|
|
2567
|
+
this.logger.trace(`[${commandId}] - invoking response method to with target ${JSON.stringify(fdc3.openApp)}`);
|
|
2568
|
+
yield this.invokeSystemMethod({ action: "startupContextOpened", correlationId: fdc3.collaborationId }, fdc3.openApp.instanceId);
|
|
2569
|
+
this.logger.trace(`[${commandId}] - system method invocation success for 'startupContextOpened' heard`);
|
|
2457
2570
|
});
|
|
2458
2571
|
}
|
|
2459
|
-
doesServerMethodExist(methodName, instance) {
|
|
2460
|
-
const serversForMethodName = this.glueController.getInteropServers({ name: methodName });
|
|
2461
|
-
return !!serversForMethodName.find(server => server.instance === instance);
|
|
2462
|
-
}
|
|
2463
2572
|
getOrCreateAppChannel(commandId, channelId) {
|
|
2464
2573
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2465
2574
|
const exists = this.doesAppChannelExist(channelId);
|
|
@@ -2468,7 +2577,8 @@
|
|
|
2468
2577
|
yield this.glueController.updateContext(channelId, {});
|
|
2469
2578
|
}
|
|
2470
2579
|
this.logger.info(`[${commandId}] - returning app channel with id ${channelId}`);
|
|
2471
|
-
|
|
2580
|
+
const logger = this.glueController.initSubLogger(`app.channel.${channelId}`);
|
|
2581
|
+
return this.buildChannel(ChannelTypes.App, { id: channelId, logger });
|
|
2472
2582
|
});
|
|
2473
2583
|
}
|
|
2474
2584
|
doesAppChannelExist(name) {
|
|
@@ -2480,12 +2590,6 @@
|
|
|
2480
2590
|
}
|
|
2481
2591
|
return !!this.channelsStateStore.userChannels[channelId];
|
|
2482
2592
|
}
|
|
2483
|
-
isPrivateChannel(channelId) {
|
|
2484
|
-
return channelId.includes(PrivateChannelPrefix) && this.glueController.getAllContexts().some((ctxName) => ctxName === channelId);
|
|
2485
|
-
}
|
|
2486
|
-
buildChannel(type, data) {
|
|
2487
|
-
return this.channelsFactory.buildModel(Object.assign(Object.assign({ type }, data), { isChannel: true }));
|
|
2488
|
-
}
|
|
2489
2593
|
broadcastByChannelId(commandId, channelId, context) {
|
|
2490
2594
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2491
2595
|
const isUserChannel = this.isUserChannel(channelId);
|
|
@@ -2503,7 +2607,7 @@
|
|
|
2503
2607
|
const subHandler = parseContextHandler(handler, contextType);
|
|
2504
2608
|
if (!channelId) {
|
|
2505
2609
|
this.logger.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
|
|
2506
|
-
const unsubscribe = this.glueController.channelsSubscribe(subHandler);
|
|
2610
|
+
const unsubscribe = this.glueController.channelsSubscribe(subHandler, contextType);
|
|
2507
2611
|
return { unsubscribe };
|
|
2508
2612
|
}
|
|
2509
2613
|
const channelType = this.getChannelTypeById(channelId);
|
|
@@ -2520,25 +2624,10 @@
|
|
|
2520
2624
|
}
|
|
2521
2625
|
};
|
|
2522
2626
|
}
|
|
2523
|
-
if (channelType === ChannelTypes.Private) {
|
|
2524
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 private channel with id ${channelId} (underlying glue context with same name)`);
|
|
2525
|
-
const contextsUnsubscribe = yield this.glueController.contextsSubscribe(channelId, subHandler);
|
|
2526
|
-
yield this.addContextTypeInPrivateChannelContext(channelId, contextType);
|
|
2527
|
-
const targetInstance = yield this.getTargetedInstanceId(channelId);
|
|
2528
|
-
const unsubscribe = () => {
|
|
2529
|
-
this.logger.info(`[${commandId}] - unsubscribe invoked for private channel with id ${channelId}`);
|
|
2530
|
-
contextsUnsubscribe();
|
|
2531
|
-
this.logger.info(`[${commandId}] - invoking onUnsubscribe handler for private channel with id ${channelId}`);
|
|
2532
|
-
this.invokeSystemMethod(targetInstance, PrivateChannelEventMethods.OnUnsubscribe, { channelId, clientId: targetInstance, contextType });
|
|
2533
|
-
};
|
|
2534
|
-
this.logger.info(`[${commandId}] - invoking onAddContextListener handler for private channel with id ${channelId}`);
|
|
2535
|
-
this.invokeSystemMethod(targetInstance, PrivateChannelEventMethods.OnAddContextListener, { channelId: channelId, clientId: targetInstance, contextType });
|
|
2536
|
-
return { unsubscribe };
|
|
2537
|
-
}
|
|
2538
2627
|
throw { message: ChannelError.AccessDenied, reason: "Cannot add a context listener on an invalid channel" };
|
|
2539
2628
|
});
|
|
2540
2629
|
}
|
|
2541
|
-
addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel }) {
|
|
2630
|
+
addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel, contextType }) {
|
|
2542
2631
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2543
2632
|
let unsubscribe;
|
|
2544
2633
|
if (invokedOnChannelModel) {
|
|
@@ -2548,7 +2637,7 @@
|
|
|
2548
2637
|
}
|
|
2549
2638
|
else {
|
|
2550
2639
|
this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
2551
|
-
unsubscribe = this.glueController.channelsSubscribe(handler);
|
|
2640
|
+
unsubscribe = this.glueController.channelsSubscribe(handler, contextType);
|
|
2552
2641
|
}
|
|
2553
2642
|
return {
|
|
2554
2643
|
unsubscribe: () => {
|
|
@@ -2563,56 +2652,21 @@
|
|
|
2563
2652
|
if (isUser) {
|
|
2564
2653
|
return ChannelTypes.User;
|
|
2565
2654
|
}
|
|
2566
|
-
const isPrivate = this.isPrivateChannel(channelId);
|
|
2567
|
-
if (isPrivate) {
|
|
2568
|
-
return ChannelTypes.Private;
|
|
2569
|
-
}
|
|
2570
2655
|
const isApp = this.doesAppChannelExist(channelId);
|
|
2571
2656
|
if (isApp) {
|
|
2572
2657
|
return ChannelTypes.App;
|
|
2573
2658
|
}
|
|
2574
2659
|
throw { message: ChannelError.NoChannelFound, reason: `Channel with id: ${channelId} does not exist` };
|
|
2575
2660
|
}
|
|
2576
|
-
|
|
2577
|
-
return
|
|
2578
|
-
const { clientId, creatorId } = yield this.glueController.getContext(channelId);
|
|
2579
|
-
const myId = this.glueController.getMyInteropInstanceId();
|
|
2580
|
-
return myId === clientId ? creatorId : clientId;
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
getOtherInstanceIdFromClosedOne(channelId, closedInstanceId) {
|
|
2584
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2585
|
-
const { clientId, creatorId } = yield this.glueController.getContext(channelId);
|
|
2586
|
-
return closedInstanceId === clientId
|
|
2587
|
-
? creatorId
|
|
2588
|
-
: clientId;
|
|
2589
|
-
});
|
|
2590
|
-
}
|
|
2591
|
-
invokeSystemMethod(clientId, action, payload) {
|
|
2592
|
-
if (clientId) {
|
|
2593
|
-
this.glueController.invokeSystemMethod({ action, payload });
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
addContextTypeInPrivateChannelContext(channelId, contextType) {
|
|
2597
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2598
|
-
const currentContext = yield this.glueController.getContext(channelId);
|
|
2599
|
-
const updatedTypes = currentContext.contextListenerTypes ? [...currentContext.contextListenerTypes, contextType] : [contextType];
|
|
2600
|
-
return this.glueController.updateContext(channelId, Object.assign(Object.assign({}, currentContext), { contextListenerTypes: updatedTypes }));
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
getContextTypesForPrivateChannel(channelId) {
|
|
2604
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2605
|
-
const ctx = yield this.glueController.getContext(channelId);
|
|
2606
|
-
return ctx.contextListenerTypes;
|
|
2607
|
-
});
|
|
2661
|
+
buildChannel(type, data) {
|
|
2662
|
+
return this.channelsFactory.buildModel(Object.assign({ type }, data));
|
|
2608
2663
|
}
|
|
2609
2664
|
}
|
|
2610
2665
|
|
|
2611
2666
|
class EventReceiver {
|
|
2612
|
-
constructor(glueController, eventDispatcher
|
|
2667
|
+
constructor(glueController, eventDispatcher) {
|
|
2613
2668
|
this.glueController = glueController;
|
|
2614
2669
|
this.eventDispatcher = eventDispatcher;
|
|
2615
|
-
this.eventsController = eventsController;
|
|
2616
2670
|
this.glueResponseReceived = false;
|
|
2617
2671
|
this.glueInitialized = false;
|
|
2618
2672
|
this.events = {
|
|
@@ -2658,7 +2712,6 @@
|
|
|
2658
2712
|
}
|
|
2659
2713
|
window.removeEventListener(GLUE42_EVENT_NAME, this._glueReceiverHandler);
|
|
2660
2714
|
this.glueController.initialize(glue);
|
|
2661
|
-
yield this.eventsController.initialize();
|
|
2662
2715
|
this.eventDispatcher.fireFdc3Ready();
|
|
2663
2716
|
this.glueInitialized = true;
|
|
2664
2717
|
});
|
|
@@ -2670,16 +2723,17 @@
|
|
|
2670
2723
|
this._currentChannel = null;
|
|
2671
2724
|
this._userChannels = {};
|
|
2672
2725
|
this._fdc3ChannelIdsToGlueChannelNames = {};
|
|
2726
|
+
this._privateChannels = {};
|
|
2673
2727
|
}
|
|
2674
2728
|
get currentChannel() {
|
|
2675
2729
|
return this._currentChannel;
|
|
2676
2730
|
}
|
|
2677
|
-
get userChannels() {
|
|
2678
|
-
return this._userChannels;
|
|
2679
|
-
}
|
|
2680
2731
|
set currentChannel(newChannelValue) {
|
|
2681
2732
|
this._currentChannel = newChannelValue;
|
|
2682
2733
|
}
|
|
2734
|
+
get userChannels() {
|
|
2735
|
+
return this._userChannels;
|
|
2736
|
+
}
|
|
2683
2737
|
addUserChannel(channel) {
|
|
2684
2738
|
this._userChannels[channel.id] = channel;
|
|
2685
2739
|
}
|
|
@@ -2693,140 +2747,14 @@
|
|
|
2693
2747
|
const [key] = Object.entries(this._fdc3ChannelIdsToGlueChannelNames).find(([_, value]) => value === glueChannelName);
|
|
2694
2748
|
return key;
|
|
2695
2749
|
}
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
class PrivateChannel {
|
|
2699
|
-
constructor(channelsController, channelId) {
|
|
2700
|
-
this.channelsController = channelsController;
|
|
2701
|
-
this.type = ChannelTypes.Private;
|
|
2702
|
-
this.id = channelId || `${PrivateChannelPrefix}${nanoid()}`;
|
|
2703
|
-
this.unsubFromInstanceStopped = this.channelsController.registerOnInstanceStopped({ commandId: generateCommandId(), channelId: this.id });
|
|
2704
|
-
}
|
|
2705
|
-
toApi() {
|
|
2706
|
-
const api = {
|
|
2707
|
-
id: this.id,
|
|
2708
|
-
type: this.type,
|
|
2709
|
-
displayMetadata: this.displayMetadata,
|
|
2710
|
-
broadcast: this.broadcast.bind(this),
|
|
2711
|
-
getCurrentContext: this.getCurrentContext.bind(this),
|
|
2712
|
-
addContextListener: this.addContextListener.bind(this),
|
|
2713
|
-
onAddContextListener: this.onAddContextListener.bind(this),
|
|
2714
|
-
onUnsubscribe: this.onUnsubscribe.bind(this),
|
|
2715
|
-
onDisconnect: this.onDisconnect.bind(this),
|
|
2716
|
-
disconnect: this.disconnect.bind(this),
|
|
2717
|
-
};
|
|
2718
|
-
return api;
|
|
2750
|
+
addPrivateChannel(privateChannel) {
|
|
2751
|
+
this._privateChannels[privateChannel.id] = privateChannel;
|
|
2719
2752
|
}
|
|
2720
|
-
|
|
2721
|
-
return
|
|
2722
|
-
const commandId = generateCommandId();
|
|
2723
|
-
const isDisconnected = yield this.channelsController.isPrivateChannelDisconnected({ commandId, channelId: this.id });
|
|
2724
|
-
if (isDisconnected) {
|
|
2725
|
-
throw { message: ChannelError.AccessDenied, reason: "Channel has disconnected - broadcast is no longer available" };
|
|
2726
|
-
}
|
|
2727
|
-
contextDecoder.runWithException(context);
|
|
2728
|
-
return this.channelsController.broadcast(commandId, context, this.id);
|
|
2729
|
-
});
|
|
2753
|
+
getPrivateChannelById(id) {
|
|
2754
|
+
return this._privateChannels[id];
|
|
2730
2755
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
2734
|
-
return this.channelsController.getContextForChannel({ commandId: generateCommandId(), channelId: this.id, contextType });
|
|
2735
|
-
});
|
|
2736
|
-
}
|
|
2737
|
-
addContextListener(contextType, handler) {
|
|
2738
|
-
return __awaiter(this, arguments, void 0, function* () {
|
|
2739
|
-
if (arguments.length === 1) {
|
|
2740
|
-
if (typeof contextType !== "function") {
|
|
2741
|
-
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof contextType}` };
|
|
2742
|
-
}
|
|
2743
|
-
return this.channelsController.addContextListener({ commandId: generateCommandId(), handler: contextType, channelId: this.id });
|
|
2744
|
-
}
|
|
2745
|
-
const contextTypeDecoder = optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
2746
|
-
if (typeof handler !== "function") {
|
|
2747
|
-
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof contextType}` };
|
|
2748
|
-
}
|
|
2749
|
-
return this.channelsController.addContextListener({
|
|
2750
|
-
commandId: generateCommandId(),
|
|
2751
|
-
contextType: contextTypeDecoder,
|
|
2752
|
-
channelId: this.id,
|
|
2753
|
-
handler,
|
|
2754
|
-
});
|
|
2755
|
-
});
|
|
2756
|
-
}
|
|
2757
|
-
onAddContextListener(handler) {
|
|
2758
|
-
if (typeof handler !== "function") {
|
|
2759
|
-
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
2760
|
-
}
|
|
2761
|
-
const unsub = this.channelsController.addPrivateChannelEvent({
|
|
2762
|
-
commandId: generateCommandId(),
|
|
2763
|
-
action: PrivateChannelEventMethods.OnAddContextListener,
|
|
2764
|
-
channelId: this.id,
|
|
2765
|
-
handler
|
|
2766
|
-
});
|
|
2767
|
-
return AsyncListener(unsub);
|
|
2768
|
-
}
|
|
2769
|
-
onUnsubscribe(handler) {
|
|
2770
|
-
if (typeof handler !== "function") {
|
|
2771
|
-
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
2772
|
-
}
|
|
2773
|
-
const unsub = this.channelsController.addPrivateChannelEvent({
|
|
2774
|
-
commandId: generateCommandId(),
|
|
2775
|
-
action: PrivateChannelEventMethods.OnUnsubscribe,
|
|
2776
|
-
channelId: this.id,
|
|
2777
|
-
handler
|
|
2778
|
-
});
|
|
2779
|
-
return AsyncListener(unsub);
|
|
2780
|
-
}
|
|
2781
|
-
onDisconnect(handler) {
|
|
2782
|
-
if (typeof handler !== "function") {
|
|
2783
|
-
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
2784
|
-
}
|
|
2785
|
-
const unsub = this.channelsController.addPrivateChannelEvent({
|
|
2786
|
-
commandId: generateCommandId(),
|
|
2787
|
-
action: PrivateChannelEventMethods.OnDisconnect,
|
|
2788
|
-
channelId: this.id,
|
|
2789
|
-
handler
|
|
2790
|
-
});
|
|
2791
|
-
return AsyncListener(unsub);
|
|
2792
|
-
}
|
|
2793
|
-
disconnect() {
|
|
2794
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2795
|
-
yield this.channelsController.announceDisconnect(generateCommandId(), this.id);
|
|
2796
|
-
this.unsubFromInstanceStopped();
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
|
-
}
|
|
2800
|
-
|
|
2801
|
-
class ChannelsFactory {
|
|
2802
|
-
constructor(createUserChannelFn, createAppChannel, createPrivateChannel) {
|
|
2803
|
-
this.createUserChannelFn = createUserChannelFn;
|
|
2804
|
-
this.createAppChannel = createAppChannel;
|
|
2805
|
-
this.createPrivateChannel = createPrivateChannel;
|
|
2806
|
-
}
|
|
2807
|
-
buildModel(data) {
|
|
2808
|
-
const { type } = data;
|
|
2809
|
-
if (type === ChannelTypes.User) {
|
|
2810
|
-
return this.buildUserChannel(data.displayMetadata.glueChannel);
|
|
2811
|
-
}
|
|
2812
|
-
else if (type === ChannelTypes.App) {
|
|
2813
|
-
return this.buildAppChannel(data.id);
|
|
2814
|
-
}
|
|
2815
|
-
else if (type === ChannelTypes.Private) {
|
|
2816
|
-
return this.buildPrivateChannel(data.id);
|
|
2817
|
-
}
|
|
2818
|
-
else {
|
|
2819
|
-
throw new Error("Pass one of the supported channel types: user, app, private");
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
buildUserChannel(data) {
|
|
2823
|
-
return this.createUserChannelFn(data);
|
|
2824
|
-
}
|
|
2825
|
-
buildAppChannel(channelId) {
|
|
2826
|
-
return this.createAppChannel(channelId);
|
|
2827
|
-
}
|
|
2828
|
-
buildPrivateChannel(channelId) {
|
|
2829
|
-
return this.createPrivateChannel(channelId);
|
|
2756
|
+
removePrivateChannelById(id) {
|
|
2757
|
+
delete this._privateChannels[id];
|
|
2830
2758
|
}
|
|
2831
2759
|
}
|
|
2832
2760
|
|
|
@@ -2947,36 +2875,345 @@
|
|
|
2947
2875
|
createRegistry.default = createRegistry;
|
|
2948
2876
|
var lib = createRegistry;
|
|
2949
2877
|
|
|
2950
|
-
class
|
|
2951
|
-
constructor() {
|
|
2878
|
+
class PrivateChannel {
|
|
2879
|
+
constructor(channelsController, logger, channelId, isCreator) {
|
|
2880
|
+
this.channelsController = channelsController;
|
|
2881
|
+
this.logger = logger;
|
|
2882
|
+
this.isCreator = isCreator;
|
|
2883
|
+
this.type = ChannelTypes.Private;
|
|
2884
|
+
this.disconnected = false;
|
|
2885
|
+
this.broadcastedContexts = {};
|
|
2886
|
+
this.collaboratorListenerTypes = [];
|
|
2887
|
+
this.myListenerTypesBeforeBound = [];
|
|
2952
2888
|
this.registry = lib();
|
|
2889
|
+
this.id = channelId;
|
|
2890
|
+
const myServerInstance = this.channelsController.getMyServerInstance();
|
|
2891
|
+
this.myAppMetadata = { source: { appId: myServerInstance.applicationName, instanceId: myServerInstance.instance } };
|
|
2892
|
+
}
|
|
2893
|
+
toApi() {
|
|
2894
|
+
const api = {
|
|
2895
|
+
id: this.id,
|
|
2896
|
+
type: this.type,
|
|
2897
|
+
displayMetadata: this.displayMetadata,
|
|
2898
|
+
broadcast: this.broadcast.bind(this),
|
|
2899
|
+
getCurrentContext: this.getCurrentContext.bind(this),
|
|
2900
|
+
addContextListener: this.addContextListener.bind(this),
|
|
2901
|
+
onAddContextListener: this.onAddContextListener.bind(this),
|
|
2902
|
+
onUnsubscribe: this.onUnsubscribe.bind(this),
|
|
2903
|
+
onDisconnect: this.onDisconnect.bind(this),
|
|
2904
|
+
disconnect: this.disconnect.bind(this),
|
|
2905
|
+
};
|
|
2906
|
+
return api;
|
|
2907
|
+
}
|
|
2908
|
+
getCollaborator() {
|
|
2909
|
+
return this.collaborator;
|
|
2910
|
+
}
|
|
2911
|
+
setCollaborator(collaborator, commandId) {
|
|
2912
|
+
if (this.collaborator && this.collaborator.instanceId !== collaborator.instanceId) {
|
|
2913
|
+
throw new Error(`There's already a collaborator for private channel with id ${this.id}`);
|
|
2914
|
+
}
|
|
2915
|
+
this.collaborator = collaborator;
|
|
2916
|
+
this.subscribeForCollaboratorInstanceStop(commandId);
|
|
2917
|
+
}
|
|
2918
|
+
handleCollaboratorJoin(collaborator, commandId) {
|
|
2919
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2920
|
+
this.setCollaborator(collaborator, commandId);
|
|
2921
|
+
yield Promise.all(this.myListenerTypesBeforeBound.map((contextType) => {
|
|
2922
|
+
var _a;
|
|
2923
|
+
const listenerAddedArgs = {
|
|
2924
|
+
action: "addedContextListenerOnPrivateChannel",
|
|
2925
|
+
correlationId: this.id,
|
|
2926
|
+
collaborationObject: {
|
|
2927
|
+
channelId: this.id,
|
|
2928
|
+
contextType: contextType || undefined
|
|
2929
|
+
}
|
|
2930
|
+
};
|
|
2931
|
+
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2932
|
+
return this.channelsController.invokeSystemMethod(listenerAddedArgs, (_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId);
|
|
2933
|
+
})).catch((err) => this.logger.error(err));
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
handleCollaboratorBroadcast(context, metadata, commandId) {
|
|
2937
|
+
this.logger.trace(`[${commandId}] - heard context with type ${context.type} broadcasted on the channel`);
|
|
2938
|
+
this.lastBroadcastedContextType = context.type;
|
|
2939
|
+
this.broadcastedContexts[context.type] = { context, metadata };
|
|
2940
|
+
this.logger.trace(`[${commandId}] - invoking all context listeners`);
|
|
2941
|
+
this.registry.execute(PrivateChannelEventMethods.ListenerAdded, context, metadata);
|
|
2942
|
+
}
|
|
2943
|
+
handleCollaboratorAddContextListener(contextType, commandId) {
|
|
2944
|
+
this.logger.trace(`[${commandId}] - heard collaborator added context listener for type ${contextType}`);
|
|
2945
|
+
this.collaboratorListenerTypes.push(contextType);
|
|
2946
|
+
this.registry.execute(PrivateChannelEventMethods.OnAddContextListener, contextType);
|
|
2947
|
+
}
|
|
2948
|
+
handleCollaboratorRemovedListener(contextType, commandId) {
|
|
2949
|
+
this.logger.trace(`[${commandId}] - heard collaborator removed context listener with type ${contextType}`);
|
|
2950
|
+
const index = this.collaboratorListenerTypes.indexOf(contextType);
|
|
2951
|
+
this.collaboratorListenerTypes.splice(index, 1);
|
|
2952
|
+
this.registry.execute(PrivateChannelEventMethods.OnUnsubscribe, contextType);
|
|
2953
|
+
}
|
|
2954
|
+
handleCollaboratorDisconnect() {
|
|
2955
|
+
this.disconnected = true;
|
|
2956
|
+
this.collaboratorListenerTypes.forEach((contextType) => this.registry.execute(PrivateChannelEventMethods.OnUnsubscribe, contextType));
|
|
2957
|
+
this.registry.execute(PrivateChannelEventMethods.OnDisconnect);
|
|
2958
|
+
}
|
|
2959
|
+
announceJoin(targetInstance, commandId) {
|
|
2960
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2961
|
+
const joinChannelArgs = {
|
|
2962
|
+
action: "joinPrivateChannel",
|
|
2963
|
+
correlationId: this.id,
|
|
2964
|
+
collaborationObject: {
|
|
2965
|
+
channelId: this.id
|
|
2966
|
+
}
|
|
2967
|
+
};
|
|
2968
|
+
this.logger.trace(`[${commandId}] - announcing ${"joinPrivateChannel"} to target instance with id ${JSON.stringify(targetInstance)}`);
|
|
2969
|
+
yield this.channelsController.invokeSystemMethod(joinChannelArgs, targetInstance);
|
|
2970
|
+
this.logger.trace(`[${commandId}] - collaborator received ${"joinPrivateChannel"} action`);
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
broadcast(context) {
|
|
2974
|
+
var _a;
|
|
2975
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2976
|
+
const commandId = generateCommandId();
|
|
2977
|
+
this.ensureAlive(commandId);
|
|
2978
|
+
this.ensureBound(commandId, "broadcast");
|
|
2979
|
+
contextDecoder.runWithException(context);
|
|
2980
|
+
this.lastBroadcastedContextType = context.type;
|
|
2981
|
+
this.broadcastedContexts[context.type] = { context, metadata: this.myAppMetadata };
|
|
2982
|
+
const broadcastArgs = {
|
|
2983
|
+
action: "publishOnPrivateChannel",
|
|
2984
|
+
correlationId: this.id,
|
|
2985
|
+
collaborationObject: {
|
|
2986
|
+
channelId: this.id,
|
|
2987
|
+
contextType: context.type,
|
|
2988
|
+
payload: context
|
|
2989
|
+
}
|
|
2990
|
+
};
|
|
2991
|
+
this.logger.trace(`[${commandId}] - announcing ${"publishOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2992
|
+
yield this.channelsController.invokeSystemMethod(broadcastArgs, (_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId);
|
|
2993
|
+
this.logger.trace(`[${commandId}] - collaborator received context for action ${"publishOnPrivateChannel"}`);
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2996
|
+
getCurrentContext(contextType) {
|
|
2997
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2998
|
+
const commandId = generateCommandId();
|
|
2999
|
+
this.ensureAlive(commandId);
|
|
3000
|
+
this.logger.trace(`[${commandId}] - getCurrentContext invoked ${contextType ? `with contextType ${contextType}` : ""}`);
|
|
3001
|
+
optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
3002
|
+
if (!contextType && !this.lastBroadcastedContextType) {
|
|
3003
|
+
return null;
|
|
3004
|
+
}
|
|
3005
|
+
const searchedType = contextType || this.lastBroadcastedContextType;
|
|
3006
|
+
this.logger.trace(`[${commandId}] - Returning context with type ${searchedType}`);
|
|
3007
|
+
return this.broadcastedContexts[searchedType].context;
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
3010
|
+
addContextListener(contextType, handler) {
|
|
3011
|
+
var _a;
|
|
3012
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3013
|
+
const commandId = generateCommandId();
|
|
3014
|
+
this.ensureAlive(commandId);
|
|
3015
|
+
optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
3016
|
+
if (typeof handler !== "function") {
|
|
3017
|
+
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof contextType}` };
|
|
3018
|
+
}
|
|
3019
|
+
this.logger.trace(`[${commandId}] - adding subscription for broadcasted contexts with type: ${contextType}`);
|
|
3020
|
+
const subHandler = (data, metadata) => {
|
|
3021
|
+
if (contextType) {
|
|
3022
|
+
if (data.type === contextType) {
|
|
3023
|
+
handler(data, metadata);
|
|
3024
|
+
}
|
|
3025
|
+
return;
|
|
3026
|
+
}
|
|
3027
|
+
handler(data, metadata);
|
|
3028
|
+
};
|
|
3029
|
+
const lastBroadcastedContextPerType = this.retrieveLatestBroadcastedContextPerType(contextType);
|
|
3030
|
+
const replayArgs = lastBroadcastedContextPerType ? [[lastBroadcastedContextPerType.context, lastBroadcastedContextPerType.metadata]] : undefined;
|
|
3031
|
+
const unsub = this.registry.add(PrivateChannelEventMethods.ListenerAdded, subHandler, replayArgs);
|
|
3032
|
+
if (this.collaborator) {
|
|
3033
|
+
const listenerAddedArgs = {
|
|
3034
|
+
action: "addedContextListenerOnPrivateChannel",
|
|
3035
|
+
correlationId: this.id,
|
|
3036
|
+
collaborationObject: {
|
|
3037
|
+
channelId: this.id,
|
|
3038
|
+
contextType: contextType || undefined
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
3041
|
+
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3042
|
+
yield this.channelsController.invokeSystemMethod(listenerAddedArgs, (_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId);
|
|
3043
|
+
this.logger.trace(`[${commandId}] - collaborator received action ${"addedContextListenerOnPrivateChannel"}`);
|
|
3044
|
+
}
|
|
3045
|
+
else {
|
|
3046
|
+
this.myListenerTypesBeforeBound.push(contextType);
|
|
3047
|
+
}
|
|
3048
|
+
const unsubscribe = this.getAddContextListenerUnsub(unsub, contextType, commandId);
|
|
3049
|
+
return AsyncListener(unsubscribe);
|
|
3050
|
+
});
|
|
2953
3051
|
}
|
|
2954
|
-
|
|
2955
|
-
|
|
3052
|
+
retrieveLatestBroadcastedContextPerType(contextType) {
|
|
3053
|
+
if (!contextType && !this.lastBroadcastedContextType) {
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
if (!contextType && this.lastBroadcastedContextType) {
|
|
3057
|
+
return {
|
|
3058
|
+
context: this.broadcastedContexts[this.lastBroadcastedContextType].context,
|
|
3059
|
+
metadata: this.broadcastedContexts[this.lastBroadcastedContextType].metadata
|
|
3060
|
+
};
|
|
3061
|
+
}
|
|
3062
|
+
return this.broadcastedContexts[contextType];
|
|
2956
3063
|
}
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
3064
|
+
getAddContextListenerUnsub(unsub, contextType, commandId) {
|
|
3065
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
3066
|
+
var _a;
|
|
3067
|
+
unsub();
|
|
3068
|
+
if (!this.collaborator) {
|
|
3069
|
+
const index = this.myListenerTypesBeforeBound.indexOf(contextType);
|
|
3070
|
+
this.myListenerTypesBeforeBound.splice(index, 1);
|
|
3071
|
+
return;
|
|
3072
|
+
}
|
|
3073
|
+
const unsubArgs = {
|
|
3074
|
+
action: "removedContextListenerOnPrivateChannel",
|
|
3075
|
+
correlationId: this.id,
|
|
3076
|
+
collaborationObject: {
|
|
3077
|
+
channelId: this.id,
|
|
3078
|
+
contextType: contextType || undefined
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
this.logger.trace(`[${commandId}] - announcing unsubscribe from context listener for type ${contextType}`);
|
|
3082
|
+
yield this.channelsController.invokeSystemMethod(unsubArgs, (_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId);
|
|
3083
|
+
this.logger.trace(`[${commandId}] - collaborator heard ${"removedContextListenerOnPrivateChannel"}`);
|
|
3084
|
+
});
|
|
3085
|
+
}
|
|
3086
|
+
onAddContextListener(handler) {
|
|
3087
|
+
if (typeof handler !== "function") {
|
|
3088
|
+
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
3089
|
+
}
|
|
3090
|
+
const commandId = generateCommandId();
|
|
3091
|
+
this.ensureAlive(commandId);
|
|
3092
|
+
const unsub = this.registry.add(PrivateChannelEventMethods.OnAddContextListener, handler, this.collaboratorListenerTypes);
|
|
3093
|
+
return AsyncListener(unsub);
|
|
3094
|
+
}
|
|
3095
|
+
onUnsubscribe(handler) {
|
|
3096
|
+
if (typeof handler !== "function") {
|
|
3097
|
+
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
3098
|
+
}
|
|
3099
|
+
const commandId = generateCommandId();
|
|
3100
|
+
this.ensureAlive(commandId);
|
|
3101
|
+
const unsub = this.registry.add(PrivateChannelEventMethods.OnUnsubscribe, handler);
|
|
3102
|
+
return AsyncListener(unsub);
|
|
3103
|
+
}
|
|
3104
|
+
onDisconnect(handler) {
|
|
3105
|
+
if (typeof handler !== "function") {
|
|
3106
|
+
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof handler}` };
|
|
3107
|
+
}
|
|
3108
|
+
const commandId = generateCommandId();
|
|
3109
|
+
this.ensureAlive(commandId);
|
|
3110
|
+
const unsub = this.registry.add(PrivateChannelEventMethods.OnDisconnect, handler);
|
|
3111
|
+
return AsyncListener(unsub);
|
|
3112
|
+
}
|
|
3113
|
+
disconnect() {
|
|
3114
|
+
var _a;
|
|
3115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3116
|
+
const commandId = generateCommandId();
|
|
3117
|
+
if (this.isCreator && !this.collaborator) {
|
|
3118
|
+
this.disconnected = true;
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
this.ensureAlive(commandId);
|
|
3122
|
+
this.ensureBound(commandId, "disconnect");
|
|
3123
|
+
this.logger.trace(`[${commandId}] - disconnect invoked`);
|
|
3124
|
+
this.disconnected = true;
|
|
3125
|
+
this.logger.trace(`[${commandId}] - announcing ${"disconnectedFromPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3126
|
+
const disconnectArgs = {
|
|
3127
|
+
action: "disconnectedFromPrivateChannel",
|
|
3128
|
+
correlationId: this.id,
|
|
3129
|
+
collaborationObject: {
|
|
3130
|
+
channelId: this.id
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
this.channelsController.removePrivateChannelFromStoreById(this.id);
|
|
3134
|
+
yield this.channelsController.invokeSystemMethod(disconnectArgs, (_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId);
|
|
3135
|
+
this.logger.trace(`[${commandId}] - collaborator received action ${"disconnectedFromPrivateChannel"}`);
|
|
3136
|
+
if (this.unsubFromInstanceStopped) {
|
|
3137
|
+
this.unsubFromInstanceStopped();
|
|
3138
|
+
}
|
|
3139
|
+
});
|
|
3140
|
+
}
|
|
3141
|
+
ensureAlive(commandId) {
|
|
3142
|
+
if (!this.disconnected) {
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3145
|
+
const errorMsg = "Channel is disconnected - operation is no longer available";
|
|
3146
|
+
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
3147
|
+
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3148
|
+
}
|
|
3149
|
+
ensureBound(commandId, operation) {
|
|
3150
|
+
if (this.collaborator) {
|
|
3151
|
+
return;
|
|
3152
|
+
}
|
|
3153
|
+
const errorMsg = `There's no collaborator on the other side of the channel - operation ${operation} is unavailable`;
|
|
3154
|
+
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
3155
|
+
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3156
|
+
}
|
|
3157
|
+
subscribeForCollaboratorInstanceStop(commandId) {
|
|
3158
|
+
const handler = (instance) => {
|
|
3159
|
+
var _a;
|
|
3160
|
+
if (instance.id !== ((_a = this.collaborator) === null || _a === void 0 ? void 0 : _a.instanceId)) {
|
|
3161
|
+
return;
|
|
3162
|
+
}
|
|
3163
|
+
this.handleCollaboratorDisconnect();
|
|
3164
|
+
};
|
|
3165
|
+
this.unsubFromInstanceStopped = this.channelsController.subscribeOnInstanceStop(this.id, handler.bind(this), commandId);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
class ChannelsFactory {
|
|
3170
|
+
constructor(createUserChannelFn, createAppChannel, createPrivateChannel) {
|
|
3171
|
+
this.createUserChannelFn = createUserChannelFn;
|
|
3172
|
+
this.createAppChannel = createAppChannel;
|
|
3173
|
+
this.createPrivateChannel = createPrivateChannel;
|
|
3174
|
+
}
|
|
3175
|
+
buildModel(data) {
|
|
3176
|
+
const { type } = data;
|
|
3177
|
+
const lowerType = type === null || type === void 0 ? void 0 : type.toLowerCase();
|
|
3178
|
+
if (lowerType === ChannelTypes.User) {
|
|
3179
|
+
return this.createUserChannelFn(data.displayMetadata.glueChannel);
|
|
3180
|
+
}
|
|
3181
|
+
if (lowerType === ChannelTypes.App) {
|
|
3182
|
+
return this.createAppChannel(data.id);
|
|
3183
|
+
}
|
|
3184
|
+
if (lowerType === ChannelTypes.Private) {
|
|
3185
|
+
return this.createPrivateChannel(data.logger, data.id, data.isCreator);
|
|
3186
|
+
}
|
|
3187
|
+
throw new Error("Pass one of the supported channel types: user, app, private");
|
|
2960
3188
|
}
|
|
2961
3189
|
}
|
|
2962
3190
|
|
|
2963
3191
|
class GlueEventsController {
|
|
2964
|
-
constructor(glueController,
|
|
3192
|
+
constructor(glueController, channelsStateStore, appsStateStore) {
|
|
2965
3193
|
this.glueController = glueController;
|
|
2966
|
-
this.
|
|
3194
|
+
this.channelsStateStore = channelsStateStore;
|
|
3195
|
+
this.appsStateStore = appsStateStore;
|
|
3196
|
+
this.actionDictionary = {
|
|
3197
|
+
joinPrivateChannel: this.handleJoin.bind(this),
|
|
3198
|
+
publishOnPrivateChannel: this.handlePublish.bind(this),
|
|
3199
|
+
addedContextListenerOnPrivateChannel: this.handleContextListenerAdded.bind(this),
|
|
3200
|
+
removedContextListenerOnPrivateChannel: this.handleContextListenerRemoved.bind(this),
|
|
3201
|
+
disconnectedFromPrivateChannel: this.handleDisconnect.bind(this),
|
|
3202
|
+
startupContextOpened: this.handleStartupContextOpened.bind(this)
|
|
3203
|
+
};
|
|
2967
3204
|
}
|
|
2968
|
-
|
|
3205
|
+
initializeCollaborateMethod() {
|
|
2969
3206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2970
|
-
const
|
|
2971
|
-
if (
|
|
3207
|
+
const methodRegisteredByMe = this.checkSystemMethodRegistered();
|
|
3208
|
+
if (methodRegisteredByMe) {
|
|
2972
3209
|
return;
|
|
2973
3210
|
}
|
|
2974
|
-
yield this.glueController.registerMethod(
|
|
3211
|
+
yield this.glueController.registerMethod(ioConnectFDC3SystemMethod, this.handleReceivedAction.bind(this));
|
|
2975
3212
|
});
|
|
2976
3213
|
}
|
|
2977
|
-
|
|
2978
|
-
const methods = this.glueController.getInteropMethods(
|
|
2979
|
-
const myId = this.glueController.
|
|
3214
|
+
checkSystemMethodRegistered() {
|
|
3215
|
+
const methods = this.glueController.getInteropMethods(ioConnectFDC3SystemMethod);
|
|
3216
|
+
const myId = this.glueController.getMyInteropInstance().instance;
|
|
2980
3217
|
const methodsByThisInstance = methods.filter(method => {
|
|
2981
3218
|
return method.getServers().find(server => server.instance === myId)
|
|
2982
3219
|
? method
|
|
@@ -2984,29 +3221,111 @@
|
|
|
2984
3221
|
});
|
|
2985
3222
|
return !!methodsByThisInstance.length;
|
|
2986
3223
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3224
|
+
handleReceivedAction(eventArgs, instance) {
|
|
3225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3226
|
+
const argsDecodeResult = SystemMethodInvocationArgumentDecoder.run(eventArgs);
|
|
3227
|
+
if (!argsDecodeResult.ok) {
|
|
3228
|
+
throw new Error(`Interop Method ${ioConnectFDC3SystemMethod} invoked with invalid argument object - ${argsDecodeResult.error}`);
|
|
3229
|
+
}
|
|
3230
|
+
const commandId = generateCommandId();
|
|
3231
|
+
this.logger.log(`${commandId} - received system method from instance with id ${instance.instance} for action ${eventArgs.action} with arguments: ${JSON.stringify(eventArgs)}`);
|
|
3232
|
+
const operation = this.actionDictionary[eventArgs.action];
|
|
3233
|
+
if (!operation) {
|
|
3234
|
+
const errorMsg = `Unsupported private channel action: ${eventArgs.action}`;
|
|
3235
|
+
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
3236
|
+
throw new Error(errorMsg);
|
|
3237
|
+
}
|
|
3238
|
+
yield operation(eventArgs, instance, commandId);
|
|
3239
|
+
});
|
|
3240
|
+
}
|
|
3241
|
+
get logger() {
|
|
3242
|
+
if (!this._logger) {
|
|
3243
|
+
this._logger = this.glueController.initSubLogger("fdc3.private.channels.controller");
|
|
3244
|
+
}
|
|
3245
|
+
return this._logger;
|
|
3246
|
+
}
|
|
3247
|
+
validateAndRetrieveChannel({ action, correlationId }, instance, commandId) {
|
|
3248
|
+
const privateChannel = this.channelsStateStore.getPrivateChannelById(correlationId);
|
|
3249
|
+
if (!privateChannel) {
|
|
3250
|
+
const errorMsg = `There's no private channel with id ${correlationId}`;
|
|
3251
|
+
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
3252
|
+
throw new Error(errorMsg);
|
|
2991
3253
|
}
|
|
2992
|
-
const
|
|
2993
|
-
if (action ===
|
|
2994
|
-
return
|
|
3254
|
+
const channelCollaborator = privateChannel.getCollaborator();
|
|
3255
|
+
if (action === "joinPrivateChannel") {
|
|
3256
|
+
return privateChannel;
|
|
2995
3257
|
}
|
|
2996
|
-
if (
|
|
2997
|
-
|
|
3258
|
+
if (channelCollaborator && channelCollaborator.instanceId === instance.instance) {
|
|
3259
|
+
this.logger.log(`[${commandId}] - request sent from correct collaborator with id ${instance.instance}. Returning channel`);
|
|
3260
|
+
return privateChannel;
|
|
2998
3261
|
}
|
|
3262
|
+
const errorMsg = `Cannot proceed with action ${action} - ${channelCollaborator
|
|
3263
|
+
? `private channel ${correlationId} established communication with collaborator with id ${channelCollaborator}`
|
|
3264
|
+
: `no collaborator joined private channel with id ${correlationId}`}`;
|
|
3265
|
+
this.logger.error(errorMsg);
|
|
3266
|
+
throw new Error(errorMsg);
|
|
3267
|
+
}
|
|
3268
|
+
handleJoin(eventArgs, instance, commandId) {
|
|
3269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3270
|
+
const collaborator = { appId: instance.application || instance.applicationName, instanceId: instance.instance };
|
|
3271
|
+
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3272
|
+
yield privateChannel.handleCollaboratorJoin(collaborator, commandId);
|
|
3273
|
+
this.logger.log(`[${commandId}] - collaborator ${JSON.stringify(collaborator)} set for private channel with id ${eventArgs.correlationId}`);
|
|
3274
|
+
});
|
|
3275
|
+
}
|
|
3276
|
+
handlePublish(eventArgs, instance, commandId) {
|
|
3277
|
+
var _a, _b;
|
|
3278
|
+
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, adding context with type ${(_a = eventArgs.collaborationObject) === null || _a === void 0 ? void 0 : _a.contextType} to the private channel broadcasted contexts`);
|
|
3279
|
+
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3280
|
+
const metadata = {
|
|
3281
|
+
source: {
|
|
3282
|
+
appId: instance.application || instance.applicationName || "",
|
|
3283
|
+
instanceId: instance.instance
|
|
3284
|
+
}
|
|
3285
|
+
};
|
|
3286
|
+
privateChannel.handleCollaboratorBroadcast((_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.payload, metadata, commandId);
|
|
3287
|
+
}
|
|
3288
|
+
handleContextListenerAdded(eventArgs, instance, commandId) {
|
|
3289
|
+
var _a;
|
|
3290
|
+
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onAddContextListener' callbacks`);
|
|
3291
|
+
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3292
|
+
privateChannel.handleCollaboratorAddContextListener(((_a = eventArgs.collaborationObject) === null || _a === void 0 ? void 0 : _a.contextType) || null, commandId);
|
|
2999
3293
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3294
|
+
handleContextListenerRemoved(eventArgs, instance, commandId) {
|
|
3295
|
+
var _a;
|
|
3296
|
+
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onUnsubscribe' callbacks`);
|
|
3297
|
+
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3298
|
+
privateChannel.handleCollaboratorRemovedListener(((_a = eventArgs.collaborationObject) === null || _a === void 0 ? void 0 : _a.contextType) || null, commandId);
|
|
3299
|
+
}
|
|
3300
|
+
handleDisconnect(eventArgs, instance, commandId) {
|
|
3301
|
+
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onDisconnect' callbacks`);
|
|
3302
|
+
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3303
|
+
privateChannel.handleCollaboratorDisconnect();
|
|
3304
|
+
}
|
|
3305
|
+
handleStartupContextOpened(eventArgs, instance, commandId) {
|
|
3306
|
+
this.logger.log(`[${commandId}] - received ${eventArgs.action} with correlationId: ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
3307
|
+
const wrappedPromise = this.appsStateStore.getOpenAppPromise(eventArgs.correlationId);
|
|
3308
|
+
if (!wrappedPromise) {
|
|
3309
|
+
this.logger.log(`[${commandId}] - there's no open app promise related to guid ${eventArgs.correlationId}`);
|
|
3310
|
+
return;
|
|
3003
3311
|
}
|
|
3004
|
-
this.
|
|
3312
|
+
this.logger.log(`[${commandId}] - resolving open app promise related to guid ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
3313
|
+
wrappedPromise.resolve();
|
|
3005
3314
|
}
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
class ApplicationsStateStore {
|
|
3318
|
+
constructor() {
|
|
3319
|
+
this.openAppPromises = {};
|
|
3320
|
+
}
|
|
3321
|
+
addOpenAppPromise(guid, promise) {
|
|
3322
|
+
this.openAppPromises[guid] = promise;
|
|
3323
|
+
}
|
|
3324
|
+
getOpenAppPromise(guid) {
|
|
3325
|
+
return this.openAppPromises[guid];
|
|
3326
|
+
}
|
|
3327
|
+
removeOpenAppPromise(guid) {
|
|
3328
|
+
delete this.openAppPromises[guid];
|
|
3010
3329
|
}
|
|
3011
3330
|
}
|
|
3012
3331
|
|
|
@@ -3016,7 +3335,7 @@
|
|
|
3016
3335
|
}
|
|
3017
3336
|
get eventReceiver() {
|
|
3018
3337
|
if (!this._eventReceiver) {
|
|
3019
|
-
this._eventReceiver = new EventReceiver(this.glueController, this.eventDispatcher
|
|
3338
|
+
this._eventReceiver = new EventReceiver(this.glueController, this.eventDispatcher);
|
|
3020
3339
|
}
|
|
3021
3340
|
return this._eventReceiver;
|
|
3022
3341
|
}
|
|
@@ -3050,8 +3369,8 @@
|
|
|
3050
3369
|
createAppChannel(id) {
|
|
3051
3370
|
return new AppChannel(this.channelsController, id).toApi();
|
|
3052
3371
|
}
|
|
3053
|
-
createPrivateChannel(channelId) {
|
|
3054
|
-
return new PrivateChannel(this.channelsController, channelId)
|
|
3372
|
+
createPrivateChannel(logger, channelId, isCreator) {
|
|
3373
|
+
return new PrivateChannel(this.channelsController, logger, channelId, isCreator);
|
|
3055
3374
|
}
|
|
3056
3375
|
get desktopAgent() {
|
|
3057
3376
|
if (!this._desktopAgent) {
|
|
@@ -3067,19 +3386,19 @@
|
|
|
3067
3386
|
}
|
|
3068
3387
|
get intentsController() {
|
|
3069
3388
|
if (!this._intentsController) {
|
|
3070
|
-
this._intentsController = new IntentsController(this.glueController, this.channelsController, this.channelsFactory);
|
|
3389
|
+
this._intentsController = new IntentsController(this.glueController, this.channelsController, this.channelsFactory, this.eventsController);
|
|
3071
3390
|
}
|
|
3072
3391
|
return this._intentsController;
|
|
3073
3392
|
}
|
|
3074
3393
|
get applicationController() {
|
|
3075
3394
|
if (!this._applicationController) {
|
|
3076
|
-
this._applicationController = new ApplicationsController(this.glueController);
|
|
3395
|
+
this._applicationController = new ApplicationsController(this.glueController, this.applicationsStateStore, this.eventsController);
|
|
3077
3396
|
}
|
|
3078
3397
|
return this._applicationController;
|
|
3079
3398
|
}
|
|
3080
3399
|
get channelsController() {
|
|
3081
3400
|
if (!this._channelsController) {
|
|
3082
|
-
this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.
|
|
3401
|
+
this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.eventsController);
|
|
3083
3402
|
}
|
|
3084
3403
|
return this._channelsController;
|
|
3085
3404
|
}
|
|
@@ -3089,18 +3408,18 @@
|
|
|
3089
3408
|
}
|
|
3090
3409
|
return this._channelsStateStore;
|
|
3091
3410
|
}
|
|
3092
|
-
get channelsCallbackRegistry() {
|
|
3093
|
-
if (!this._channelsCallbackRegistry) {
|
|
3094
|
-
this._channelsCallbackRegistry = new ChannelsCallbackRegistry();
|
|
3095
|
-
}
|
|
3096
|
-
return this._channelsCallbackRegistry;
|
|
3097
|
-
}
|
|
3098
3411
|
get eventsController() {
|
|
3099
3412
|
if (!this._eventsController) {
|
|
3100
|
-
this._eventsController = new GlueEventsController(this.glueController, this.
|
|
3413
|
+
this._eventsController = new GlueEventsController(this.glueController, this.channelsStateStore, this.applicationsStateStore);
|
|
3101
3414
|
}
|
|
3102
3415
|
return this._eventsController;
|
|
3103
3416
|
}
|
|
3417
|
+
get applicationsStateStore() {
|
|
3418
|
+
if (!this._applicationsStateStore) {
|
|
3419
|
+
this._applicationsStateStore = new ApplicationsStateStore();
|
|
3420
|
+
}
|
|
3421
|
+
return this._applicationsStateStore;
|
|
3422
|
+
}
|
|
3104
3423
|
}
|
|
3105
3424
|
|
|
3106
3425
|
const fdc3Factory = () => {
|