Sariska Media provides powerful Dart API's for developing real-time applications.
You can integrate audio/video, live streaming cloud recording, transcriptions, language translation, virtual background and many other services on the fly.
This API documentation describes all possible features supported by sariska-media-transport which possibly covers any of your use cases.
WebSockets are ideal to keep a single, persistent session. Unlike HTTPS, WebSocket requests are updated almost immediately. To start using the media services, the primary step is to create a Media WebSocket connection.
let token = {your-token}let connection =newSariskaMediaTransport.JitsiConnection(token, "roomName", isNightly);// set isNightly true for latest updates on the features else build will point to stable versionconnection.addEventListener("CONNECTION_ESTABLISHED", () {});connection.addEventListener("CONNECTION_FAILED", (error){if ( PASSWORD_REQUIRED=== err ) {// token is expired connection.setToken(token) // set a new token }});connection.addEventListener("CONNECTION_DISCONNECTED", () {});connection.connect()
Once you have your connection established, the next step is to create a conference. Sariska is backed by the Jitsi architecture.
let conference = connection.initJitsiConference();conference.addEventListener("CONFERENCE_JOINED", () {for (JitsiLocalTrack track in localtracks) { conference.addTrack(track); }});conference.addEventListener("TRACK_ADDED", (track) {JitsiRemoteTrack remoteTrack = track;for (JitsiLocalTrack track in localtracks){if (track.getStreamURL() == remoteTrack.getStreamURL()){return; } }if (remoteTrack.getType() =="audio") {return; } streamURL = remoteTrack.getStreamURL();replaceChild(remoteTrack);});conference.addEventListener("TRACK_REMOVED", (track){// Do cater to track removal});conference.join();
Now, the conference object will have all events and methods that you would possibly need for any feature that you wish to supplement your application with.
A MediaStream consists of zero or more MediaStreamTrack objects, representing various audio or video tracks.
Each MediaStreamTrack may have one or more channels. The channel represents the smallest unit of a media stream, such as an audio signal associated with a given speaker, like left or right in a stereo audio track. Here we mostly talk about track.
Map<String, dynamic> options = {};options["audio"] =true;options["video"] =true;options["resolution"] =240; // 180, 240, 360, vga, 480, qhd, 540, hd, 720, fullhd, 1080, 4k, 2160SariskaMediaTransport.createLocalTracks(options,(tracks) { localTracks = tracks;});//default value for framerates are already configured, You don't set all options.
let videoTrack = localTracks[1];@overrideWidgetbuild(BuildContext context) {returnContainer( child:Stack( children: [Align( alignment:Alignment.topLeft, child:WebRTCView(videoTrack.getStreamURL()) ) ] ) );}//mirror = true or false,//zOrder = 0, 1, 2//objectFit = "cover" or "contain"
This will be your most basic conference call. However, we recommend following up with the two further steps to add customized features to enhance your experience.
Note: You don't any audio element to play sound as it is in conjunction with video the stream.
Sariska-media-transport comes with pre-configured top events used to help improvise your product and overall consumer experience.
Few popular events:
User left
User joined
Conference duration
Camera duration
Audio track duration
Video track duration
Recording started
Recording stopped
Transcription started
Transcription stopped
Local Recording started
Local Recording stopped
Speaker Stats
We will be updating the list of features soon.
// you can start tracking events just by listening conference.addEventListener("ANALYTICS_EVENT_RECEIVED", (payload){// payload will have // payload["name"] of event is string // payload["action"] is string// payload["actionSubject"] is string// payload["source"] is string// payload["attributes"] , JSON of all extra attributed of the event})
You can easily detect the active or the dominant speaker. You could choose to stream only their video, thereby saving on the costs and better resolution to others. This is could be a use case for one-way streaming; such as virtual concerts.
conference.addEventListener("DOMINANT_SPEAKER_CHANGED", (id){// let id = as String; dominant speaker id});
The idea is that we select a subset of N participants, whose video to show, and we stop the video from others. We dynamically and automatically adjust the set of participants that we show according to who speaks – effectively we only show video for the last N people to have spoken.
// to listen for last n speakers changed eventconference.addEventListener("LAST_N_ENDPOINTS_CHANGED", (leavingEndpointIds, enteringEndpointIds){// let leavingEndpointIds = leavingEndpointIds as List<String>; //Array of ID's of users leaving lastN// let enteringEndpointIds = as enteringEndpointIds as List<String>; //Array of ID's of users entering lastN});// to set set last n speakers in mid or you can pass option during conference initializationconference.setLastN(10)
// to set local participant property conference.setLocalParticipantProperty(key, value);// name is a string // value can be object string or object// to remove local participant property conference.rempveLocalParticipantProperty(key)// to get local participant propety conference.getLocalParticipantProperty(key)// this notifies everyone in the conference with following PARTICIPANT_PROPERTY_CHANGED eventconference.addEventListener("PARTICIPANT_PROPERTY_CHANGED", (participant, key,oldValue, newValue){});
Note: Local participant property can be used to set local particpants features example: screen-sharing, setting custom role or any other properties which help us group and identify participants by certain property.
conference.selectParticipant(participantId)//Elects the participant with the given id to be the selected participant in order to receive higher video quality (if simulcast is enabled).
conference.selectParticipants(participantIds) // string array of participant Id's //Elects the participant with the given id to be the selected participant in order to receive higher video quality (if simulcast is enabled).
Access local user details directly from conference
// notifies that participant has been kicked from the conference by moderatorconference.addEventListener("KICKED", (id){//let id = id as String; id of kicked participant});// notifies that moderator has been kicked by other moderatorconference.addEventListener("PARTICIPANT_KICKED", (actorParticipant, kickedParticipant, reason){//let actorParticipant = actorParticipant as Participant;//let kickedParticipant = kickedParticipant as Participant;//let reason = reason as String; reason for kick})// to kick participantconference.kickParticipant(id); // participant id// to kick moderator conference.kickParticipant(id, reason); // participant id, reason for kick
Except for the room creator, the rest of the users have a participatory role. You can grant them owner rights with the following code.
conference.grantOwner(id) // participant id// listen for role changed event conference.addEventListener("USER_ROLE_CHANGED",( id, role){// let id = id as String; id of participant//let role = role as String; new role of userif (confernece.getUserId() === id ) {// My role changed, new role: role; } else {// Participant role changed: role; }});
// to change your display nameconference.setDisplayName(name); // Listens for change display name event if changed by anyone in the conferenceconference.addEventListener("DISPLAY_NAME_CHANGED", (id, displayName){// let id = id as String;// let displayName = displayName as String;});
A participant supports 2 tracks at a type: audio and video. Screen sharing(desktop) is also a type of video track. If you need screen sharing along with the speaker video you need to have Presenter mode enabled.
conference.sendMessage("message"); // group conference.sendMessage("message", participantId); // to send private message to a participant // Now participants can listen message received event conference.addEventListener("MESSAGE_RECEIVED") , (message, senderId){// let message = message as String; message text // let senderId = senderId as String; senderId });
// New local connection statistics are received. conference.addEventListener("LOCAL_STATS_UPDATED", (stats){ });// New remote connection statistics are received.conference.addEventListener("REMOTE_STATS_UPDATED", (id, stats){ });
Sariska automatically switches to peer peer-to-peer mode if participants in the conference exactly 2. You can, however, still you can forcefully switch to peer-to-peer mode.
conference.startP2PSession();
Note: Conferences started on peer-to-peer mode will not be charged until the turn server is not used.
// to join a conference with already muted audio and video Map<String, dynamic> options = {};options["startAudioMuted"] =true;options["startVideoMuted"] =true;const conference = connection.initJitsiConference(options);
Map<String, dynamic> options = {}; options["broadcastId"] ="youtubeBroadcastID"; // put any string this will become part of your publish URLoptions["mode"] ="stream"; // here mode will be streamoptions["streamId"] ="youtubeStreamKey"; // to start the live streamconference.startRecording(options);
You can get the youtube stream key manually by login to your youtube account or using google OAuth API
Map<String, dynamic> options = {}; options["mode"] ="stream"; // here mode will be stream options["streamId"] ="rtmp://live.twitch.tv/app/STREAM_KEY"; // to start live stream conference.startRecording(options);
Stream to any RTMP server
Map<String, dynamic> options = {};options["mode"] ="stream"; // here mode will be streamoptions["streamId"] ="rtmps://rtmp-server/rtmp"; // RTMP server URL// to start live streamconference.startRecording(options);
Listen for RECORDER_STATE_CHANGED event to know live streaming status
conference.addEventListener("RECORDER_STATE_CHANGED", (sessionId, mode, status){String sessionId = sessionId asString; // sessionId of live streaming sessionString mode = mode asString; // mode will be streamString status = status asString; // status of live streaming session it can be on, off or pending});
// Config for object based storage AWS S3, Google Cloud Storage, Azure Blob Storage or any other S3 compatible cloud providers are supported. Login to your Sariska dashboard to set your credentials , we will upload all your recordings and transcriptios.
Map<String, dynamic> options = {};options["mode"] ="file";options["serviceName"] ="s3";// config options for dropboxMap<String, dynamic> options = {};options["mode"] ="file";options["serviceName"] ="dropbox";options["token"] ="dropbox_oauth_token";// to start cloud recordingconference.startRecording(options);//listen for RECORDER_STATE_CHANGED event to know what is happeningconference.addEventListener("RECORDER_STATE_CHANGED", (sessionId, mode, status){String sessionId = sessionId asString; // sessionId of cloud recording sessionString mode = mode asString; // here mode will be fileString status = status asString; // status of cloud recording session it can be on, off or pending});
String phonePin = conference.getPhonePin();
String phoneNumber = conference.getPhoneNumber();
// Share this Phone Number and Phone Pin to anyone who can join conference call without internet.
To enable the feature for waiting room/lobby checkout API's below
// to join lobyy
conference.joinLobby(displayName, email);
// This notifies everyone at the conference with the following events
conference.addEventListener("LOBBY_USER_JOINED", (id, name){
// let id = id as String;
// let name = name as String;
})
conference.addEventListener("LOBBY_USER_UPDATED", (id, participant){
// let id = id as String;
// let participant = participant as Participant;
})
conference.addEventListener("LOBBY_USER_LEFT", (id){
// let id = id as String;
})
conference.addEventListener("MEMBERS_ONLY_CHANGED", (enabled){
// let id = id as bool;
})
// now a conference moderator can allow/deny
conference.lobbyDenyAccess(participantId); //to deny lobby access
conference.lobbyApproveAccess(participantId); // to approve lobby mode
// others methods
conference.enableLobby() //to enable lobby mode in the conference call moderator only
conference.disableLobby(); //to disable lobby mode in the conference call moderator only
conference.isMembersOnly(); // whether conference room is members only. means lobby mode is disabled
// start sip gateway session
conference.startSIPVideoCall("address@sip.domain.com", "display name"); // your sip address and display name
// stop sip call
conference.stopSIPVideoCall('address@sip.domain.com');
// after you create your session now you can track the state of your session
conference.addEventListener("VIDEO_SIP_GW_SESSION_STATE_CHANGED", (state){
// let state = state as String;
// state can be on, off, pending, retrying, failed
})
// check if gateway is busy
conference.addEventListener("VIDEO_SIP_GW_AVAILABILITY_CHANGED", (status){
// let status = status as String;
// status can be busy or available
})
One to one calling is more of synchronous way of calling where you deal with things like
Calling someone even if his app is closed or background
Play a busy tone if a user is busy on another call or disconnected your call
Play ringtone/ringback/dtmftone
This is similar to how WhatsApp works.
Make an HTTP call to the Sariska server
URL: https://api.sariska.io/api/v1/media/poltergeist/create?room=sessionId&token=your-token&status=calling&user=12234&name=Kavi
Method: GET
where paramters are
* room: current session sessionId of the room you joined inviteCallee
* token: your jwt token
* status: calling
* user: callee user id
* name: callee user name
* domain: 'sariska.io'
Send push notifications to callee using your Firebase or APNS account
Callee now reads the push notification using ConnectionService or CallKit even if the app is closed or in the background
Callee can update his status back to the caller just by making an updated HTTP Call, no needs to join the conference via SDK
URL: https://api.sariska.io/api/v1/media/poltergeist/update?room=sessionId&token=your-token&status=accepted&user=12234&name=Kavi
Method: GET
where paramters are
* room: current session sessionId of the room you joined inviteCallee
* token: callee jwt token
* status: accepted or rejected
* user: callee user id
* name: callee user name
* domain: 'sariska.io'
Since the Caller has already joined the conference using SDK he can easily get the status just by listening USER_STATUS_CHANGED event
conference.addEventListener("USER_STATUS_CHANGED", (id, status){
let id = id as String; // id of callee
let status = status as String; // status can be ringing, busy, rejected, connected, expired
// ringing if callee changed status to ringing
// busy if callee is busy on ther call
// rejected if callee has rejected your call
// connected if callee has accepted your call
// expired if callee is not able to answered within 40 seconds an expired status will be trigger by sariska
});
After the callee has joined the conference rest of the steps are the same as the normal conference call
This integration adds the /sariska slash command for your team so that you can start a video conference in your channel, making it easy for everyone to just jump on the call. The slash command, /sariska, will drop a conference link in the channel for all to join.
Mentioning one or more teammates, after /sariska, will send personalized invites to each user mentioned. Check out how it is integrated here.
Low-level logging on peer connection API calls and periodic getStats calls for analytics/debugging purposes. Make sure you have passed RTCstats WebSocket URL while initializing the conference. Check out how to configure RTCStats WebSocket Server here.