@microsoft/omnichannel-amsclient
Advanced tools
Comparing version 0.1.0-main.294e9eb to 0.1.0-main.32eec41
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## [Unreleased] | ||
## [Unreleased] | ||
### Added | ||
- Prevent multiple iframes being loaded | ||
- Add `dispose()` on `FramedClient` | ||
- Use `amsEndpoint` property by default |
@@ -97,3 +97,3 @@ "use strict"; | ||
patchChatToken(chatToken); | ||
url = ((_b = chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams) + "/v1/skypetokenauth"; | ||
url = (chatToken.amsEndpoint || ((_b = chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams)) + "/v1/skypetokenauth"; | ||
headers = (_a = {}, | ||
@@ -142,3 +142,3 @@ _a[HeadersName.Authorization] = "skype_token " + chatToken.token, | ||
patchChatToken(chatToken); | ||
url = ((_c = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _c === void 0 ? void 0 : _c.ams) + "/v1/objects"; | ||
url = (chatToken.amsEndpoint || ((_c = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _c === void 0 ? void 0 : _c.ams)) + "/v1/objects"; | ||
headers = __assign(__assign({}, createDefaultHeaders(chatToken.token)), (_b = {}, _b[HeadersName.ContentType] = MIMEType.applicationJson, _b)); | ||
@@ -178,3 +178,3 @@ request = { | ||
patchChatToken(chatToken); | ||
url = ((_b = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams) + "/v1/objects/" + documentId + "/content/" + (file.type.includes('image') ? 'imgpsh' : 'original'); | ||
url = (chatToken.amsEndpoint || ((_b = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _b === void 0 ? void 0 : _b.ams)) + "/v1/objects/" + documentId + "/content/" + (file.type.includes('image') ? 'imgpsh' : 'original'); | ||
headers = __assign(__assign({}, createDefaultHeaders(chatToken.token)), (_a = {}, _a[HeadersName.ContentType] = MIMEType.applicationFormUrlEncoded, _a)); | ||
@@ -217,3 +217,3 @@ request = { | ||
patchChatToken(chatToken); | ||
url = ((_a = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _a === void 0 ? void 0 : _a.ams) + "/v1/objects/" + fileMetadata.id + "/views/" + (validImageTypes.includes(fileMetadata.type) ? 'imgpsh_fullsize_anim' : 'original') + "/status"; | ||
url = (chatToken.amsEndpoint || ((_a = chatToken === null || chatToken === void 0 ? void 0 : chatToken.regionGTMS) === null || _a === void 0 ? void 0 : _a.ams)) + "/v1/objects/" + fileMetadata.id + "/views/" + (validImageTypes.includes(fileMetadata.type) ? 'imgpsh_fullsize_anim' : 'original') + "/status"; | ||
headers = createDefaultHeaders(chatToken.token); | ||
@@ -220,0 +220,0 @@ request = { |
@@ -1,1 +0,1 @@ | ||
exports.baseUrl = 'https://comms-test.omnichannelengagementhub.com/ams'; exports.sdkVersion = '0.1.0-main.294e9eb'; | ||
exports.baseUrl = 'https://comms.omnichannelengagementhub.com/ams'; exports.sdkVersion = '0.1.0-main.32eec41'; |
export default interface FileMetadata { | ||
fileSharingProtocolType: number; | ||
fileSharingProtocolType?: number; | ||
id: string; | ||
name: string; | ||
size: number; | ||
name?: string; | ||
size?: number; | ||
type: string; | ||
url: string; | ||
url?: string; | ||
} |
@@ -10,2 +10,3 @@ import AMSFileInfo from "./AMSFileInfo"; | ||
declare class FramedClient { | ||
private iframeId; | ||
private origin; | ||
@@ -29,5 +30,6 @@ private targetWindow; | ||
postMessage(eventType: PostMessageEventType, eventName: PostMessageEventName, data?: PostMessageRequestData, resolve?: CallableFunction, reject?: CallableFunction): void; | ||
handleEvent(event: MessageEvent<any>): Promise<void>; | ||
private createIframe; | ||
handleEvent(event: MessageEvent): Promise<void>; | ||
dispose(): void; | ||
private loadIframe; | ||
} | ||
export default FramedClient; |
@@ -56,2 +56,3 @@ "use strict"; | ||
var version = config_1.sdkVersion; | ||
var iframePrefix = 'Microsoft_Omnichannel_AMSClient_Iframe_Window'; | ||
var FramedClient = /** @class */ (function () { | ||
@@ -66,2 +67,3 @@ function FramedClient(logger) { | ||
this.logger = logger; | ||
this.iframeId = iframePrefix; | ||
this.onMessageEvent(function (event) { return _this.handleEvent(event); }); // eslint-disable-line @typescript-eslint/no-explicit-any | ||
@@ -83,3 +85,3 @@ } | ||
} | ||
return [4 /*yield*/, this.createIframe()]; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
@@ -105,10 +107,16 @@ _a.sent(); | ||
return __generator(this, function (_a) { | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][skypeAuth]"); | ||
data = { | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.SkypeTokenAuth, data, resolve, reject); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][skypeAuth]"); | ||
data = { | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.SkypeTokenAuth, data, resolve, reject); | ||
})]; | ||
} | ||
}); | ||
@@ -123,12 +131,18 @@ }); | ||
return __generator(this, function (_a) { | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][createObject]"); | ||
data = { | ||
id: id, | ||
file: file, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.CreateObject, data, resolve, reject); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][createObject]"); | ||
data = { | ||
id: id, | ||
file: file, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.CreateObject, data, resolve, reject); | ||
})]; | ||
} | ||
}); | ||
@@ -143,12 +157,18 @@ }); | ||
return __generator(this, function (_a) { | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][uploadDocument]"); | ||
data = { | ||
documentId: documentId, | ||
file: file, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.UploadDocument, data, resolve, reject); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
/* istanbul ignore next */ | ||
this.debug && console.log("[FramedClient][uploadDocument]"); | ||
data = { | ||
documentId: documentId, | ||
file: file, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.UploadDocument, data, resolve, reject); | ||
})]; | ||
} | ||
}); | ||
@@ -163,9 +183,15 @@ }); | ||
return __generator(this, function (_a) { | ||
data = { | ||
fileMetadata: fileMetadata, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetViewStatus, data, resolve, reject); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
data = { | ||
fileMetadata: fileMetadata, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetViewStatus, data, resolve, reject); | ||
})]; | ||
} | ||
}); | ||
@@ -180,10 +206,16 @@ }); | ||
return __generator(this, function (_a) { | ||
data = { | ||
fileMetadata: fileMetadata, | ||
viewLocation: viewLocation, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetView, data, resolve, reject); | ||
})]; | ||
switch (_a.label) { | ||
case 0: | ||
data = { | ||
fileMetadata: fileMetadata, | ||
viewLocation: viewLocation, | ||
chatToken: chatToken || this.chatToken | ||
}; | ||
return [4 /*yield*/, this.loadIframe()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.postMessage(PostMessageEventType_1.default.Request, PostMessageEventName_1.default.GetView, data, resolve, reject); | ||
})]; | ||
} | ||
}); | ||
@@ -227,2 +259,6 @@ }); | ||
}; | ||
if (!this.targetWindow) { | ||
console.error('Target window not found!'); | ||
return; | ||
} | ||
this.targetWindow.postMessage(__assign({ requestId: requestId, | ||
@@ -242,3 +278,6 @@ eventType: eventType, | ||
this.debug && console.log(event); | ||
this.targetWindow = event.source; // Finds target window to post message back | ||
// Finds target window to post message back | ||
if (event.source) { | ||
this.targetWindow = event.source; | ||
} | ||
if (event.data.eventType === PostMessageEventType_1.default.Response) { | ||
@@ -249,20 +288,30 @@ /* istanbul ignore next */ | ||
if (event.data.eventName === PostMessageEventName_1.default.SkypeTokenAuth) { | ||
this.requestCallbacks[data.requestId].resolve(); | ||
delete this.requestCallbacks[data.requestId]; | ||
if (data.requestId in this.requestCallbacks) { | ||
this.requestCallbacks[data.requestId].resolve(); | ||
delete this.requestCallbacks[data.requestId]; | ||
} | ||
} | ||
else if (event.data.eventName === PostMessageEventName_1.default.CreateObject) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
if (data.requestId in this.requestCallbacks) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
} | ||
} | ||
else if (event.data.eventName === PostMessageEventName_1.default.UploadDocument) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
if (data.requestId in this.requestCallbacks) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
} | ||
} | ||
else if (event.data.eventName === PostMessageEventName_1.default.GetViewStatus) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
if (data.requestId in this.requestCallbacks) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
} | ||
} | ||
else if (event.data.eventName === PostMessageEventName_1.default.GetView) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
if (data.requestId in this.requestCallbacks) { | ||
this.requestCallbacks[data.requestId].resolve(data.response); | ||
delete this.requestCallbacks[data.requestId]; | ||
} | ||
} | ||
@@ -277,11 +326,21 @@ else if (event.data.eventName === PostMessageEventName_1.default.SendTelemetry) { | ||
}; | ||
FramedClient.prototype.createIframe = function () { | ||
FramedClient.prototype.dispose = function () { | ||
var _a; | ||
(_a = document.getElementById(this.iframeId)) === null || _a === void 0 ? void 0 : _a.remove(); | ||
this.requestCallbacks = {}; | ||
this.iframeLoaded = false; | ||
}; | ||
FramedClient.prototype.loadIframe = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iframeId; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
iframeId = 'Microsoft_Omnichannel_AMSClient_Iframe_Window'; | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
var iframeElements = Array.from(document.getElementsByTagName('iframe')); | ||
var foundIframeElement = iframeElements.filter(function (iframeElement) { return iframeElement.id == _this.iframeId; }); | ||
// Avoid duplicate load | ||
if (foundIframeElement.length) { | ||
return resolve(); | ||
} | ||
var iframeElement = document.createElement('iframe'); | ||
iframeElement.id = iframeId; | ||
iframeElement.id = _this.iframeId; | ||
iframeElement.src = config_1.baseUrl + "/" + version + "/iframe.html?debug=" + _this.debug + "&telemetry=true"; | ||
@@ -288,0 +347,0 @@ iframeElement.addEventListener('load', function () { |
@@ -117,3 +117,3 @@ "use strict"; | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -132,3 +132,3 @@ Event: PostMessageEventName_1.default.SkypeTokenAuth, | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -161,3 +161,3 @@ Event: PostMessageEventName_1.default.SkypeTokenAuth, | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -191,3 +191,3 @@ Event: PostMessageEventName_1.default.CreateObject, | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -221,3 +221,3 @@ Event: PostMessageEventName_1.default.UploadDocument, | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -251,3 +251,3 @@ Event: PostMessageEventName_1.default.GetViewStatus, | ||
this.sendTelemetry(LogLevel_1.default.ERROR, { | ||
ChatId: data.chatToken.ChatId, | ||
ChatId: data.chatToken.chatId, | ||
AMSClientVersion: config_1.sdkVersion, | ||
@@ -254,0 +254,0 @@ Event: PostMessageEventName_1.default.GetView, |
@@ -9,3 +9,4 @@ interface OmnichannelChatToken { | ||
voiceVideoCallToken?: string; | ||
amsEndpoint?: string; | ||
} | ||
export default OmnichannelChatToken; |
declare enum PostMessageEventName { | ||
IframeLoaded = "IframeLoaded", | ||
SkypeTokenAuth = "SkypeTokenAuth", | ||
CreateObject = "CreateObject", | ||
UploadDocument = "UploadDocument", | ||
GetViewStatus = "GetViewStatus", | ||
GetView = "GetView", | ||
SendTelemetry = "SendTelemetry" | ||
IframeLoaded = "AMSIframeLoaded", | ||
SkypeTokenAuth = "AMSSkypeTokenAuth", | ||
CreateObject = "AMSCreateObject", | ||
UploadDocument = "AMSUploadDocument", | ||
GetViewStatus = "AMSGetViewStatus", | ||
GetView = "AMSGetView", | ||
SendTelemetry = "AMSSendTelemetry" | ||
} | ||
export default PostMessageEventName; |
@@ -5,11 +5,11 @@ "use strict"; | ||
(function (PostMessageEventName) { | ||
PostMessageEventName["IframeLoaded"] = "IframeLoaded"; | ||
PostMessageEventName["SkypeTokenAuth"] = "SkypeTokenAuth"; | ||
PostMessageEventName["CreateObject"] = "CreateObject"; | ||
PostMessageEventName["UploadDocument"] = "UploadDocument"; | ||
PostMessageEventName["GetViewStatus"] = "GetViewStatus"; | ||
PostMessageEventName["GetView"] = "GetView"; | ||
PostMessageEventName["SendTelemetry"] = "SendTelemetry"; | ||
PostMessageEventName["IframeLoaded"] = "AMSIframeLoaded"; | ||
PostMessageEventName["SkypeTokenAuth"] = "AMSSkypeTokenAuth"; | ||
PostMessageEventName["CreateObject"] = "AMSCreateObject"; | ||
PostMessageEventName["UploadDocument"] = "AMSUploadDocument"; | ||
PostMessageEventName["GetViewStatus"] = "AMSGetViewStatus"; | ||
PostMessageEventName["GetView"] = "AMSGetView"; | ||
PostMessageEventName["SendTelemetry"] = "AMSSendTelemetry"; | ||
})(PostMessageEventName || (PostMessageEventName = {})); | ||
exports.default = PostMessageEventName; | ||
//# sourceMappingURL=PostMessageEventName.js.map |
{ | ||
"name": "@microsoft/omnichannel-amsclient", | ||
"version": "0.1.0-main.294e9eb", | ||
"version": "0.1.0-main.32eec41", | ||
"description": "Microsoft Omnichannel AMSClient", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
209082
1629