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.

784 lines
17 KiB

  1. <HTML>
  2. <HEAD>
  3. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  4. <TITLE>Remote Control Chat Server</TITLE>
  5. </HEAD>
  6. <!--
  7. Test
  8. <BODY id="ChatServerId" onload=TransmitScreenInfo()>
  9. -->
  10. <BODY id="ChatServerId" onload=InitiateRCSession() bgcolor="#4a8ece" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  11. <!--
  12. Title and control panel
  13. -->
  14. <table width="700" border="0" cellspacing="0" cellpadding="2" bgcolor="#4a8ece">
  15. <tr bgcolor="#4a8ece">
  16. <td>
  17. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  18. <tr>
  19. <td width="42%" height="30"><img src="WinRCTitleChat.gif" width="290" height="33"></td>
  20. <td width="9%" valign="middle" height="30">
  21. <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF">
  22. <tr bgcolor="#4a8ece">
  23. <td><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>MODE:</b><br>
  24. <font size="1"> <div id=StatusID> </div></font></font></td>
  25. </tr>
  26. </table>
  27. <font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">
  28. </font></td>
  29. <td width="49%" valign="middle" height="30">
  30. <div align="right">
  31. <input type="button" id=AbortConnection value="Quit Session" onclick=AbortConnection()>
  32. <input type="button" id="FileXferId" value="File Transfer" onclick=LaunchFileXfer(0)>
  33. <!--input type="button" id=HideChat onclick=HideChatBox()-->
  34. &nbsp;&nbsp;&nbsp; </div>
  35. </td>
  36. </tr>
  37. </table>
  38. </td>
  39. </tr>
  40. <tr>
  41. <TABLE>
  42. <TR>
  43. <!--
  44. Incoming chat display area
  45. -->
  46. <TD>
  47. <TEXTAREA wrap="VIRTUAL" cols="85" rows="15" id=incomingChatText name=incomingChatText readOnly multiline="true"></TEXTAREA>
  48. </TD>
  49. </TR>
  50. <TR>
  51. <!--
  52. Chat text box
  53. -->
  54. <TD><TEXTAREA id=chatText name=chatText cols="60" wrap="VIRTUAL" rows="4" onkeypress=OnEnter()></TEXTAREA>&nbsp;&nbsp;&nbsp;
  55. <input type="submit" id=sendChatButton name=sendChatButton onclick=SendChatButtonHandler() value="Submit Message ^">
  56. </TR>
  57. </TABLE>
  58. </tr>
  59. </table>
  60. <SCRIPT Language="JScript">
  61. //
  62. // Salem objects.
  63. //
  64. var vArgs = null;
  65. var g_oSAFRemoteDesktopSession = null;
  66. var g_oSAFRemoteDesktopChannelMgr = null;
  67. var g_oChatChannel = null;
  68. var g_oControlChannel = null;
  69. if(null == parent.oRCSession)
  70. {
  71. //alert("Dialog");
  72. vArgs = window.dialogArguments;
  73. g_oSAFRemoteDesktopSession = vArgs;
  74. }
  75. else
  76. {
  77. //alert("not a dialog");
  78. g_oSAFRemoteDesktopSession = parent.oRCSession;
  79. }
  80. //
  81. // Globals
  82. //
  83. var g_bChatBoxHidden = false;
  84. var g_bNewBinaries = false;
  85. var g_bUserDisconnect = true;
  86. //
  87. // Constants
  88. //
  89. var c_szChatChannelID = "70";
  90. var c_szControlChannelID = "71";
  91. var c_szHomePage = "hcp://system/HomePage.htm";
  92. var c_szRCCommand = "RCCOMMAND";
  93. var c_szRCCommandName = "NAME";
  94. var c_szScreenInfo = "SCREENINFO";
  95. var c_szWidth = "WIDTH";
  96. var c_szHeight = "HEIGHT";
  97. var c_szColorDepth = "COLORDEPTH";
  98. var c_szDisconnectRC = "DISCONNECTRC";
  99. var c_szFileXfer = "FILEXFER";
  100. var c_szFileName = "FILENAME";
  101. var c_szFileSize = "FILESIZE";
  102. var c_szChannelId = "CHANNELID";
  103. var c_szRemoteCtrlStart = "REMOTECTRLSTART";
  104. var c_szRemoteCtrlEnd = "REMOTECTRLEND";
  105. var c_szRCMODE = "REMOTE CONTROL";
  106. var c_szCHATMODE = "CHAT";
  107. //
  108. // Desktop Control Permissions
  109. //
  110. var DESKTOPSHARING_DEFAULT = 0x0000;
  111. var NO_DESKTOP_SHARING = 0x0001;
  112. var VIEWDESKTOP_PERMISSION_REQUIRE = 0x0002;
  113. var VIEWDESKTOP_PERMISSION_NOT_REQUIRE = 0x0004;
  114. var CONTROLDESKTOP_PERMISSION_REQUIRE = 0x0008;
  115. var CONTROLDESKTOP_PERMISSION_NOT_REQUIRE = 0x00010;
  116. //
  117. // Localizable contants
  118. //
  119. var L_cszExpertID = "\n Helper> ";
  120. var L_cszUserID = "\n Helpee> ";
  121. var L_HIDECHAT = "Hide Chat Boxes";
  122. var L_SHOWCHAT = "Show Chat Boxes";
  123. //
  124. // Messages
  125. //
  126. var L_EXPERTDISCONNECT_MSG = "Helper disconnected.";
  127. var L_EXPERTCONNECTED_MSG = "Helper connected.";
  128. var L_ABORTINGCONNECTION_MSG = "Terminating Remote control connection from Helper";
  129. var L_USECHATBOX_MSG = "1. Your Helper will now taken Remote control of your Computer.\n2. Both you and your helper can control your computer at the same time.\n3. You can still use your chat window to communicate with your helper. \n4. However, your helper would need to use your chat window to communicate with you. \n";
  130. //
  131. // Error Messages
  132. //
  133. var L_ERRNULLRCSESSION = "RCSession object is not defined";
  134. //
  135. // InitiateRCSession: Initiates the RC Session
  136. //
  137. function InitiateRCSession()
  138. {
  139. g_bNewBinaries = true;
  140. if(null == g_oSAFRemoteDesktopSession)
  141. {
  142. alert( L_ERRNULLRCSESSION );
  143. }
  144. else
  145. {
  146. var x;
  147. try
  148. {
  149. if (false == g_bNewBinaries)
  150. {
  151. //
  152. // Using Old interface
  153. //
  154. //
  155. // Add the chat channel
  156. //
  157. g_oSAFRemoteDesktopSession.AddChannels( c_szChatChannelID );
  158. //
  159. // Add the control channel
  160. //
  161. g_oSAFRemoteDesktopSession.AddChannels( c_szControlChannelID );
  162. //
  163. // Bind OnChannelDataReady callback
  164. //
  165. g_oSAFRemoteDesktopSession.OnChannelDataReady = function(channelID)
  166. { OnChannelDataReadyEvent(channelID); }
  167. }
  168. else
  169. {
  170. //
  171. // Use new interface
  172. //
  173. //
  174. // Get the Channel Manager
  175. //
  176. //alert("Getting ChannelManager");
  177. g_oSAFRemoteDesktopChannelMgr = g_oSAFRemoteDesktopSession.ChannelManager;
  178. //
  179. // Open the Chat channel
  180. //
  181. //alert("Opening ChatChannel");
  182. g_oChatChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szChatChannelID );
  183. //
  184. // Open the Control Channel
  185. //
  186. //alert("Opening Control Channel");
  187. g_oControlChannel = g_oSAFRemoteDesktopChannelMgr.OpenDataChannel( c_szControlChannelID );
  188. //
  189. // Setup the ChannelDataReady handlers
  190. //
  191. //alert("Binding Events");
  192. g_oChatChannel.OnChannelDataReady = function()
  193. { ChatChannelDataReadyEvent(); }
  194. g_oControlChannel.OnChannelDataReady = function()
  195. { ControlChannelDataReadyEvent(); }
  196. HideChat.value = L_HIDECHAT;
  197. }
  198. }
  199. catch(x)
  200. {
  201. // no big deal ... it just means that the channel was added
  202. // by a previous instance.
  203. }
  204. //
  205. // Setup the OnDisconnected event callback
  206. //
  207. g_oSAFRemoteDesktopSession.OnDisconnected = function()
  208. { OnClientDisconnected(); }
  209. }
  210. try
  211. {
  212. //
  213. // Also, Enable Remote Control
  214. //
  215. //alert("Enabling Remote Control");
  216. EnableRemoteControl();
  217. //
  218. // Transmit screen resolution to Expert, so that
  219. // he has the right screen size to see in the RC Tool
  220. //
  221. //alert("Transmitting screen info");
  222. TransmitScreenInfo();
  223. StatusID.innerText = c_szCHATMODE;
  224. }
  225. catch(error)
  226. {
  227. alert(error);
  228. }
  229. }
  230. //
  231. // TransmitScreenInfo: Sends the user's screen resolution to the expert
  232. //
  233. function TransmitScreenInfo()
  234. {
  235. var Doc = null;
  236. var RCCommand = null;
  237. try
  238. {
  239. //
  240. // Create an XML document
  241. //
  242. Doc = new ActiveXObject("microsoft.XMLDOM");
  243. //
  244. // Create the RCCOMMAND root node
  245. //
  246. RCCommand = Doc.createElement( c_szRCCommand );
  247. //
  248. // Set the NAME attribute to SCREENINFO
  249. //
  250. RCCommand.setAttribute( c_szRCCommandName, c_szScreenInfo );
  251. //
  252. // Set the WIDTH attribute
  253. //
  254. RCCommand.setAttribute( c_szWidth, screen.width );
  255. //
  256. // Set the HEIGHT attribute
  257. //
  258. RCCommand.setAttribute( c_szHeight, screen.height );
  259. //
  260. // Set the COLORDEPTH attribute
  261. //
  262. RCCommand.setAttribute( c_szColorDepth, screen.colorDepth );
  263. //
  264. // Send the XML across
  265. //
  266. if (false == g_bNewBinaries)
  267. {
  268. //
  269. // Using Old interface
  270. //
  271. g_oSAFRemoteDesktopSession.SendChannelData( c_szControlChannelID, RCCommand.xml );
  272. }
  273. else
  274. {
  275. //
  276. // Use new interface
  277. //
  278. g_oControlChannel.SendChannelData( RCCommand.xml );
  279. }
  280. }
  281. catch(error)
  282. {
  283. alert( error );
  284. }
  285. }
  286. //
  287. // EnableRemoteControl: This routine enables remote control
  288. //
  289. function EnableRemoteControl()
  290. {
  291. if(null != g_oSAFRemoteDesktopSession)
  292. {
  293. if (false == g_bNewBinaries)
  294. {
  295. //
  296. // Using Old interface
  297. //
  298. g_oSAFRemoteDesktopSession.EnableRemoteControl( "" );
  299. }
  300. else
  301. {
  302. //
  303. // Use the new interface
  304. //
  305. //alert("remote control permissions: ");
  306. //alert("Existing: " + g_oSAFRemoteDesktopSession.SharingClass);
  307. g_oSAFRemoteDesktopSession.SharingClass = CONTROLDESKTOP_PERMISSION_NOT_REQUIRE;
  308. }
  309. }
  310. }
  311. //
  312. // DisableRemoteControl: Routine to disable Remote Control
  313. //
  314. function DisableRemoteControl()
  315. {
  316. if(null != g_oSAFRemoteDesktopSession)
  317. {
  318. if (false == g_bNewBinaries)
  319. {
  320. //
  321. // Using Old interface
  322. //
  323. g_oSAFRemoteDesktopSession.DisableRemoteControl( "" );
  324. }
  325. else
  326. {
  327. //
  328. // Use the new interface
  329. //
  330. g_oSAFRemoteDesktopSession.RemoteControlPermissions = NO_DESKTOP_SHARING;
  331. }
  332. }
  333. }
  334. //
  335. // AbortConnection: Routine that disconnects the session
  336. //
  337. function AbortConnection()
  338. {
  339. if (false == g_bNewBinaries)
  340. {
  341. //
  342. // Using Old interface
  343. //
  344. if (g_oSAFRemoteDesktopSession != null)
  345. {
  346. g_oSAFRemoteDesktopSession.StopListening();
  347. }
  348. //
  349. // Remove the chat channel
  350. //
  351. g_oSAFRemoteDesktopSession.RemoveChannels( c_szChatChannelID );
  352. //
  353. // Remove the control channel
  354. //
  355. g_oSAFRemoteDesktopSession.RemoveChannels( c_szControlChannelID );
  356. }
  357. else
  358. {
  359. //
  360. // Using New interfaces
  361. //
  362. //
  363. // Disconnect the connection to Helper, if the connection is broken by the Helpee
  364. //
  365. if(true == g_bUserDisconnect)
  366. {
  367. DisconnectRC();
  368. }
  369. }
  370. //
  371. // Close this window
  372. //
  373. //window.close();
  374. //
  375. // Close the session
  376. //
  377. //alert("Closing Session");
  378. try
  379. {
  380. g_oSAFRemoteDesktopSession.CloseRemoteDesktopSession();
  381. }
  382. catch(error)
  383. {
  384. alert(error);
  385. }
  386. parent.navigate( c_szHomePage );
  387. return;
  388. }
  389. //
  390. // SendChatButtonHandler: Routine to send chat data
  391. //
  392. function SendChatButtonHandler()
  393. {
  394. if (g_oSAFRemoteDesktopSession != null)
  395. {
  396. if (StatusID.innerText == c_szCHATMODE)
  397. {
  398. //
  399. // If We are in Chat Mode. Only then send the data across
  400. //
  401. if (false == g_bNewBinaries)
  402. {
  403. //
  404. // Using Old interface
  405. //
  406. //
  407. // Send data on the chat channel
  408. //
  409. g_oSAFRemoteDesktopSession.SendChannelData(c_szChatChannelID, chatText.value);
  410. }
  411. else
  412. {
  413. //
  414. // Use the new interface
  415. //
  416. g_oChatChannel.SendChannelData( chatText.value );
  417. }
  418. //
  419. // Update user's chat history window
  420. //
  421. incomingChatText.value = incomingChatText.value + L_cszUserID + chatText.value;
  422. }
  423. else
  424. {
  425. //
  426. // This is remote control Mode
  427. //
  428. //
  429. // Update user's chat history window
  430. //
  431. incomingChatText.value = incomingChatText.value + "\n> " + chatText.value;
  432. }
  433. //
  434. // Clear up the chat message window
  435. //
  436. chatText.value="";
  437. incomingChatText.doScroll("scrollbarPageDown");
  438. }
  439. }
  440. //
  441. // OnChannelDataReadyEvent: Call back to handle data from expert
  442. //
  443. function OnChannelDataReadyEvent(channelID)
  444. {
  445. var str = null;
  446. if (channelID == c_szChatChannelID)
  447. {
  448. //
  449. // Data on chat channel
  450. //
  451. str = g_oSAFRemoteDesktopSession.ReceiveChannelData(channelID)
  452. //
  453. // Update chat history window with incoming data
  454. //
  455. incomingChatText.value = incomingChatText.value + L_cszExpertID + str;
  456. incomingChatText.doScroll("scrollbarPageDown");
  457. }
  458. else if (channelID == c_szControlChannelID)
  459. {
  460. //
  461. // Incoming data on the control channel
  462. //
  463. }
  464. }
  465. //
  466. // ChatChannelDataReadyEvent: Call back to handle data from expert
  467. //
  468. function ChatChannelDataReadyEvent()
  469. {
  470. var str = null;
  471. //
  472. // Data on chat channel
  473. //
  474. str = g_oChatChannel.ReceiveChannelData();
  475. //
  476. // Update chat history window with incoming data
  477. //
  478. incomingChatText.value = incomingChatText.value + L_cszExpertID + str;
  479. incomingChatText.doScroll("scrollbarPageDown");
  480. return;
  481. }
  482. //
  483. // ControlChannelDataReadyEvent: Call back to handle data from expert
  484. //
  485. function ControlChannelDataReadyEvent()
  486. {
  487. var str = null;
  488. //
  489. // Data on control channel
  490. //
  491. str = g_oControlChannel.ReceiveChannelData();
  492. //
  493. // Parse the data sent on the control channel
  494. //
  495. ParseControlData ( str );
  496. return;
  497. }
  498. //
  499. // ParseControlData: Parse the data sent on the control channel
  500. //
  501. function ParseControlData ( str )
  502. {
  503. var Doc = new ActiveXObject("microsoft.XMLDOM");
  504. var RCCommand = null;
  505. var szCommandName = null;
  506. try
  507. {
  508. if( false == Doc.loadXML( str ))
  509. {
  510. alert ( L_ERRLOADXMLFAIL_MSG );
  511. }
  512. if ( Doc.parseError.reason != "")
  513. {
  514. alert( Doc.parseError.reason);
  515. }
  516. //
  517. // Get the RCCOMMAND node
  518. //
  519. RCCommand = Doc.documentElement;
  520. //
  521. // Get the NAME of the command
  522. //
  523. szCommandName = RCCommand.getAttribute( c_szRCCommandName );
  524. if( szCommandName == c_szFileXfer )
  525. {
  526. //
  527. // File Transfer Initiation
  528. //
  529. var vArgs = new Array(6);
  530. var FileXferWidth = "600";
  531. var FileXferHeight = "500";
  532. vArgs[0] = 1; // Destination Mode
  533. vArgs[1] = g_oControlChannel; // Control Channel
  534. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  535. vArgs[3] = RCCommand.getAttribute( c_szFileName ); // FILENAME
  536. vArgs[4] = RCCommand.getAttribute( c_szFileSize ); // FILESIZE
  537. vArgs[5] = RCCommand.getAttribute( c_szChannelId ); // CHANNELID
  538. window.showModelessDialog("../RCExpert/RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  539. }
  540. else if ( szCommandName == c_szRemoteCtrlStart )
  541. {
  542. //
  543. // Remote Control initiation
  544. //
  545. //
  546. // Change mode display to "Remote control"
  547. //
  548. StatusID.innerText = c_szRCMODE;
  549. incomingChatText.value = L_USECHATBOX_MSG;
  550. FileXferId.disabled = true;
  551. //AbortConnection.disabled = true;
  552. }
  553. else if ( szCommandName == c_szRemoteCtrlEnd )
  554. {
  555. //
  556. // End of Remote Control
  557. //
  558. //
  559. // Change mode display to "chat"
  560. //
  561. StatusID.innerText = c_szCHATMODE;
  562. incomingChatText.value = "";
  563. FileXferId.disabled = false;
  564. //AbortConnection.disabled = false;
  565. }
  566. }
  567. catch(error)
  568. {
  569. alert( error );
  570. }
  571. }
  572. function OnClientConnected() {
  573. StatusID.innerText = c_szCHATMODE;
  574. }
  575. function OnClientDisconnected() {
  576. StatusID.innerText = L_EXPERTDISCONNECT_MSG ;
  577. g_bUserDisconnect = false;
  578. AbortConnection();
  579. }
  580. function OnEnter()
  581. {
  582. if (window.event.keyCode == 13)
  583. {
  584. SendChatButtonHandler();
  585. }
  586. }
  587. //
  588. // HideChatBox: Toggles the chat box controls
  589. //
  590. function HideChatBox()
  591. {
  592. if(false == g_bChatBoxHidden)
  593. {
  594. //
  595. // Chatbox is visible. Hide it
  596. //
  597. chatText.style.visibility = "hidden";
  598. sendChatButton.style.visibility = "hidden";
  599. incomingChatText.style.visibility = "hidden";
  600. g_bChatBoxHidden = true;
  601. HideChat.value = L_SHOWCHAT;
  602. }
  603. else
  604. {
  605. //
  606. // Chatbox is Hidden. Show it
  607. //
  608. chatText.style.visibility = "visible";
  609. sendChatButton.style.visibility = "visible";
  610. incomingChatText.style.visibility = "visible";
  611. g_bChatBoxHidden = false;
  612. HideChat.value = L_HIDECHAT;
  613. }
  614. }
  615. //
  616. // Disconnect: Disconnects the RC Connection made by Expert
  617. //
  618. function DisconnectRC()
  619. {
  620. var Doc = null;
  621. var RCCommand = null;
  622. try
  623. {
  624. //
  625. // Create an XML document
  626. //
  627. Doc = new ActiveXObject("microsoft.XMLDOM");
  628. //
  629. // Create the RCCOMMAND root node
  630. //
  631. RCCommand = Doc.createElement( c_szRCCommand );
  632. //
  633. // Set the NAME attribute to DISCONNECTRC
  634. //
  635. RCCommand.setAttribute( c_szRCCommandName, c_szDisconnectRC );
  636. //
  637. // Send the XML across
  638. //
  639. if (false == g_bNewBinaries)
  640. {
  641. //
  642. // Using Old interface
  643. //
  644. g_oSAFRemoteDesktopSession.SendChannelData( c_szControlChannelID, RCCommand.xml );
  645. }
  646. else
  647. {
  648. //
  649. // Use new interface
  650. //
  651. g_oControlChannel.SendChannelData( RCCommand.xml );
  652. }
  653. }
  654. catch(error)
  655. {
  656. alert( error );
  657. }
  658. }
  659. var g_iChannelId = 1000;
  660. //
  661. // LaunchFileXfer: Launches the File Xfer UI
  662. //
  663. function LaunchFileXfer( mode )
  664. {
  665. var vArgs = new Array(4);
  666. var FileXferWidth = "600";
  667. var FileXferHeight = "500";
  668. if(0 == mode)
  669. {
  670. vArgs[0] = mode; // Source Mode
  671. vArgs[1] = g_oControlChannel; // Control Channel
  672. vArgs[2] = g_oSAFRemoteDesktopChannelMgr; // Channel Manager
  673. vArgs[3] = g_iChannelId++; // Channel ID
  674. window.showModelessDialog("../RCExpert/RCFileXfer.htm", vArgs, "dialogwidth:" + FileXferWidth + "px;dialogHeight:" + FileXferHeight + "px;status:no;resizable:yes");
  675. }
  676. return;
  677. }
  678. </SCRIPT>
  679. </BODY>
  680. </HTML>