In your project, add the Maven repository https://github.com/SariskaIO/sariska-maven-repository/raw/master/releases and the dependency io.sariska:sariska-media-transport into your build.gradle files.
The repository typically goes into the build.gradle file in the root of your project:
In recent versions of Android Studios, allprojects{} might not be found in build.gradle. In that case, the repository goes into the settings.gradle file in the root of your project:
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.
String token = {your-token};Connection connection =SariskaMediaTransport.JitsiConnection(token,"roomName",false);// 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 (error ==="PASSWORD_REQUIRED") {// token is expiredconnection.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.
Conference conference =connection.initJitsiConference(options);conference.join();//Additional options initJitsiConference accepts to enable more feature// startAudioMuted: true // to join audio muted// startVideoMuted: true // to join video muted// startSilent : true // to start conference in silent no audio recieve/send// rtcstatsServer: “” // send data to rtcstats server// callStatsID: “” // callStatsID to enble callstats// callStatsSecret: “” //callstatssecret// channelLastN: 10
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.
runOnUiThread(() -> {for (JitsiLocalTrack track : localTracks) {if (track.getType().equals("video")) {WebRTCView view =track.render();view.setObjectFit("cover");mLocalContainer.addView(view); } }})// WebRTCView class provides additional methods to manage View styling// view.setMirror( mirror)->true or false if you want to mirror your video to other participants// view.setObjectFit("cover")—> Can be "contain" or "cover"// view.setZOrderMediaOverlay(0)-> can be 0 or 1// view.setZOrderOnTop(0)-> 0, 1, 2
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 plays in conjunction with video stream.
The moderator of the meeting controls and gatekeeps the participants. The moderator has exclusive control of the meeting.
If you wish to have a moderator, pass the moderator value as true while generating your token. Moderator has the following permissions:
Ability to add a password to a room
Ability to grant the moderator role to non-moderators
Ability to kick non-moderators or other moderators
Ability to mute participates
Ability to make everyone see the moderator video (Everyone follows me)
Ability to make participants join muted (Everyone starts muted)
Ability to make participants join without video (Everyone starts hidden)
Ability to enable/disable the lobby room
Ability to approve join/knocking requests (when the lobby is enabled)
When the moderator leaves, a new one is selected automatically
conference.addEventListener("USER_JOINED", (id, participant)=>{// String id = (String) id// Participant participant = (Participant) participant// joined Participant class has the following popular properties which you can use to maintain UI states// avatar // email // moderator// audioMuted// videoMuted// displayName// role// status// hidden// botType// Generally participants are bots like transcriber, recorder});
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)=> {//String id = (String) id; 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)=>{// String[] leavingEndpointIds = ( String[] ) leavingEndpointIds; //Array of ID's of users leaving lastN// String[] enteringEndpointIds = ( String[] ) enteringEndpointIds; //Array of ID's of users entering lastN});// to 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 of the following PARTICIPANT_PROPERTY_CHANGED eventconference.addEventListener("PARTICIPANT_PROPERTY_CHANGED", (participant, key,oldValue, newValue) => {});
Note: Local participant property can be used to set local participants 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 modeatorconference.addEventListener("KICKED", (id)=> {//String id = (String) id; id of kicked participant});// notifies that moderator has been kicked from the conference by another moderatorconference.addEventListener("PARTICIPANT_KICKED", (actorParticipant, kickedParticipant, reason)=>{//Participant actorParticipant = (Participant) actorParticipant; //Participant kickedParticipant = (Participant) kickedParticipant;//String reason = (String) reason; moderator has to give reason for kick})// method to kick out a participant confernece.kickParticipant(id) // participant id
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) =>{//String id = (String) id; id of participant//String role = (String) role; 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)=>{// String id = (String) id;// String displayName = (String) displayName;});
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 to message received event conference.addEventListener("MESSAGE_RECEIVED", (message, senderId)=>{// message sent by sender// 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.
Bundle options =newBundle();options.putString("broadcastId","youtubeBroadcastID"); // put any string this will become part of your publish URLoptions.putString("mode","stream"); // here mode will be streamoptions.putString("streamId","youtubeStreamKey");// to start live streamconference.startRecording(options);
You can get youtube stream key manually by login to your youtube account or use google OAuth API
Bundle options =newBundle();options.putString("mode","stream"); // here mode will be streamoptions.putString("streamId","rtmps://live-api-s.facebook.com:443/rtmp/FB-4742724459088842-0-AbwKHwKiTd9lFMPy"); // facebook stream URL// to start live streamconference.startRecording(options);
You can get facebook streamId manually by login to your facebook account or use Facebook OAuth API.
Bundle options =newBundle(); options.putString("mode","stream"); // here mode will be stream options.putString("streamId","rtmp://live.twitch.tv/app/STREAM_KEY"); // switch // to start live stream conference.startRecording(options);
Stream to any RTMP server
Bundle options =newBundle();options.putString("mode","stream"); // here mode will be streamoptions.putString("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 = (String) sessionId; // sessionId of live streaming sessionString mode = (String) mode; // mode will be streamString status = (String) status; // 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.Bundle options =newBundle();options.putString("mode","file");options.putString("serviceName","s3");// config options for dropboxBundle options =newBundle();options.putString("mode","file");options.putString("serviceName","dropbox");options.putString("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 = (String) sessionId; // sessionId of cloud recording sessionString mode = (String) mode; // here mode will be fileString status = (String) status; // 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 a conference call without internet.
To enable the feature for waiting room/lobby checkout APIs below
// to join a lobby conference.joinLobby(displayName, email);// This notifies everyone at the conference of the following eventsconference.addEventListener("LOBBY_USER_JOINED", (id, name) => {});conference.addEventListener("LOBBY_USER_UPDATED", (id, participant)=> {});conference.addEventListener("LOBBY_USER_LEFT", id=> {});conference.addEventListener("MEMBERS_ONLY_CHANGED", enabled=> {});// now a conference moderator can allow/deny conference.lobbyDenyAccess(participantId); //to deny lobby accessconference.lobbyApproveAccess(participantId); // to approve lobby mode// other methodsconference.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 sessionconference.startSIPVideoCall("address@sip.domain.com","display name"); // your sip address and display name// stop sip callconference.stopSIPVideoCall('address@sip.domain.com');// after you create your session now you can track the state of your sessionconference.addEventListener("VIDEO_SIP_GW_SESSION_STATE_CHANGED", (state)=>{// String state = (String) state;// state can be on, off, pending, retrying, failed});// check if the gateway is busyconference.addEventListener("VIDEO_SIP_GW_AVAILABILITY_CHANGED", (status)=>{// String status = (String) status;// status can be busy or available });
One-to-one calling is more of the 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=KaviMethod:GETwhereparamtersare* 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=KaviMethod:GETwhereparametersare* room: current session sessionId of the room you joined invite Callee* 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) => {String id = (String) id; // id of callee String status = (String) status; // 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.