12. Advanced Topics

Transport Filtering

The AMPS JavaScript client offers the ability to filter incoming and outgoing messages in the format they are sent and received on the network. This allows you to inspect or modify outgoing messages before they are sent to the network, and incoming messages as they arrive from the network. This can be especially useful when using SSL connections, since this gives you a way to monitor outgoing network traffic before it is encrypted, and incoming network traffic after it is decrypted.

To create a transport filter, you create a callable that expects a string that contains the raw data, and a direction parameter indicating whether the string is output or not. For example, the following function simply prints the direction and data:

const printingFilter = (data, outgoing) => {
  if (outgoing) {
    console.log('OUTGOING ---> ', data);
  else {
    console.log('INCOMING ---> ', data.data);

You then register the filter by calling Client.transportFilter() with the function, as shown below.

// client is an AMPS client

Using WebSocket over SSL

The AMPS JavaScript client includes support for Secure Sockets Layer. To use this support in the JavaScript client, you need only use wss for the transport type in the connection string.