SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2017 Wrinkle, Inc.
  2.  
  3.  
  4.  
  5. // Copyright 2011 Google Inc.
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License");
  8. // you may not use this file except in compliance with the License.
  9. // You may obtain a copy of the License at
  10. //
  11. //     http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. // See the License for the specific language governing permissions and
  17. // limitations under the License.
  18.  
  19. var serverURL = '';
  20. var socket;
  21. var sendScroll = true;
  22. var sendScrollTimeout;
  23.  
  24. if (typeof localStorage.wrinkleId == "undefined") {
  25.     localStorage.wrinkleId = new UUID(1).format("std");
  26. }
  27.  
  28. function socketSend(msg) {
  29.   socket.send(JSON.stringify(msg));
  30. }
  31.  
  32.  
  33.  
  34. function sendDims() {
  35. var w=window,
  36.     d=document,
  37.     e=d.documentElement,
  38.     g=d.getElementsByTagName('body')[0],
  39.     x=w.innerWidth||e.clientWidth||g.clientWidth,
  40.     y=w.innerHeight||e.clientHeight||g.clientHeight;
  41.  
  42.  
  43.     socketSend({
  44.       dims: [x, y]
  45.     });
  46. }
  47.  
  48. function sendMM(event) {
  49.       var dot, eventDoc, doc, body, pageX, pageY;
  50.  
  51.       // fix
  52.       if(!event) { event = event || window.event}; // IE-ism
  53.  
  54.       // If pageX/Y aren't available and clientX/Y are,
  55.       // calculate pageX/Y - logic taken from jQuery.
  56.       // (This is to support old IE)
  57.       if (event.pageX == null && event.clientX != null) {
  58.           eventDoc = (event.target && event.target.ownerDocument) || document;
  59.           doc = eventDoc.documentElement;
  60.           body = eventDoc.body;
  61.  
  62.           event.pageX = event.clientX +
  63.             (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
  64.             (doc && doc.clientLeft || body && body.clientLeft || 0);
  65.           event.pageY = event.clientY +
  66.             (doc && doc.scrollTop  || body && body.scrollTop  || 0) -
  67.             (doc && doc.clientTop  || body && body.clientTop  || 0 );
  68.       }
  69.       socketSend({
  70.         mm: [event.pageX, event.pageY]
  71.       });
  72. }
  73. document.onmousemove = sendMM;
  74.     document.onscroll = function(event) {
  75.       socketSend({
  76.         scroll: [window.pageXOffset, window.pageYOffset]
  77.       });
  78.       sendMM(event);
  79.     }
  80.  
  81. function getHTTPObject()
  82. {
  83.     if (window.ActiveXObject)
  84.     {
  85.         return new ActiveXObject("Microsoft.XMLHTTP");
  86.     }
  87.     else
  88.     {
  89.         if (window.XMLHttpRequest)
  90.         {
  91.             return new XMLHttpRequest();
  92.         }
  93.         else
  94.         {
  95.             return null;
  96.         }
  97.     }
  98. }
  99.  
  100. window.addEventListener("beforeunload", function (e) {
  101.     sessionStorage.closedLastTab = '1';
  102. });
  103.  
  104. /* global olark */
  105. function checkIntegrations() {
  106.     var screenshareURL = "https://getwrinkle.com/agent/screen/window/" + localStorage.wrinkleId;
  107.     if (typeof olark !== "undefined") {
  108.         olark('api.chat.updateVisitorStatus', {
  109.             snippet: 'Screenshare URL: ' + screenshareURL
  110.         });
  111.     }
  112. }
  113.  
  114. var cursor_img = null;
  115.  
  116. var createCursor = function() {
  117.     cursor_img = document.createElement("IMG");
  118.     cursor_img.src = "https://getwrinkle.com/cobrowse/img/cursor_agent.png";
  119.     cursor_img.style.position = "absolute";
  120.     cursor_img.style.zIndex = 99999;
  121.     cursor_img.id = "cursor_agent";
  122.     cursor_img.style.pointerEvents = "none";
  123.     document.getElementsByTagName('body')[0].appendChild(cursor_img);
  124.     }
  125.  
  126. var createRipple = function(left, top) {
  127.     left -= 50;
  128.     top -= 50;
  129.     var ripple_img = document.createElement("IMG");
  130.     ripple_img.src = "https://getwrinkle.com/cobrowse/img/ripple.gif";
  131.     ripple_img.style.position = "absolute";
  132.     ripple_img.style.zIndex = 99999;
  133.     ripple_img.style.transition = "all 1s";
  134.     ripple_img.style.height = '100px';
  135.     ripple_img.style.opacity = '0';
  136.     ripple_img.style.left = left + 'px';
  137.     ripple_img.style.top = top + 'px';
  138.     ripple_img.style.pointerEvents = "none";
  139.     ripple_img.id = "wrinkle_ripple";
  140.     document.getElementsByTagName('body')[0].appendChild(ripple_img);
  141.     setTimeout(function() { ripple_img.style.opacity = '1'; }, 100);
  142.     setTimeout(function() { ripple_img.style.opacity = '0'; }, 3000);
  143.     setTimeout(function() { ripple_img.remove(); }, 4100);
  144.     }
  145.    
  146.    
  147. function startMirroring() {
  148.   if (socket)
  149.     return;
  150.    
  151.    
  152.     console.log('Starting mirroring...');
  153.  
  154.     var new_uuid = new UUID(1).format("std");
  155.     var tab_uuid = sessionStorage.tabID && sessionStorage.closedLastTab !== '2' ? sessionStorage.tabID : sessionStorage.tabID = new_uuid;
  156.     sessionStorage.closedLastTab = '2';
  157.  
  158.     serverURL = 'wss://getwrinkle.com:8080/projector/?company='+company+'&sid='+localStorage.wrinkleId+'&tid='+tab_uuid+'&tabTitle=' + document.title;
  159.     checkIntegrations();
  160.   socket = new WebSocket(serverURL);
  161.   var mirrorClient;
  162.  
  163.   socket.onopen = function() {
  164.     socketSend({ base: location.href.match(/^(.*\/)[^\/]*$/)[1] });
  165.     mirrorClient = new TreeMirrorClient(document, {
  166.       initialize: function(rootId, children) {
  167.         socketSend({
  168.           f: 'initialize',
  169.           args: [rootId, children]
  170.         });
  171.        
  172.         sendDims();
  173.       },
  174.  
  175.       applyChanged: function(removed, addedOrMoved, attributes, text) {
  176.         socketSend({
  177.           f: 'applyChanged',
  178.           args: [removed, addedOrMoved, attributes, text]
  179.         });
  180.       }
  181.      
  182.      
  183.     });
  184.    
  185.        
  186.     document.onmousemove = sendMM;
  187.     document.onscroll = function(event) {
  188.         if (sendScroll) {
  189.           socketSend({
  190.             scroll: [window.pageXOffset, window.pageYOffset]
  191.           });
  192.         }
  193.         sendMM(event);
  194.     }
  195.     window.onresize = function(event) {
  196.         sendDims();
  197.         sendMM(event);
  198.     }
  199.   }
  200.  
  201.   function handleMessage(msg) {
  202.     if (msg.agentMM) {
  203.       if (cursor_img !== null) {
  204.         cursor_img.style.left = msg.agentMM[0] + 'px';
  205.         cursor_img.style.top = msg.agentMM[1] + 'px';
  206.       }
  207.     } else if (msg.agentClick) {
  208.       createRipple(msg.agentClick[0], msg.agentClick[1]);
  209.     } else if (msg.agentScroll) {
  210.         sendScroll = false;
  211.       window.scrollTo(msg.agentScroll[0], msg.agentScroll[1]);
  212.       clearTimeout(sendScrollTimeout);
  213.       sendScrollTimeout = setTimeout(function() { sendScroll = true; }, 1000);
  214.     }
  215.   }
  216.  
  217.   socket.onmessage = function(event) {
  218.     var msg = JSON.parse(event.data);
  219.     if (msg instanceof Array) {
  220.       msg.forEach(function(subMessage) {
  221.         handleMessage(JSON.parse(subMessage));
  222.       });
  223.     } else {
  224.       handleMessage(msg);
  225.     }
  226.   }
  227.  
  228.   socket.onclose = function() {
  229.     mirrorClient.disconnect();
  230.     socket = undefined;
  231.   }
  232.  
  233.   createCursor();
  234. }
  235.  
  236. function stopMirroring() {
  237.   if (socket)
  238.     socket.close();
  239.   socket = undefined;
  240. }
  241.  
  242.  
  243. startMirroring();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top