A WebSocket client for Whisper messaging server.
Add the following dependency to your pubspec.yaml
whisper_websocket_client_dart:
git:
url: https://github.com/jsfraz/whisper_websocket_client_dart.gitimport 'package:whisper_websocket_client_dart/ws_client.dart';
var wsClient = WsClient('ws://localhost:8080/ws', onReceived: (wsResponse) {
// TODO handle server response
});
await wsClient.connect(accessToken, Duration(seconds: 5));
await Future.delayed(Duration(seconds: 5));
wsClient.disconnect();For more detailed example see test/ws_client_test.dart.
Media files are transferred over HTTP, not over the WebSocket. The file is encrypted locally and uploaded as ciphertext; only a small encrypted reference to it travels inside a normal private message, so the server never learns anything about the media (zero-knowledge). The server stores the file on disk with a TTL and deletes it after the recipient downloads it once (or when the TTL expires).
Sender flow:
- Encrypt the media file locally and upload the ciphertext with
MediaApi.uploadMedia(receiverId, file)fromwhisper_openapi_client_dart, which returns the mediaid. - Build a
MediaReference(id, key, type, size, ...)describing the upload (including the symmetrickeyneeded to decrypt it). - Serialize the reference (
mediaReference.toJson()), encrypt it the same way text messages are encrypted, and send it as thecontentof aNewPrivateMessage.
Recipient flow:
- Decrypt the received message
contentand parse it withMediaReference.fromJson(...). - Download the ciphertext via
MediaApi.downloadMedia(mediaReference.mediaId). - Decrypt it locally using
mediaReference.key. - Only after the file is successfully downloaded, decrypted and persisted, call
MediaApi.confirmMediaDownload(mediaReference.mediaId)to delete it from the server. The download is retriable until confirmed; if the client never confirms, the file is removed once its server-side TTL expires.
- web_socket_channel
- provides WebSocket support for Dart
- lints
- lint rules for Dart code analysis
- test
- testing framework
- dotenv
- environment variables from .env files
- pointycastle
- used for cryptography
- basic_utils
- used for cryptography
- dart_jsonwebtoken
- used for JWT token handling
- whisper_openapi_client_dart
- used for API communication with Whisper server