MTE Relay Client for Flutter (SPM)
Introduction​
This Flutter plugin provides the Eclypses MteRelay Mobile Client for iOS and Android. It enables secure, encrypted HTTP(S) communication between your Flutter app and your backend via an MteRelay server. You must have licensed access to an MteRelay server instance. More Info
Purpose of MteRelay:
- Securely relay HTTP requests to your server
- Protect sensitive headers and data with MTE encryption
- Stream large files efficiently
This guide provides a quick-start for experienced developers. For detailed examples, troubleshooting, and in-depth explanations, see the complete documentation on GitHub.
Prerequisites​
- Flutter SDK (stable channel)
- iOS 14.0+ / Android SDK
- Xcode 14.0+ (for iOS Swift Package Manager support)
- Access to a licensed MteRelay server instance
Installation​
Add to your pubspec.yaml:
dependencies:
mte_relay_client_plugin:
git:
url: https://github.com/Eclypses/mte-relay-client-flutter.git
ref: 4.2.11
Run flutter pub get.
iOS Setup (Swift Package Manager)​
The plugin uses Swift Package Manager (SPM) to manage the iOS MteRelay dependency. The dependency is automatically resolved from the plugin's Package.swift file.
Ensure your iOS deployment target is set to 14.0 or higher:
- Open
ios/Runner.xcworkspacein Xcode - Select the Runner project → Runner target → General tab
- Set "Minimum Deployments" to iOS 14.0 or higher
No additional manual configuration is required for SPM.
Android Setup​
No additional configuration required.
Setup​
Import and initialize the plugin:
import 'package:mte_relay_client_plugin/mte_relay_client_plugin.dart';
import 'package:mte_relay_client_plugin/mte_relay_response_model.dart';
class YourClass {
final _relay = MteRelayClientPlugin();
Future<void> init() async {
// Set up callbacks
_relay.relayResponseStream.listen((message) {
// Handle relay messages
});
_relay.relayStreamResponseStream.listen((args) {
// Handle file stream responses
bool success = args['success'];
int statusCode = args['statusCode'];
Uint8List? data = args['data'];
});
// Initialize relay
await _relay.initializeRelay();
}
}
Usage​
Standard HTTP Request​
final args = {
'url': 'https://your-relay-server.com',
'route': '/api/endpoint', // Encrypted
'method': 'POST',
'headers': {'Content-Type': 'application/json'},
'headersToEncrypt': ['Content-Type'],
'pathnamePrefix': null, // Optional unencrypted prefix
'body': jsonEncode({'key': 'value'}),
};
Map response = await _relay.relayDataTask(args);
final result = Result.fromMap(response);
if (result.isSuccess) {
final json = result.bodyAsJsonObject;
}
Streamed File Upload​
// Set up chunk streaming callback
_relay.relayRequestChunksStream.listen((streamID) async {
final fileStream = file.openRead();
await for (final chunk in fileStream) {
await _relay.sendChunk({'streamID': streamID, 'data': Uint8List.fromList(chunk)});
}
await _relay.closeStream({'streamID': streamID});
});
// Progress callback
_relay.relayStreamCompletionStream.listen((progress) {
double percent = double.parse(progress);
});
// Start upload
final args = {
'url': relayServerUrl,
'route': '/api/upload',
'method': 'POST',
'headers': {'Content-Type': 'multipart/form-data; boundary=...', 'Content-Length': '...'},
'headersToEncrypt': ['Content-Type'],
};
await _relay.relayUploadFile(args);
Streamed File Download​
final args = {
'url': relayServerUrl,
'route': '/api/download/filename.pdf',
'method': 'GET',
'headers': {'Content-Type': 'application/json'},
'headersToEncrypt': ['Content-Type'],
'downloadLocation': '/path/to/save/file.pdf',
};
await _relay.relayDownloadFile(args);
// Response via relayStreamResponseStream
Re-pair with Server​
await _relay.rePair({'url': relayServerUrl, 'pathnamePrefix': null});
Adjust Relay Settings​
await _relay.adjustRelaySettings({
'url': relayServerUrl,
'pathnamePrefix': null,
'streamChunkSize': 1024 * 1024, // 1MB
'pairPoolSize': 3,
'persistPairs': false,
});
Logging​
await _relay.enableFileLogging({'url': relayServerUrl, 'isEnabled': true});
String logs = await _relay.readLogFile({'url': relayServerUrl});
await _relay.clearLogFile({'url': relayServerUrl});
API Reference​
See the source code and inline documentation for full API details. Key classes:
MteRelayClientPlugin: Main entry point for secure requests and file streamingResult<T>: Response wrapper with typed dataNativeHttpResponse: Response wrapper with rawUint8Listbody
Support​
Email: info@eclypses.com
Web: www.eclypses.com
Additional Resources​
- GitHub Repository – Source code and comprehensive examples
- Release Notes – Latest updates and changes
- CocoaPods Version – Alternative plugin using CocoaPods
All trademarks of Eclypses Inc. may not be used without Eclypses Inc.'s prior written consent.