FastX Events

FastX 3 uses an event based system to communicate from the client web page, to the protocol page which is located in an iframe  FastX integrators wishing to fine-tune their user experience can add event listeners to these window message events to emit actions when the message occurs.

Server to Client Messages

These messages originate from the server and are propagated to the client.  To listen for events, add a window.addEventListener to your script. For example

<script>
   window.addEventListener("message", function myEvent (evt) {
       if(evt.data.msg == "connected") {
         console.log ("Connected!", evt.data.body);
       }
       // ... other custom code here 
   });
</script>

‘error’

The session disconnected with an error

{
   "msg": "error",
   "body": "Error Message"
}

‘disconnect’

The session disconnected normally

{
   "msg": "disconnect",
   "body": "Disconnect Message"
}

‘security.password’

The session requires a password to continue establishing a connection.  The client should send a “security.password” response message

{
   "msg": "security.password",
   "body": {}
}

‘security.none’

The session does not require any security protocol to continue.  The client should send a “security.none” response message

{
"msg": "security.none",
"body": {}
}

‘settings.update’

The server sent a settings update message. The settings update can have one or more of the following settings.

{
   "msg": "settings.update",
   "body": {
      "1": {  // keyboard
        layout: 0x00000004,
        type: 0x00000001 
      }, 
      "2": {  // geometry
         width: 1024,
         height:768,
       }, 
      "3": { // network autodetect
         enabled: true
       },  
      "4": { // compression
        min: 0,
        max: 7,
        current: 0,
      },  
      "5": { // frame rate
         min: 1,
        max: 60,
        current: 60
       },  
      "6": {  // frame window
          min: 1,
          max: 60,
          current: 2
       }, 
   }
}

Client to Server Messages

These messages are used to communicate with the server.  To send a message.  Add a postMessage to the iframe

<script>
   iframe.contentWindow.postMessage ({
     msg: "settings.networkAutodetect",
     body: {
        "enabled": false
     }
   });
</script>

 ‘connect’

The initiate the session connection. Note this should be only sent once.

{
   "msg": "connect",
   "body": {
      id: "session id",
      options: {
         identity: "string that the server will see as the connection name",
         debug: "send" | "receive" | 1 
      }
      
    }
}

‘security.password’

Respond to a ‘security.password’ request from the server.  Note this should be only sent once.

{
   "msg": "security.password",
   "body": {
       username: "username",
       password: "password-string-from-a-connect-command"
    }
}

‘security.none’

Respond to a ‘security.none’ request from the server.  Note this should be only sent once.

{
"msg": "security.none",
"body": {
     username: "username"
 }
}

‘settings.geometry’

Change the width and height of the session

{
   "msg": "settings.geometry",
   "body":   {
      width: 1024,
      height:768
    }
}

‘settings.keyboard’

Change the keyboard layout and type of the session

{
   "msg": "settings.keyboard",
   "body": {
       layout: 0x00000004,
        type: 0x00000001 
    }
}

‘settings.networkAutodetect’

Enable/disable automatic adjustments of network settings

{
   "msg": "settings.networkAutodetect",
   "body": {
        enabled: true
    }
}

‘settings.compression’

Change the compression level of the image data

{
   "msg": "settings.compression",
   "body": {
       min: 0,
       max: 7,
       current: 1
    }
}

‘settings.frameRate’

Change the maximum frames per second to be sent from the server

{
   "msg": "settings.frameRate",
   "body": {
       min: 1,
       max: 60,
       current: 30
    }
}

‘settings.frameWindow’

Change the maximum frames sent by the server that have not yet been acknowledged by the client

{
   "msg": "settings.frameWindow",
   "body": {
       min: 1,
       max: 60,
       current: 30
    }
}

‘mouse.down’

Send a mouse down event to the server

Possbile mouse flags are:
LEFT = 0x01,
MIDDLE = 0x04,
RIGHT = 0x02,
BACK = 0x08,
FORWARD = 0x10

{
   "msg": "mouse.down",
   "body": {
      flags: LEFT | MIDDLE | RIGHT | BACK | FORWARD,  //Mouse buttons that were down at the time of the event
      pos: [0, 0] //position of the mouse when the down event occurred
    }
}

‘mouse.up’

Send a mouse up  event to the server

{
   "msg": "mouse.up",
   "body": {
      flags:  LEFT | MIDDLE | RIGHT | BACK | FORWARD,  //Mouse buttons that were down at the time of the. see mouse.down
      pos: [0, 0] //position of the mouse when the down event occurred
    }
}

‘mouse.move’

Send a mouse move event to the server

{
   "msg": "mouse.move",
   "body":  {
      pos: [0, 0] //position of the mouse when the down event occurred
    }
}

‘mouse.wheel’

Send a mouse wheel event to the server

{
   "msg": "mouse.wheel",
   "body": {
      delta: 120, //mouse wheel delta.  Negative numbers reverse the wheel
      pos: [0, 0] //position of the mouse when the down event occurred
    }
}