LiveStyler SDK for Flutter(Android, iOS)
This SDK is for applying LiveStyler functionality to Flutter cross-platform applications. The SDK provides functionality to initialize the camera, transmit captured video, and receive and display processed video.
Getting Started
Requirements
- Flutter 3.24.5 or higher
- Android 9.0 or higher
- AGP 8.0 or higher
- Kotlin 1.7.21 or higher
- iOS 12.0 or higher
- Xcode 12.0 or higher
- Swift 5.0 or higher
Key Features
- Control video transformation through signal channels
- Transmit camera video to WebRTC server
- Receive filtered video
Installation
Gradle
// pubspec.yml
dependencies:
livestayler_sdk_flutter:
# Preparing storage.
git: https://github.com/dob-world/LiveStylerSDKFlutter.git
ref: 0.0.1
Then run the following command:
How to Use
Easy Usage
You can use the pre-implemented StreamPage.
// Environment initialization
AppEnv.setEnv(
'{credential}',
'{apiEndpoint}',
'{signalEndpoint}',
'{iceServers}',
'{onTrialStarted}',
'{onTrialEnded}',
'{language}',
);
// Navigate to screen
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return StreamPage();
},
),
);
Custom Development
For additional features not provided in the easy usage and custom UI/UX implementation, it's better to implement directly.
Please refer to the Key Feature Specifications described below for usage instructions.
If you want to change the screen design and functionality, please refer to the stream_page.dart file.
For detailed API specifications, please refer to Flutter Web APIs.
Key Feature Specifications
You can directly create and implement screen functionality using the API.
LiveStylerManager
_liveStylerManager = LiveStylerManager(
credential: '{credential}',
apiEndpoint: '{apiEndpoint}',
signalEndpoint: '{signalEndpoint}',
iceServerList: '{iceServers}',
iceTransportsType: 'Relay',
localRenderer: {localRenderer},
remoteRenderer: {remoteRenderer},
signalStateListener: {signalStateListener},
rendererStateListener: {rendererStateListener},
dataChannelStateListener: {dataChannelStateListener},
onReceiveStatsData: {onReceiveStatsData},
);
credential: Authentication token issued through the admin pageapiEndpoint: API server where service information can be obtainedsignalEndpoint: Signal channel endpoint address for exchanging authentication information with the backendiceServers: Configure STUN and TURN servers; using the provided Google STUN server is recommendediceTransportsType: Specify peer-to-peer connection method using one of All, NoHost, or Relay valueslocalRenderer: Renderer for rendering WebRTC streams (RTCVideoRenderer)remoteRenderer: Renderer for rendering WebRTC remote streams (RTCVideoRenderer)signalStateListener: Handle signal channel eventsrendererStateListener: Handle renderer eventsdataChannelStateListener: Handle data channel eventsonReceiveStatsData: Callback function that receives playback statistics
initialize()
Performs necessary tasks during initialization.
release()
Completely terminates signal server connection and WebRTC connection and returns resources.
updateFilterCategory()
Updates by receiving new filter and category lists from the API server. The filter list is automatically updated when connecting to the signal server. The updated list is delivered through SignalStateListener.
switchCamera(String)
Switches to the received camera ID. Camera ID can be obtained through CameraManager.
camera_id: Camera ID obtained through MediaDevices
changeModel(String)
Changes the filter model to the received model name.
model_name: Model name from FilterCategoryData
AppEnv
The AppEnv class manages application environment settings.
// Environment configuration
AppEnv.setEnv(
'{credential}',
'{apiEndpoint}',
'{signalEndpoint}',
'{iceServers}',
'{onTrialStarted}',
'{onTrialEnded}',
'{onChangeLanguage}',
'{language}',
);
credential: Authentication informationapiEndpoint: API endpoint URLsignalEndpoint: Signaling server endpoint URLiceServers: ICE server configurationonTrialStarted: Trial start callbackonTrialEnded: Trial end callbackonChangeLanguage: Language change callbacklanguage: Initial language setting
Usage Example
void main() async {
// Environment configuration
AppEnv.setEnv(
credential: 'your_credential',
apiEndpoint: 'https://api.example.com',
signalEndpoint: 'wss://signal.example.com',
iceServers: [
{'urls': 'stun:stun.example.com:19302'},
],
language: 'en-US',
);
// LiveStylerManager initialization
final manager = LiveStylerManager(
credential: AppEnv.credential,
apiEndpoint: AppEnv.apiEndpoint,
signalEndpoint: AppEnv.signalEndpoint,
iceServerList: AppEnv.iceServers.map((server) => StunTurnServer.fromJson(server)).toList(),
localRenderer: RTCVideoRenderer(),
remoteRenderer: RTCVideoRenderer(),
signalStateListener: YourSignalStateListener(),
rendererStateListener: YourRendererStateListener(),
dataChannelStateListener: YourDataChannelStateListener(),
onReceiveStatsData: (stats) {
print('Received stats: $stats');
},
);
await manager.initialize();
await manager.start();
// Change style model
await manager.changeModel('romantic');
// Switch camera
await manager.switchCamera('front_camera_id');
// Terminate connection
await manager.stop();
}