update credits
[LibreOffice.git] / firefoxos / sdremote / js / client.js
blob77025063ee8b1ea45efcfadccf428bde57a000c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 function Client( aServerAddress ) {
11 var mReceiveBuffer = "";
12 var mCurrentMessage = [];
13 var mSocket;
14 var mReceiver = new Receiver();
16 // PUBLIC
17 this.sendMessage = function( aMessage ) {
18 mSocket.send( aMessage );
21 // PRIVATE
22 function dataReceived( aEvent ) {
23 mReceiveBuffer += aEvent.data;
24 var i;
25 while ( ( i = mReceiveBuffer.indexOf( '\n' ) ) != -1 ) {
26 var aLine = mReceiveBuffer.substring( 0, i );
27 mReceiveBuffer = mReceiveBuffer.substring( i+1 );
28 if ( aLine.length > 0 ) {
29 mCurrentMessage.push( aLine );
30 } else {
31 mReceiver.parseMessage( mCurrentMessage );
32 mCurrentMessage = [];
34 aLine = "";
38 // CONSTRUCTOR
39 if( navigator.mozTCPSocket ) {
40 mSocket = navigator.mozTCPSocket.open( "localhost", 1599 );
41 mSocket.onopen = function( aEvent ) {
42 console.log( "Received onopen" );
43 mSocket.send( "LO_SERVER_CLIENT_PAIR\nFirefox OS\n1234\n\n" );
45 mSocket.onerror = function( aEvent ) {
46 console.log( "Received error: " + aEvent.data );
48 mSocket.ondata = dataReceived;
49 } else {
50 console.log( "Can't access socket." );
54 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */