srt_dart 1.0.0 copy "srt_dart: ^1.0.0" to clipboard
srt_dart: ^1.0.0 copied to clipboard

Bindings of Secure Reliable Transport (SRT) protocol for Dart.

Welcome to the Secure Reliable Transport wrapper for Dart

SRT is a high-level protocol for streaming data with security and integrity. Primarily made in C/C++, see the Haivision SRT repository.

The current library consumes the raw code and provides a Dart-like interface with sugar on top.

First Steps: #

In a Dart environment #

The libsrt package is required if you want to use the srt_dart with pure Dart. Follow the SRT Build Documentation for more details.

On Flutter apps this step is unnecessary. But, enussure to have the srt_flutter_libs in your pubspec.yaml

For Linux / Brew

  git clone https://github.com/Haivision/srt.git
  cd srt 
  ./configure
  make install

Main pratices #

In the head of project initilize the Srt class. He is the core and need be static on code. And, call the function cleanUp on finalize

After initlized or cleaned, don`t call Srt again

You can crete multiply sockets, such that needed call dispose on fineshed the main propoese of them

On necessary, the Epoll class can manage 100+ sockets

Built on the UDP protocol, the transport is done using a server/client model. Both side can send data ( if sender is defined true ) but one need listen for a connection (server) and other try connect (client).

Configuring the SRT in the Head of project (server/client) #

import 'package:srt_dart/srt_dart.dart';
/// for flutter projects, add 
import 'package:srt_flutter_libs/main.dart';

/// On the head of project
void main(){
  /// in flutter projects, use
  WidgetsFlutterBinding.ensureInitialized();
  initializeSrtFlutter();

  /// in dart projects, use
  Srt();

}

Configure a Server #

import 'dart:io' show InternetAddress;
final serverSocket = SrtSocket(options: SocketOptions.liveMode(sender: false)) /// Create the socket of server
serverSocket.bind(InternetAddress.loopbackIPv4, 9000); /// set the ip (127.0.0.1) and port of the server will listen
serverSocket.listen(backlog: 1); /// listen for clients
final handle = serverSocket.accept(); /// accpet one client, and get one socket to manage this connection 
handle.waitStream(onReceive : (data){
  print(data.lenght);
});

Configure a Client #

import 'dart:io' show InternetAddress;

final address = InternetAddress.loopbackIPv4; // the ip of server
final clientSocket = SrtSocket(options: SocketOptions.liveMode(sender: true)); /// Create the socket of Client
clientSocket.connect(address, 9000); /// try connect in ip (127.0.0.1) and port (9000) of server
final text = "when need send a text, use the menssage api"; /// the data to be send
clientSocket.sendStrem(Uint8List.fromList(text.codeUnits)); /// send the data to server

On end, close the SRT. #

On Flutter apps this step is unnecessary

Srt.cleanUp();

For more examples

  • see the path example/...
  • A real, flutter application at laughing-dollop repository
1
likes
130
points
56
downloads

Publisher

unverified uploader

Weekly Downloads

Bindings of Secure Reliable Transport (SRT) protocol for Dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

ffi, ffigen, path

More

Packages that depend on srt_dart