js1.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Check for the various File API support.
  2. if (window.File && window.FileReader && window.FileList && window.Blob) {
  3. // Great success! All the File APIs are supported.
  4. } else {
  5. alert('The File APIs are not fully supported in this browser.');
  6. }
  7. helloWorldModule = null; // Global application object.
  8. statusText = 'NO-STATUS';
  9. // Indicate success when the NaCl module has loaded.
  10. function moduleDidLoad() {
  11. helloWorldModule = document.getElementById('udp_example');
  12. updateStatus('moduleDidLoad SUCCESS');
  13. }
  14. // Handle a message coming from the NaCl module.
  15. function handleMessage(message_event)
  16. {
  17. console.log("Got handleMessage");
  18. console.log(message_event.data);
  19. }
  20. // If the page loads before the Native Client module loads, then set the
  21. // status message indicating that the module is still loading. Otherwise,
  22. // do not change the status message.
  23. function pageDidLoad() {
  24. if (helloWorldModule == null) {
  25. updateStatus('LOADING...');
  26. } else {
  27. // It's possible that the Native Client module onload event fired
  28. // before the page's onload event. In this case, the status message
  29. // will reflect 'SUCCESS', but won't be displayed. This call will
  30. // display the current message.
  31. updateStatus();
  32. }
  33. }
  34. // Set the global status message. If the element with id 'statusField'
  35. // exists, then set its HTML to the status message as well.
  36. // opt_message The message test. If this is null or undefined, then
  37. // attempt to set the element with id 'statusField' to the value of
  38. // |statusText|.
  39. function updateStatus(opt_message) {
  40. if (opt_message)
  41. statusText = opt_message;
  42. var statusField = document.getElementById('statusField');
  43. if (statusField) {
  44. statusField.innerHTML = statusText;
  45. }
  46. }
  47. // Indicate success when the NaCl module has loaded.
  48. function clikedConnect() {
  49. helloWorldModule = document.getElementById('udp_example');
  50. if (helloWorldModule == null) {
  51. updateStatus('helloWorldModule == null');
  52. }
  53. else
  54. {
  55. updateStatus('Calling postMessage');
  56. helloWorldModule.postMessage('connect');
  57. }
  58. }
粤ICP备19079148号