Home | History | Annotate | Download | only in websocket
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Called by the common.js module.
      6 function attachListeners() {
      7   document.getElementById('connectForm').addEventListener('submit', doConnect);
      8   document.getElementById('sendForm').addEventListener('submit', doSend);
      9   document.getElementById('closeButton').addEventListener('click', doClose);
     10 }
     11 
     12 // Called by the common.js module.
     13 function moduleDidLoad() {
     14   // The module is not hidden by default so we can easily see if the plugin
     15   // failed to load.
     16   common.hideModule();
     17 }
     18 
     19 function doConnect(event) {
     20   // Send a request message. See also websocket.cc for the request format.
     21   var url = document.getElementById('url').value;
     22   common.naclModule.postMessage('o;' + url);
     23   event.preventDefault();
     24 }
     25 
     26 function doSend() {
     27   // Send a request message. See also websocket.cc for the request format.
     28   var message = document.getElementById('message').value;
     29   var type = document.getElementById('is_binary').checked ? 'b;' : 't;';
     30   common.naclModule.postMessage(type + message);
     31   event.preventDefault();
     32 }
     33 
     34 function doClose() {
     35   // Send a request message. See also websocket.cc for the request format.
     36   common.naclModule.postMessage('c;');
     37 }
     38 
     39 function handleMessage(message) {
     40   common.logMessage(message.data);
     41 }
     42