From b8aa5709a0d796b48f68480e9ab16cd59b88783c Mon Sep 17 00:00:00 2001 From: Mirhossein Mousavi Date: Mon, 13 May 2024 14:23:19 +0200 Subject: [PATCH 1/3] Send follower link to the backend instead of using signaler scripts --- main.js | 152 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 57 deletions(-) diff --git a/main.js b/main.js index 99e165f..dcd54b7 100644 --- a/main.js +++ b/main.js @@ -1,49 +1,54 @@ /** - * Surfly NIC integration - * - * Make sure the following variables are initialized based on your configuration before importing this script - * showLiveChatButton - * showVideoChatButton - * scaleDroneChannelId - * nicHomeURL - * nicBusNumber - * nicChatPOC - * clusterNiC - * videoSignalerURL - * chatSignalerURL - * surflySettings - * surflyWidgetKey - * surflyModalTitle - * surflyModalBody - * - * Example in HTML pages: - * - * - * - * ... - * - * - * ... - * - * - * ... - * ​ - * + Surfly NIC integration + + Make sure the following variables are initialized based on your configuration before importing this script + + - showLiveChatButton + - showVideoChatButton + - scaleDroneChannelId + + - surflySettings + - surflyWidgetKey + - surflyModalTitle + - surflyModalBody + + - nicChatPOC + - clusterNiC + - nicBusNumber + - nicHomeURL + + # If your BU is not configured for the new signaling flow, you should provide the following variables + - videoSignalerURL + - chatSignalerURL + + Example in HTML pages: + + + + ... + + + ... + + + ... + + */ var nicHomeURL = nicHomeURL || "https://home-" + clusterNiC + ".nice-incontact.com"; @@ -168,17 +173,25 @@ function createSurflySession(contactId, inviteType) { var surflyMetadata = { "name": "Customer" }; + if (inviteType == 'cobrowse') { var regularSession = Surfly.session({ block_until_agent_joins: false }); regularSession.on("session_started", function(session, event) { - var surflySessionPin = session.pin; - var surflyFollowerLink = session.followerLink; - signalContact(contactId, surflyFollowerLink, surflySessionPin, 'cobrowse'); + if(!window.chatSignalerURL) { + sendFollowerLink( + session.followerLink, + inviteType, + localStorage.getItem(nicBusNumber + "-uniquePageId"), + scaleDroneChannelId + ); + } else { + signalContact(contactId, session.follower_link, session.pin, inviteType); + } var chatDiv = document.getElementById("chat-div-wrap"); chatDiv.style.zIndex = "2147483549"; - console.log('Session Pin: ' + surflySessionPin); + console.log('Session Pin: ' + session.pin); console.log('Contact ID: ' + contactId); }).on("session_ended", function(session, event) { console.log("Regular session ended, updating Studio"); @@ -192,12 +205,19 @@ function createSurflySession(contactId, inviteType) { videochat_start_fullscreen: true }); regularSession.on("session_started", function(session, event) { - var surflySessionPin = session.pin; - var surflyFollowerLink = session.followerLink; - signalContact(contactId, surflyFollowerLink, surflySessionPin, 'videochat'); + if(!window.chatSignalerURL) { + sendFollowerLink( + session.followerLink, + inviteType, + localStorage.getItem(nicBusNumber + "-uniquePageId"), + scaleDroneChannelId + ); + } else { + signalContact(contactId, session.follower_link, session.pin, inviteType); + } var chatDiv = document.getElementById("chat-div-wrap"); chatDiv.style.zIndex = "2147483549"; - console.log('Session Pin: ' + surflySessionPin); + console.log('Session Pin: ' + session.pin); console.log('Contact ID: ' + contactId); }).on("session_ended", function(session, event) { console.log("Regular session ended, updating Studio"); @@ -207,6 +227,24 @@ function createSurflySession(contactId, inviteType) { } } +function sendFollowerLink(followerLink, type, uniquePageId, channelId) { + fetch( + "https://nic.surf.ly/follower_link", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + channel_id: channelId, + room: type, + unique_page_id: uniquePageId, + follower_link: followerLink, + }), + } + ); +} + function loadSurfly() { var settings = { @@ -257,8 +295,8 @@ function loadSurfly() { } = message; if (data.type == 'ElevateToCobrowse' && data.bu == nicBusNumber && data.uniquePageId == localStorage.getItem(nicBusNumber + "-uniquePageId")) { - createSurflySession(data.contactId, 'cobrowse'); - + const inviteType = 'cobrowse'; + createSurflySession(data.contactId, inviteType); console.log('Co-browsing session requested'); console.log("Message ID: " + id); console.log("Timestamp: " + timestamp); @@ -294,7 +332,7 @@ function loadSurfly() { } = message; if (data.type == 'ElevateToVideo' && data.bu == nicBusNumber && data.uniquePageId == localStorage.getItem(nicBusNumber + "-uniquePageId")) { - createSurflySession(data.contactId, 'videochat'); + createSurflySession(data.contactId, inviteType); console.log('Videochat session requested'); console.log("Message ID: " + id); @@ -341,4 +379,4 @@ function initializeChatNiC() { }); console.log('Initializing NiC'); -} \ No newline at end of file +} From aa311fc7f6bb776827753e76cae1273a40f81eaa Mon Sep 17 00:00:00 2001 From: Mirhossein Mousavi Date: Mon, 27 May 2024 10:35:48 +0200 Subject: [PATCH 2/3] Remove mention of legacy approach in docstring --- main.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.js b/main.js index dcd54b7..7bf6a3a 100644 --- a/main.js +++ b/main.js @@ -17,10 +17,6 @@ - nicBusNumber - nicHomeURL - # If your BU is not configured for the new signaling flow, you should provide the following variables - - videoSignalerURL - - chatSignalerURL - Example in HTML pages: From 881f72d7e500270acf504390da2051421d0003a2 Mon Sep 17 00:00:00 2001 From: mirhossein Date: Tue, 11 Jun 2024 11:03:16 +0000 Subject: [PATCH 3/3] wip --- main.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 7bf6a3a..b68eb0c 100644 --- a/main.js +++ b/main.js @@ -225,7 +225,7 @@ function createSurflySession(contactId, inviteType) { function sendFollowerLink(followerLink, type, uniquePageId, channelId) { fetch( - "https://nic.surf.ly/follower_link", + "https://admin-api-backend-ef6aeff35287.herokuapp.com/follower_link", { method: "POST", headers: { @@ -376,3 +376,18 @@ function initializeChatNiC() { console.log('Initializing NiC'); } + +var observer = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + console.log("mutation", mutation); + mutation.addedNodes.forEach(function (node) { + console.log("node added 2", node); + }); + mutation.removedNodes.forEach(function (node) { + console.log("node removed 2", node); + }); + + }); +}); +var chat_messenger_frame = document.getElementById("icChat"); +observer.observe(document, { childList: true, subtree: true, attributes: true, characterData: true });