Basic Usage Examples
Basic Usage Examples
Authorization Setup
Here’s how to set up JWT authorization in your middleware:
const jwtAuth = new JWTAuthorizationControl('Auth', '/auth');
jwtAuth.addEventHandler('SignalMessage', (event) => {
if (event.data.payload.jwt !== 'valid_token') {
event.handled = true;
}
});Custom Routing Strategy
Implement a priority-based routing strategy:
class PriorityRouting extends RoutingStrategy {
async route(event, geometry) {
const nodes = geometry.getNodesSortedByPriority();
for (const node of nodes) {
await node.handleEvent(event);
if (event.handled) break;
}
}
}XAML Integration
Define your middleware structure in XAML:
<TreeGeometry xmlns="http://schemas.matrix.com/middleware">
<JWTAuthorizationControl Name="Auth" Path="/auth">
<MQTTConnector Name="MQTT" Path="/mqtt">
<TerminalComponent Name="Terminal" Path="/terminal" />
</MQTTConnector>
</JWTAuthorizationControl>
</TreeGeometry>Event Handling
Set up event handlers for your components:
const terminal = new TerminalComponent('Terminal', '/terminal');
terminal.addEventHandler('Command', async (event) => {
const { command } = event.data;
const result = await executeCommand(command);
await terminal.sendResponse(result);
});