File: emacspeak.js

package info (click to toggle)
emacspeak 29.0-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 12,904 kB
  • sloc: xml: 55,354; lisp: 48,335; cpp: 2,321; tcl: 1,500; makefile: 936; python: 836; sh: 785; perl: 459; ansic: 241
file content (91 lines) | stat: -rw-r--r-- 2,263 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//$Id:$

/**
 * @file emacspeak.js
 * Holds Emacspeak connection
 */


/**
 * Emacspeak: encapsulate Emacspeak connection
 * @constructor
 * Optional: @param {path} Specifies Emacspeak install root
 * e.g., /usr/share/emacs/site-lisp/emacspeak/
 */

function Emacspeak( basepath) {
  /**
   * @private basepath_ Install location
   */
  this.path_ = (basepath === undefined) ? '/usr/share/emacs/site-lisp/emacspeak/'  : basepath;

  /**
   * @private cmd_ location of server  executable
   */
  this.cmd_ = basepath + 'servers/python/HTTPSpeaker.py';

  /**
   * @private url_
   * URL of our local server
   */
  this.url_ ='http://localhost:2222/';
}


/**
 * Load needed modules and initialize things.
 */

Emacspeak.prototype.init = function() {
  try {
    var js = 'file://localhost' + this.path_ + 'js/';
    repl.load(js + 'di.js');
    repl.load(js + 'adom.js');
    window.addEventListener(
                        "load",
                        function () {
                                     gBrowser.addEventListener('load', repl.updateADom, true);
                                     },
                        false);

    this.say('Emacspeak Enabled Firefox');
  } catch (err) {
    repl.print('Error during init ' + err);
  }
};

/**
 * Launch the server
 */

Emacspeak.prototype.initserver = function() {
  try {
    // See http://developer.mozilla.org/en/docs/Code_snippets:Running_applications
    var exec_file = Components.classes['@mozilla.org/file/local;1'].
    createInstance(Components.interfaces.nsILocalFile);
    this.exec_ = Components.classes['@mozilla.org/process/util;1'].
    createInstance(Components.interfaces.nsIProcess);
    exec_file.initWithPath(this.cmd_);
    this.exec_.init(exec_file);
    this.exec_.run(false, null, 0);
  } catch (err) {
    repl.print(
        'Cannot initialize executable with path=' + this.cmd_ + ' error: ' + err);
  }
};


/**
 * Speak argument.
 @param {string} text to speak.
 * @return void
 */
Emacspeak.prototype.say = function(text) {
  var url = this.url_ + 'say?' +encodeURIComponent(text);
  var xhr  = new XMLHttpRequest();
  xhr.open('GET', url,true);
  // xhr.onreadystatechange = function (data) {repl.print(data);};
  xhr.send(null);
};

repl.print('Loaded emacspeak.js');