An axis is defined as a floating-point value in the range of $[-1, 1]$. This can be used to transmit data e.g. from a joystick, a pedal, a trigger and any other devices that has two distinct start- and endpoints. Meaning, the devices has to be bound by an upper and lower limit.
=== "C"
``` c
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
return 0;
}
```
=== "C++"
``` c++
#include <iostream>
int main(void) {
std::cout << "Hello world!" << std::endl;
return 0;
}
```
Use a JSON boolean type to transfer these types of data values.
This interface is defined in [JSON Schema](https://json-schema.org/) as follows:
This example defines a requirement, as in a data receiving port, that expects data of the type [Axis](../interfaces/axis.md).
## Matching Algorithm
Matching is performed either automatically or by a semi-manual process. This can be done on a server-by-server basis and changes by the needs of the developers implementing a server.
If matches are found, the server performs a handshake protocol, announcing to each connected party how they need to send and receive data. Afterwards, the server handles all data traffic between the parties, serving as an intermediary. Because all data travels through the server, it can be captured and later be used to analyze the users performance in the last training session.
To actually transmit the defined data, a websocket [@websocket] server is used, which handles both signal matching as well as serving as a proxy for the websocket connections between connected parties.
By definitions, websockets are only able to communicate with one party at a time (though in both directions). Therefore, to connect two unrelated parties, the server needs to receive all data sent by either party and pass them along to the other party.
By definitions, websockets are only able to communicate with one party at a time (though in both directions). Therefore, to connect two unrelated parties, the server needs to receive all data sent by either party and pass them along to the other parties.
For each party, exactly one Websocket-Connection is opened. All data sent over this Websocket has to satisfy the interface in [@fig:packetinterface].
For each party, exactly one Websocket-Connection is opened. All data sent over this Websocket has to satisfy the following[JSON Schema](https://json-schema.org/).
"description":"Defines what type of port is transmitted",
"enum":["requirement","capability"]
}
},
"required":["meta"]
}
```
This means, that each packet consist of at least a `meta` object. Sending a `data` object is not required (e.g. an administrative packet may not need any data).
The possible `actions` are as follows:
`emit`
: Emit sends the data to all clients that are subscribed to the channel defined in `meta.channel`, excluding the sending client.
`broadcast`
: Broadcast sends the data to all clients that are subscribed to the channel defined in `meta.channel, including the sending client.
`join`
: This action has two functions. When sent from the server to a client, it instructs the client to join the channel defined in `meta.channel`.
If sent from the client, it asks the server to subscribe the client to the channel defined in `meta.channel`. This action will be answered with a packet containing either the `accept` or `reject` action.
`leave`
: This action has two functions. When sent from the server to a client, it instructs the client to leave the channel defined in `meta.channel`.
If sent from the client, it asks the server to deregister the client from the channel defined in `meta.channel`. This action will be answered with a packet containing either the `accept` or `reject` action.
`accept`
: A packet with this action is sent from the server to the client if it was successfully subscribed to the channel defined in `meta.channel`
`reject`
: A packet with this action is sent from the server to the client if the clients request to join the channel defined in `meta.channel` was rejected for any reason. `data` may contain the reason for the rejection, but this is optional and clients may not rely on that information.
### Example
The following `packet` transmits data of type [`Axis`](../interfaces/axis.md) on channel `example-channel`.
Of special note is the `channel` field in the `meta` object. By setting this parameter, a publisher can send data specifically for this channel. All publishers who have announced their interest in that specific channel will then be notified of the new data.