Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1453 lines
28 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. RCScripts.js
  5. Abstract:
  6. Helper End javascript that drives the RCTOOL
  7. Author:
  8. Rajesh Soy 07/00
  9. Revision History:
  10. --*/
  11. var g_oSAFRemoteDesktopClient = null;
  12. var g_oSAFRemoteDesktopChannelMgr = null;
  13. var g_oChatChannel = null;
  14. var g_oControlChannel = null;
  15. var g_bChatBoxHidden = false;
  16. //
  17. // SetupLayers: Initializes the various layers
  18. //
  19. function SetupLayers()
  20. {
  21. ConnectionProgressLayer.style.visibility = "hidden";
  22. RemoteControlLayer.style.visibility = "hidden";
  23. RemoteControlObject.style.visibility = "hidden";
  24. ChatServerLayer.style.visibility = "hidden";
  25. Layer2.style.visibility = "visible";
  26. }
  27. //
  28. // ParseIncident: Basic XML parse to parse the Incident
  29. //
  30. function ParseIncident()
  31. {
  32. var IncidentDoc = new ActiveXObject("microsoft.XMLDOM");
  33. try
  34. {
  35. IncidentDoc.load( g_szIncidentFile );
  36. if ( IncidentDoc.parseError.reason != "")
  37. {
  38. alert( IncidentDoc.parseError.reason);
  39. }
  40. //
  41. // Fetch the Upload data
  42. //
  43. var UploadData = IncidentDoc.documentElement.firstChild;
  44. //
  45. // Fetch the attributes of the upload data
  46. //
  47. var Attributes = UploadData.attributes;
  48. //
  49. // UserName
  50. //
  51. try
  52. {
  53. g_szUserName = Attributes.getNamedItem("USERNAME").nodeValue;
  54. }
  55. catch(error)
  56. {
  57. g_szUserName = "Unknown";
  58. }
  59. //
  60. // ProblemDescription
  61. //
  62. try
  63. {
  64. g_szProblemDescription = Attributes.getNamedItem("PROBLEMDESCRIPTION").nodeValue;
  65. }
  66. catch(error)
  67. {
  68. g_szProblemDescription = "";
  69. }
  70. //
  71. // SALEM ticket
  72. //
  73. try
  74. {
  75. g_szRCTicketEncrypted = Attributes.getNamedItem("SalemID").nodeValue;
  76. }
  77. catch(error)
  78. {
  79. g_szRCTicketEncrypted = null;
  80. }
  81. }
  82. catch(error)
  83. {
  84. alert("Failed to load: " + g_szIncidentFile + " Error: " + error);
  85. }
  86. }
  87. //
  88. // ValidateIncident: Validates the incident information loaded from XML
  89. //
  90. function ValidateIncident()
  91. {
  92. var bRetVal = true;
  93. if("" == g_oCurrentIncident.UserName)
  94. {
  95. alert( L_ERRLOADINGUSERNAME_MSG );
  96. bRetVal = false;
  97. }
  98. if("" == g_oCurrentIncident.RCTicket)
  99. {
  100. alert( L_ERRLOADINGRCTICKET_MSG );
  101. bRetVal = false;
  102. }
  103. return bRetVal;
  104. }
  105. //
  106. // InitializeRCTool: Stuff done when the RCTool page is loaded in the helpctr
  107. //
  108. function InitializeRCTool()
  109. {
  110. ConnectionProgressLayer.style.visibility = "hidden";
  111. RemoteControlLayer.style.visibility = "hidden";
  112. ChatServerLayer.style.visibility = "hidden";
  113. Layer2.style.visibility = "visible";
  114. try
  115. {
  116. //alert("CreateObject_Incident");
  117. //
  118. // Create an instance of the SAF Incident Object
  119. //
  120. g_oCurrentIncident = oSAFClassFactory.CreateObject_Incident();
  121. //
  122. // Create an instance of the SAF Encryption Object
  123. //
  124. g_oEncryption = oSAFClassFactory.CreateObject_Encryption();
  125. }
  126. catch(error)
  127. {
  128. alert(error);
  129. //
  130. // Todo: Handle Error
  131. //
  132. }
  133. //
  134. // Parse the document URL to Get the location of the Incident file
  135. //
  136. //
  137. // Location the position of "?"
  138. //
  139. var i = document.URL.indexOf("?", 1);
  140. if (i > 0)
  141. {
  142. //
  143. // Go past "?"
  144. //
  145. var g_szIncidentFileURL = document.URL.slice(i+2);
  146. //
  147. // Go past "IncidentFile="
  148. //
  149. var j = g_szIncidentFileURL.indexOf("=", 1);
  150. //
  151. // Split g_szIncidentFileURL to obtain the path to incident XML blob
  152. //
  153. g_szIncidentFile = g_szIncidentFileURL.slice(j+1);
  154. }
  155. else
  156. {
  157. alert ("Unable to locate Incident File");
  158. //
  159. // Todo: Add code to handle this error here
  160. //
  161. }
  162. //
  163. // Populate the incident object from the XML
  164. // representation of the incident (call LoadXML)
  165. //
  166. try
  167. {
  168. //
  169. // Load the incident from the XML blob
  170. //
  171. g_oCurrentIncident.LoadFromXMLFile( g_szIncidentFile );
  172. //
  173. // Validate the information loaded
  174. //
  175. if( false == ValidateIncident())
  176. {
  177. alert(L_ERRLOADINGINCIDENT_MSG);
  178. //
  179. // If incident loaded from XML is invalid
  180. // Use my XML parser to load the incident data
  181. //
  182. ParseIncident();
  183. }
  184. else
  185. {
  186. //
  187. // Incident loaded from XML blob is valid
  188. //
  189. //
  190. // Get the UserName of the person requesting support
  191. //
  192. g_szUserName = g_oCurrentIncident.UserName;
  193. //
  194. // Get the Description of the problem
  195. //
  196. g_szProblemDescription = g_oCurrentIncident.ProblemDescription;
  197. //
  198. // Get the RC Ticket
  199. //
  200. g_szRCTicketEncrypted = g_oCurrentIncident.RCTicket;
  201. //
  202. // Get the Misc Items
  203. //
  204. g_oDict = g_oCurrentIncident.Misc;
  205. //
  206. // Get the Expiry time. ToDo: Get the accurate Math
  207. //
  208. var DtStart = g_oDict.Item("DtStart");
  209. var DtLength = g_oDict.Item("DtLength");
  210. //alert( "DtStart: " + DtStart );
  211. //alert( "DtLength: " + DtLength);
  212. var ms = DtStart*1000 + DtLength*60*1000;
  213. //alert (ms );
  214. var ExpiryDate = new Date ( ms );
  215. g_szExpiryTime = g_oDict.Item("DtLength") + " minutes ( " + ExpiryDate.toLocaleString() + " )";
  216. g_szHelpeeIP = g_oDict.Item("IP");
  217. //alert("Expiry " + g_szExpiryTime);
  218. //alert("IP " + g_szHelpeeIP);
  219. }
  220. }
  221. catch(error)
  222. {
  223. alert( L_UNABLETOLOAD_MSG + "\n" + error );
  224. //
  225. // Use my XML parser to load the incident data
  226. //
  227. ParseIncident();
  228. }
  229. //
  230. // Set the UI elements to be displayed from the data
  231. // contained in the incident object
  232. //
  233. window.InviteSent.innerHTML = "<div class=\"styText\">" + g_szUserName + "</div>";
  234. window.InviteExpires.innerHTML = "<div class=\"styText\">"
  235. + g_szExpiryTime +
  236. "</div>";
  237. //
  238. // Check to see if we need to ask for password
  239. //
  240. if(true == g_oCurrentIncident.RCTicketEncrypted)
  241. {
  242. //
  243. // RCTicket is encrypted. We need to ask for the password
  244. //
  245. PasswordTbl.disabled = false;
  246. //alert("Encrypted RCTicket: " + g_szRCTicketEncrypted);
  247. }
  248. else
  249. {
  250. //
  251. // RCTicket is not encrypted. Dont need to ask for the password
  252. //
  253. PasswordTbl.disabled = true;
  254. g_szRCTicket = g_szRCTicketEncrypted;
  255. }
  256. return;
  257. }
  258. //
  259. // DecryptRCTicket: Calls into the SAF Encryption/Decryption API to decrypt
  260. // RCTicket
  261. //
  262. function DecryptRCTicket()
  263. {
  264. try
  265. {
  266. if(false == g_bPasswordSet)
  267. {
  268. //
  269. // Get the password
  270. //
  271. g_szPassword = PasswordBox.value;
  272. //
  273. // Use g_szPassword to decrypt the g_szRCTicketEncrypted.
  274. //
  275. g_szRCTicket = g_oEncryption.DecryptString( g_szPassword, g_szRCTicketEncrypted );
  276. //alert("Decrypted RCTicket: " + g_szRCTicket);
  277. //
  278. // Password has been set
  279. //
  280. g_bPasswordSet = true;
  281. }
  282. }
  283. catch(error)
  284. {
  285. alert( L_ERRPWD_MSG );
  286. PasswordBox.value = "";
  287. }
  288. return g_bPasswordSet;
  289. }
  290. //
  291. // PasswordSet: Use password as key to decrypt RCTicket on data entry.
  292. //
  293. function PasswordSet()
  294. {
  295. if (window.event.keyCode == 13)
  296. {
  297. //
  298. // Decrypt the RCTicket
  299. //
  300. DecryptRCTicket();
  301. }
  302. return;
  303. }
  304. //
  305. // Display_Screen2: Launches the actual RCTool
  306. //
  307. function Display_Screen2()
  308. {
  309. //
  310. // Check if Password needs to be set
  311. //
  312. if(true == g_oCurrentIncident.RCTicketEncrypted)
  313. {
  314. //
  315. // Decrypt RCTicket
  316. //
  317. if(false == DecryptRCTicket())
  318. {
  319. //
  320. // Invalid password. Re-enter
  321. //
  322. return;
  323. }
  324. }
  325. //
  326. // Go To HC Home Page
  327. //
  328. navigate(c_szHomePage);
  329. var vArgs = new Array(2);
  330. vArgs[0] = g_szRCTicket; // Remote Control Ticket
  331. vArgs[1] = g_szUserName; // UserName of Helpee
  332. //
  333. // Launch the actual RCTool in a seperate window
  334. //
  335. window.showModalDialog("RCToolScreen2.htm", vArgs, "dialogwidth:" + Screen2Width + "px;dialogHeight:" + Screen2Height + "px;status:no;resizable:yes");
  336. }
  337. //
  338. // InitScreen2: Initializes Screen 2
  339. //
  340. function InitScreen2()
  341. {
  342. //
  343. // Hide all the divs, except the one that displays connection status
  344. //
  345. RemoteControlLayer.style.visibility = "hidden";
  346. RemoteControlObject.style.visibility = "visible";
  347. ChatServerLayer.style.visibility = "hidden";
  348. ConnectionProgressLayer.style.visibility = "visible";
  349. Layer2.style.visibility = "hidden";
  350. ConnectStarted = 0;
  351. g_bConnected = true;
  352. //
  353. // Decrypt RCTicket if necessary
  354. //
  355. if(true == g_oCurrentIncident.RCTicketEncrypted)
  356. {
  357. DecryptRCTicket();
  358. }
  359. //
  360. // Check if the RemoteClientDesktopHost object is loaded
  361. // if loaded, connected
  362. //
  363. checkLoadx();
  364. return;
  365. }
  366. //
  367. // This checks to see if the Remote desktop client host object is loaded. if not wait 3 sec and try again
  368. //
  369. function checkLoadx()
  370. {
  371. //
  372. // Check if DesktopClientHost object loaded
  373. //
  374. if(L_COMPLETE != RemoteDesktopClientHost.readyState)
  375. {
  376. //
  377. // Not loaded yet
  378. //
  379. setTimeout('checkLoadx()', 3000);
  380. }
  381. else
  382. {
  383. //alert("L_COMPLETE == RemoteDesktopClientHost.readyState");
  384. //
  385. // Object loaded: Make a connection to the helpee's machine using SALEM API
  386. //
  387. setTimeout('RCConnect()', 1); // BUGBUG: THIS IS GROSS
  388. }
  389. }
  390. //
  391. // RCConnect connects to the user's terminal
  392. //
  393. function RCConnect()
  394. {
  395. //alert("RCTicket: " + g_szRCTicket);
  396. //..alert("UserName: " + g_szUserName);
  397. ConnectionProgressLayer.style.visibility = "visible";
  398. RemoteControlObject.style.visibility = "hidden";
  399. if(null != RemoteDesktopClientHost)
  400. {
  401. g_bNewBinaries = true;
  402. try
  403. {
  404. //
  405. // set screen up for the connect anouncement screen size.
  406. //
  407. //..setupFirstScreen();
  408. Enunciator.innerText = L_ConnectTo;
  409. HelpeeName.innerText = g_szUserName;
  410. FirstProgressBox.bgColor="#F5F5F5";
  411. //alert("Obtaining g_oSAFRemoteDesktopClient " + RemoteDesktopClientHost.readyState);
  412. //
  413. // Obtain the RDSClient object
  414. //
  415. g_oSAFRemoteDesktopClient = RemoteDesktopClientHost.GetRemoteDesktopClient();
  416. if(null != g_oSAFRemoteDesktopClient)
  417. {
  418. //
  419. // Bind the event handlers for this object.
  420. //
  421. g_oSAFRemoteDesktopClient.OnConnected = function()
  422. { ConnectedHandler(); }
  423. g_oSAFRemoteDesktopClient.OnDisconnected = function(reason)
  424. { DisconnectedHandler(reason); }
  425. if (false == g_bNewBinaries)
  426. {
  427. //
  428. // Using the Old SALEM interfaces
  429. //
  430. g_oSAFRemoteDesktopClient.OnChannelDataReady = function(channelID)
  431. { ChannelDataReadyHandler(channelID); }
  432. g_oSAFRemoteDesktopClient.ConnectToServer(g_szRCTicket);
  433. }
  434. else
  435. {
  436. //
  437. // Using the NEW Salem interfaces
  438. //
  439. //g_oSAFRemoteDesktopClient.OnRemoteControlRequestComplete = function(status)
  440. // { RemoteControlRequestCompleteHandler( status ); }
  441. //alert("RCTicket: " + g_szRCTicket);
  442. g_oSAFRemoteDesktopClient.ConnectParms = g_szRCTicket;
  443. //alert("Calling ConnectToServer");
  444. g_oSAFRemoteDesktopClient.ConnectToServer();
  445. }
  446. //
  447. // ToDo: Handle connection failure conditions
  448. //
  449. }
  450. else
  451. {
  452. alert( L_ERRRDSCLIENT_MSG );
  453. }
  454. }
  455. catch(error)
  456. {
  457. alert( L_ERRCONNECT_MSG + "\n" + error );
  458. }
  459. }
  460. else
  461. {
  462. alert( L_ERRRDSCLIENTHOST_MSG );
  463. }
  464. return;
  465. }
  466. //
  467. // RemoteControlRequestCompleteHandler: Fired when Remote Control request completes
  468. //
  469. function RemoteControlRequestCompleteHandler( status )
  470. {
  471. alert("RCStatus: " + status);
  472. }
  473. //
  474. // HideChatBox: Toggles the chat box controls
  475. //
  476. function HideChatBox()
  477. {
  478. if(false == g_bChatBoxHidden)
  479. {
  480. //
  481. // Chatbox is visible. Hide it
  482. //
  483. //HideChatBoxId.value = L_SHOWCHAT;
  484. sendChatButton.style.visibility="hidden";
  485. chatText.style.visibility="hidden";
  486. incomingChatText.style.visibility="hidden";
  487. g_bChatBoxHidden = true;
  488. }
  489. else
  490. {
  491. //
  492. // Chatbox is Hidden. Show it
  493. //
  494. sendChatButton.style.visibility="visible";
  495. chatText.style.visibility="visible";
  496. incomingChatText.style.visibility="visible";
  497. g_bChatBoxHidden = false;
  498. //HideChatBoxId.value = L_HIDECHAT;
  499. }
  500. }
  501. //
  502. // ToggleConnection: Toggles between Quit Session and Connect
  503. //
  504. function ToggleConnection()
  505. {
  506. if(false == g_bConnected)
  507. {
  508. //
  509. // Establish Connection
  510. //
  511. RCConnect();
  512. g_bConnected = true;
  513. //...ConnectionId.innerText = L_QUITSESSION;
  514. }
  515. else
  516. {
  517. //
  518. // Disconnect
  519. //
  520. RCDisconnect();
  521. g_bConnected = false;
  522. //..ConnectionId.innerText = L_CONNECT;
  523. }
  524. return;
  525. }
  526. //
  527. // ResetHelpee: Routine to reset Helpee after RC
  528. //
  529. function ResetHelpee()
  530. {
  531. var Doc = null;
  532. var RCCommand = null;
  533. //
  534. // Create an XML document
  535. //
  536. Doc = new ActiveXObject("microsoft.XMLDOM");
  537. //
  538. // Create the RCCOMMAND root node
  539. //
  540. RCCommand = Doc.createElement( c_szRCCommand );
  541. //
  542. // Set the NAME attribute to REMOTECTRLEND
  543. //
  544. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteCtrlEnd );
  545. //
  546. // Send control message to other end to signal Remote control end
  547. //
  548. //
  549. // Wait for SALEM to allow data transfer on channels
  550. //
  551. //alert( L_RCSUCCESS_MSG );
  552. g_oControlChannel.SendChannelData( RCCommand.xml );
  553. return;
  554. }
  555. //
  556. // Routine to enable Remote Control
  557. //
  558. function ControlRemotePCHandler()
  559. {
  560. var Doc = null;
  561. var RCCommand = null;
  562. try
  563. {
  564. if(null != g_oSAFRemoteDesktopClient)
  565. {
  566. //alert("null != g_oSAFRemoteDesktopClient");
  567. //
  568. // If RemoteControl is not ON already, Enable it
  569. //
  570. if( false == g_bRCEnabled )
  571. {
  572. //
  573. // Disable chat controls on the screen
  574. incomingChatText.disabled=true;
  575. chatText.disabled=true;
  576. sendChatButton.disabled=true;
  577. SendFile.disabled=true;
  578. TakeControl.innerText = "Release";
  579. //
  580. //
  581. // Create an XML document
  582. //
  583. Doc = new ActiveXObject("microsoft.XMLDOM");
  584. //
  585. // Create the RCCOMMAND root node
  586. //
  587. RCCommand = Doc.createElement( c_szRCCommand );
  588. //
  589. // Set the NAME attribute to REMOTECTRLSTART
  590. //
  591. RCCommand.setAttribute( c_szRCCommandName, c_szRemoteCtrlStart );
  592. //
  593. // Send control message to other end to signal Remote control start
  594. //
  595. g_oControlChannel.SendChannelData( RCCommand.xml );
  596. //
  597. // ToDo: We should wait for an ack from the helpee here
  598. //
  599. //XXX = g_oControlChannel.IsRemoteControlEnabled(abc);
  600. //
  601. // Resize the helper's screen using the helpee's screen
  602. // resolution obtained during connection handshake
  603. //
  604. /*
  605. if (UserWidth <= window.screen.availWidth)
  606. {
  607. window.dialogWidth = " " + (parseInt(UserWidth) + 20) + "px";
  608. window.dialogHeight = " " + (parseInt(UserHeight)+145) + "px";
  609. window.group1.style.width = " " + (parseInt(UserWidth)) + "px";
  610. window.screen2.style.width = " " + (parseInt(UserWidth)) + "px";
  611. window.RemoteDesktopClientHost.style.width = " " + (parseInt(UserWidth)) + "px";
  612. window.RemoteDesktopClientHost.style.height = " " + (parseInt(UserHeight)) + "px";
  613. }
  614. else
  615. {
  616. window.dialogWidth = window.screen.availWidth;
  617. window.dialogHeight = " " + parseInt(window.screen.availHeight) + "px";
  618. window.group1.style.width = " " + (parseInt(window.screen.availWidth) - 20) + "px";
  619. window.screen2.style.width = " " + (parseInt(window.screen.availWidth) - 20) + "px";
  620. window.RemoteDesktopClientHost.style.width = " " + (parseInt(UserWidth)) + "px";
  621. window.RemoteDesktopClientHost.style.height = " " + (parseInt(UserHeight)) + "px";
  622. }
  623. */
  624. //
  625. // Enable Remote Control
  626. //
  627. g_oSAFRemoteDesktopClient.ConnectRemoteDesktop();
  628. //
  629. // Hide the Chat Boxes control button
  630. //
  631. //HideChatBox();
  632. //HideChatBoxId.style.visibility = "hidden";
  633. //
  634. // Hide the File XFer button
  635. //
  636. //FileXferId.disabled = true;
  637. //
  638. // Change Mode
  639. //
  640. //..StatusId.innerText = c_szRCMODE;
  641. g_bRCEnabled = true;
  642. //ControlRemotePC.value = L_ENDRC;
  643. }
  644. else
  645. {
  646. //
  647. // enable chat controls on the screen
  648. //
  649. incomingChatText.disabled=false;
  650. chatText.disabled=false;
  651. sendChatButton.disabled=false;
  652. TakeControl.innerText = "Take Control";
  653. SendFile.disabled=false;
  654. //
  655. // Disable Remote Control
  656. //
  657. g_oSAFRemoteDesktopClient.DisConnectRemoteDesktop();
  658. /*
  659. //
  660. // put screen size of 730 by 500 here
  661. //
  662. if (640 >= window.screen.availWidth)
  663. {
  664. window.group1.style.width = "640px";
  665. window.screen2.style.width = "640px";
  666. window.dialogWidth = "640px";
  667. window.dialogHeight = "480px";
  668. }
  669. else
  670. {
  671. window.group1.style.width = " 730px";
  672. window.screen2.style.width = " 730px";
  673. window.dialogWidth = " 730px";
  674. window.dialogHeight = "500px";
  675. }
  676. */
  677. g_bRCEnabled = false;
  678. //..ControlRemotePC.value = L_STARTRC;
  679. setTimeout("ResetHelpee()", 1000); // BUGBUG: Another gross timing issue
  680. //
  681. // Change Mode
  682. //
  683. }
  684. }
  685. else
  686. {
  687. //alert("null == g_oSAFRemoteDesktopClient");
  688. }
  689. }
  690. catch(error)
  691. {
  692. alert( L_ERRRCTOGGLEFAILED_MSG );
  693. }
  694. }
  695. //
  696. // Routine to disable Remote Control
  697. //
  698. function CloseConnectionHandler()
  699. {
  700. if(null != g_oSAFRemoteDesktopClient)
  701. {
  702. g_oSAFRemoteDesktopClient.DisConnectRemoteDesktop();
  703. }
  704. }
  705. //
  706. // ConnectedHandler: Triggered on connection establishment
  707. //
  708. function ConnectedHandler()
  709. {
  710. var x;
  711. //..StatusId.innerText = L_WAITFORHELPEE_MSG;
  712. Enunciator.innerText = L_WAITFORHELPEE_MSG + g_szUserName;
  713. SecondProgressBox.bgColor="#F5F5F5";
  714. try {
  715. if (false == g_bNewBinaries)
  716. {
  717. //
  718. // Using Old interface
  719. //
  720. //
  721. // Add the chat channel
  722. //
  723. g_oSAFRemoteDesktopClient.AddChannels(c_szChatChannelID);
  724. //
  725. // Add the control channel
  726. //
  727. g_oSAFRemoteDesktopClient.AddChannels( c_szControlChannelID );
  728. }
  729. else
  730. {
  731. //
  732. // Use new interface
  733. //
  734. //
  735. // Get the Channel Manager
  736. //
  737. //alert("Getting ChannelManager");
  738. g_oSAFRemoteDesktopChannelMgr = g_oSAFRemoteDesktopClient.ChannelManager;
  739. //
  740. // Open the Chat channel
  741. //
  742. //alert("Opening channels");
  743. g_oChatChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szChatChannelID );
  744. //
  745. // Open the Control Channel
  746. //
  747. g_oControlChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szControlChannelID );
  748. //
  749. // Setup the ChannelDataReady handlers
  750. //
  751. g_oChatChannel.OnChannelDataReady = function()
  752. { ChatChannelDataReadyHandler(); }
  753. g_oControlChannel.OnChannelDataReady = function()
  754. { ControlChannelDataReadyHandler(); }
  755. }
  756. }
  757. catch(x)
  758. {
  759. //
  760. // Todo: Add handler here
  761. //
  762. }
  763. }
  764. //
  765. // SendChatData sends chat data to remote machine
  766. //
  767. function SendChatData()
  768. {
  769. if (g_oSAFRemoteDesktopClient != null)
  770. {
  771. if (false == g_bNewBinaries)
  772. {
  773. //
  774. // Send chat data to user (using Old interfaces)
  775. //
  776. g_oSAFRemoteDesktopClient.SendChannelData(c_szChatChannelID, chatText.value);
  777. }
  778. else
  779. {
  780. //
  781. // Send chat data to user (using New interfaces)
  782. //
  783. g_oChatChannel.SendChannelData( chatText.value );
  784. }
  785. //
  786. // Update chat history window
  787. //
  788. incomingChatText.value = incomingChatText.value + L_cszExpertID + chatText.value;
  789. //
  790. // Clear chat msg window
  791. //
  792. chatText.value="";
  793. //
  794. // Scroll down
  795. //
  796. incomingChatText.doScroll("scrollbarPageDown");
  797. }
  798. }
  799. //
  800. // RCDisconnect: Disconnects remote connection
  801. //
  802. function RCDisconnect()
  803. {
  804. if (g_oSAFRemoteDesktopClient != null)
  805. {
  806. if (false == g_bNewBinaries)
  807. {
  808. //
  809. // Using the old interface
  810. //
  811. //
  812. // Remove the chat channel
  813. //
  814. g_oSAFRemoteDesktopClient.RemoveChannels( c_szChatChannelID );
  815. //
  816. // Remove the control channel
  817. //
  818. g_oSAFRemoteDesktopClient.RemoveChannels( c_szControlChannelID );
  819. }
  820. if(false == g_bUserDisconnect)
  821. {
  822. //
  823. // Disconnect from Server (only if helper initiated)
  824. //
  825. g_oSAFRemoteDesktopClient.DisconnectFromServer();
  826. }
  827. navigate( c_szHomePage );
  828. //alert( L_DISCONNECTED_MSG );
  829. }
  830. }
  831. //
  832. // DisconnectedHandler: Fired when Session disconnected
  833. //
  834. function DisconnectedHandler(reason)
  835. {
  836. //
  837. // Close down RC Connection
  838. //
  839. RCDisconnect();
  840. }
  841. //
  842. // ParseControlData: Parse the data sent on the control channel
  843. //
  844. function ParseControlData ( str )
  845. {
  846. var Doc = new ActiveXObject("microsoft.XMLDOM");
  847. var RCCommand = null;
  848. var szCommandName = null;
  849. try
  850. {
  851. if( false == Doc.loadXML( str ))
  852. {
  853. alert ( L_ERRLOADXMLFAIL_MSG );
  854. }
  855. if ( Doc.parseError.reason != "")
  856. {
  857. alert( Doc.parseError.reason);
  858. }
  859. //
  860. // Get the RCCOMMAND node
  861. //
  862. RCCommand = Doc.documentElement;
  863. //
  864. // Get the NAME of the command
  865. //
  866. szCommandName = RCCommand.getAttribute( c_szRCCommandName );
  867. if( szCommandName == c_szScreenInfo )
  868. {
  869. //
  870. // SCREENINFO: Contains width/height/colordepth of user's machine
  871. //
  872. UserWidth = RCCommand.getAttribute( c_szWidth );
  873. UserHeight = RCCommand.getAttribute( c_szHeight );
  874. UserColorDepth = RCCommand.getAttribute( c_szColorDepth );
  875. //
  876. // put screen size of 730 by 500 here
  877. //
  878. /*
  879. if (640 >= window.screen.availWidth)
  880. {
  881. window.group1.style.width = "610px";
  882. window.screen2.style.width = "610px";
  883. window.dialogWidth = "640px";
  884. window.dialogHeight = "480px";
  885. }
  886. else
  887. {
  888. window.group1.style.width = "700px";
  889. window.screen2.style.width = "700px";
  890. window.dialogWidth = " 730px";
  891. window.dialogHeight = "500px";
  892. }
  893. BUGBUG: Need to fix this. This does not work since we are no longer a dialog.
  894. */
  895. Enunciator.innerText = L_ConnectionSuccess;
  896. ThirdProgressBox.bgColor="#F5F5F5";
  897. ConnectionProgressLayer.style.visibility = "hidden";
  898. RemoteControlLayer.style.visibility = "visible";
  899. RemoteControlObject.style.visibility = "visible";
  900. ChatServerLayer.style.visibility = "visible";
  901. //
  902. // enable chat controls on the screen
  903. incomingChatText.disabled=false;
  904. chatText.disabled=false;
  905. sendChatButton.disabled=false;
  906. TakeControl.innerText = "Take Control";
  907. SendFile.disabled=false;
  908. //
  909. // Initialization
  910. //
  911. headerHelpeeName.innerHTML="<font face=\"Tahoma, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#ffffff\"><b><font color=\"#ffffff\" face=\"Tahoma, Arial, Helvetica, sans-serif\">&nbsp;&nbsp;&nbsp;" + g_szUserName + "</font></b></font>";
  912. g_bNewBinaries = true;
  913. }
  914. else if( szCommandName == c_szDisconnectRC )
  915. {
  916. //
  917. // DISCONNECTRC: Disconnect the connection
  918. //
  919. g_bUserDisconnect = true;
  920. RCDisconnect();
  921. }
  922. else if( szCommandName == c_szFileXfer )
  923. {
  924. //
  925. // File Transfer Initiation
  926. //
  927. var vArgs = new Array(6);
  928. var FileXferWidth = "600";
  929. var FileXferHeight = "500";
  930. vArgs[0] = 1; // Destination Mode
  931. vArgs[1] = g_oControlChannel; // Control Channel
  932. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  933. vArgs[3] = RCCommand.getAttribute( c_szFileName ); // FILENAME
  934. vArgs[4] = RCCommand.getAttribute( c_szFileSize ); // FILESIZE
  935. vArgs[5] = RCCommand.getAttribute( c_szChannelId ); // CHANNELID
  936. //alert("launching RCFileXfer.htm");
  937. window.showModelessDialog("RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  938. }
  939. }
  940. catch(error)
  941. {
  942. alert( error );
  943. }
  944. }
  945. //
  946. // ChannelDataReadyHandler: Fired when there is data available on any channel
  947. //
  948. function ChannelDataReadyHandler(channelID)
  949. {
  950. var str = null;
  951. if (channelID == c_szChatChannelID)
  952. {
  953. if (false == g_bNewBinaries)
  954. {
  955. //
  956. // Using the old interface
  957. //
  958. //
  959. // Incoming data on the chat channel
  960. //
  961. str = g_oSAFRemoteDesktopClient.ReceiveChannelData(channelID);
  962. }
  963. else
  964. {
  965. //
  966. // Using the new interface
  967. //
  968. str = g_oChatChannel.ReceiveChannelData();
  969. }
  970. //
  971. // Update chat history window
  972. //
  973. incomingChatText.value = incomingChatText.value + L_cszUserID + str;
  974. incomingChatText.doScroll("scrollbarPageDown");
  975. }
  976. else if (channelID == c_szControlChannelID)
  977. {
  978. //
  979. // Incoming data on the control channel. Data on this
  980. // channel will be in XML.
  981. // This channel will be used to support the following:
  982. // 1. Server side (user end) disconnect
  983. // 2. File transfer
  984. //
  985. if (false == g_bNewBinaries)
  986. {
  987. //
  988. // Using the old interface
  989. //
  990. str = g_oSAFRemoteDesktopClient.ReceiveChannelData(channelID);
  991. }
  992. else
  993. {
  994. //
  995. // Using the new interface
  996. //
  997. str = g_oControlChannel.ReceiveChannelData();
  998. }
  999. //
  1000. // Parse the data sent on the control channel
  1001. //
  1002. ParseControlData ( str );
  1003. }
  1004. return;
  1005. }
  1006. //
  1007. // ChatChannelDataReadyHandler: Fired when there is data available on Chat channel
  1008. //
  1009. function ChatChannelDataReadyHandler()
  1010. {
  1011. var str = null;
  1012. //
  1013. // Incoming data on the chat channel
  1014. //
  1015. str = g_oChatChannel.ReceiveChannelData();
  1016. //
  1017. // Update chat history window
  1018. //
  1019. incomingChatText.value = incomingChatText.value + L_cszUserID + str;
  1020. incomingChatText.doScroll("scrollbarPageDown");
  1021. return;
  1022. }
  1023. //
  1024. // ControlChannelDataReadyHandler: Fired when there is data available on Control channel
  1025. //
  1026. function ControlChannelDataReadyHandler()
  1027. {
  1028. var str = null;
  1029. //
  1030. // Incoming data on the control channel. Data on this
  1031. // channel will be in XML.
  1032. // This channel will be used to support the following:
  1033. // 1. Server side (user end) disconnect
  1034. // 2. File transfer
  1035. //
  1036. str = g_oControlChannel.ReceiveChannelData();
  1037. //
  1038. // Parse the data sent on the control channel
  1039. //
  1040. ParseControlData ( str );
  1041. return;
  1042. }
  1043. //
  1044. // OnEnter: This is fired when Expert hits <ENTER> in the chat message window
  1045. //
  1046. function OnEnter()
  1047. {
  1048. if (window.event.keyCode == 13)
  1049. {
  1050. //
  1051. // Send chat data to user
  1052. //
  1053. SendChatData();
  1054. }
  1055. }
  1056. var g_iChannelId = 1000;
  1057. //
  1058. // LaunchFileXfer: Launches the File Xfer UI
  1059. //
  1060. function LaunchFileXfer( mode )
  1061. {
  1062. var vArgs = new Array(4);
  1063. var FileXferWidth = "400";
  1064. var FileXferHeight = "140";
  1065. vArgs[0] = mode; // Source Mode
  1066. vArgs[1] = g_oControlChannel; // Control Channel
  1067. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  1068. vArgs[3] = g_iChannelId++;
  1069. window.showModelessDialog("RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  1070. return;
  1071. }
  1072. function InitiateRCSessionxxx()
  1073. {
  1074. //
  1075. // Initialization
  1076. //
  1077. idtogglechat.innerHTML = "<div class=styText> Hide Chat <img src=\"hide-chat.gif\"> </div>";
  1078. g_bNewBinaries = true;
  1079. //
  1080. // To Do: File the Helper's name
  1081. //
  1082. //..idHelperName.innerText = "( Place Holder )";
  1083. idStatus.innerHTML = "<div class=styText> <IMG src=\"net.gif\"> <STRONG>Status</STRONG> :Connected </div>";
  1084. return;
  1085. if(null == g_oSAFRemoteDesktopSession)
  1086. {
  1087. alert( L_ERRNULLRCSESSION );
  1088. }
  1089. else
  1090. {
  1091. var x;
  1092. try
  1093. {
  1094. if (false == g_bNewBinaries)
  1095. {
  1096. //
  1097. // Using Old interface
  1098. //
  1099. //
  1100. // Add the chat channel
  1101. //
  1102. g_oSAFRemoteDesktopSession.AddChannels( c_szChatChannelID );
  1103. //
  1104. // Add the control channel
  1105. //
  1106. g_oSAFRemoteDesktopSession.AddChannels( c_szControlChannelID );
  1107. //
  1108. // Bind OnChannelDataReady callback
  1109. //
  1110. g_oSAFRemoteDesktopSession.OnChannelDataReady = function(channelID)
  1111. { OnChannelDataReadyEvent(channelID); }
  1112. }
  1113. else
  1114. {
  1115. //
  1116. // Use new interface
  1117. //
  1118. //
  1119. // Get the Channel Manager
  1120. //
  1121. //alert("Getting ChannelManager");
  1122. g_oSAFRemoteDesktopChannelMgr = g_oSAFRemoteDesktopSession.ChannelManager;
  1123. //
  1124. // Open the Chat channel
  1125. //
  1126. //alert("Opening ChatChannel");
  1127. g_oChatChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szChatChannelID );
  1128. //
  1129. // Open the Control Channel
  1130. //
  1131. //alert("Opening Control Channel");
  1132. g_oControlChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szControlChannelID );
  1133. //
  1134. // Setup the ChannelDataReady handlers
  1135. //
  1136. g_oChatChannel.OnChannelDataReady = function()
  1137. { ChatChannelDataReadyEvent(); }
  1138. g_oControlChannel.OnChannelDataReady = function()
  1139. { ControlChannelDataReadyEvent(); }
  1140. HideChat.value = L_HIDECHAT;
  1141. }
  1142. }
  1143. catch(x)
  1144. {
  1145. // no big deal ... it just means that the channel was added
  1146. // by a previous instance.
  1147. }
  1148. //
  1149. // Setup the OnDisconnected event callback
  1150. //
  1151. g_oSAFRemoteDesktopSession.OnDisconnected = function()
  1152. { OnClientDisconnected(); }
  1153. }
  1154. try
  1155. {
  1156. //
  1157. // Also, Enable Remote Control
  1158. //
  1159. EnableRemoteControl();
  1160. //
  1161. // Transmit screen resolution to Expert, so that
  1162. // he has the right screen size to see in the RC Tool
  1163. //
  1164. TransmitScreenInfo();
  1165. //..StatusID.innerText = c_szCHATMODE;
  1166. }
  1167. catch(error)
  1168. {
  1169. alert(error);
  1170. }
  1171. }
  1172. function TakeControlMethod()
  1173. {
  1174. ControlRemotePCHandler();
  1175. }
  1176. function SendFileMethod()
  1177. {
  1178. LaunchFileXfer(0);
  1179. }
  1180. function QuitMethod()
  1181. {
  1182. RCDisconnect();
  1183. }
  1184. function HelpMethod()
  1185. {
  1186. }