/desktop_extensions/content/mobibar_working.js
JavaScript | 90 lines | 39 code | 5 blank | 46 comment | 0 complexity | fd1be43ee431d6bd67ad0d0a0f93b137 MD5 | raw file
- function MobiBarSearch(event){
- var query = document.getElementById("MobiBarQuery").value;
-
- var server = 'localhost';
- var port = 12345;
- var data = query;
- this.transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].
- getService(Components.interfaces.nsISocketTransportService);
- this.scriptablestream = Components.classes["@mozilla.org/scriptableinputstream;1"].
- createInstance(Components.interfaces.nsIScriptableInputStream);
- this.pump = Components.classes["@mozilla.org/network/input-stream-pump;1"].
- createInstance(Components.interfaces.nsIInputStreamPump);
- this.transport = this.transportService.createTransport(null, 0, server, port, null);
- this.outstream = this.transport.openOutputStream(1, 0, 0);
- this.outputData = query;
- //this is where the connection is actually opens.
- this.outstream.write(this.outputData, this.outputData.length);
- this.outstream.flush();
- this.stream = this.transport.openInputStream(0, 0, 0);
- this.scriptablestream.init(this.stream);
- var dataListener = {
- data: "testdata",
- onStartRequest: function (request, context) {
- //here is the event for connection established
- alert("Started");
- },
- onStopRequest: function (request, context, status) {
- // here is the event if connection lost
- alert("Stop");
- },
- onDataAvailable: function (request, context, inputStream, offset, count) {
- // here is where you recieve input from server
- var response = scriptStream.read(count);
- alert("Data available");
- },
- };
- outstream.write(data, data.length);
- outstream.flush();
- this.pump.init(this.stream, -1, -1, 0, 0, false);
- this.pump.asyncRead(dataListener, null);
-
- //to write to stream
- outstream.write(data, data.length);
- outstream.flush();
- window._content.document.location = encodeURI(query);
-
- }
-
-
- //var serverSocket;
- //serverSocket = io.connect('127.0.0.1:12345');
- //serverSocket.emit('clientMessage', 'Yo server');
- //function getLocalPlaya(whichOne){
- //var filePa = emfile.path+'\\chrome\\content\\players\\'+whichOne;
- //var gunsNRoses = filePa.replace('\\', '\\\\');
- //var bFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
- //bFile.initWithPath(gunsNRoses);
- //var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
- //istream.init(bFile, -1, -1, false);
- //var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
- //bstream.setInputStream(istream);
- //var bytes = bstream.readBytes(bstream.available());
- /*
- var serverSocket;
- var listener =
- {
- onSocketAccepted : function(socket, transport)
- {
- try {
- /*var outputString = 'HTTP/1.1 200 OK\n' +
- 'Content-Length: '+bytes.length+'\r\n'+
- 'Content-Type: application/x-shockwave-flash\r\n' +
- 'content-disposition: attachment; filename="'+whichOne+'"\r\n'+
- 'Accept-Ranges: bytes\r\n'+
- bytes;
- var outputString = query;
- var stream = transport.openOutputStream(0,0,0);
- stream.write(outputString,outputString.length);
- stream.close();
- } catch(ex2){ LOG("::"+ex2); }
- },
- onStopListening : function(socket, status){}
- };
- try {
- serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
- .createInstance(Components.interfaces.nsIServerSocket);
- serverSocket.init(12345,true,-1);
- serverSocket.asyncListen(listener);
- } catch(ex){ }
- */