Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {

dependencies {

implementation 'live.videosdk:rtc-android-sdk:0.1.26'
implementation 'live.videosdk:rtc-android-sdk:0.1.32'
implementation 'com.nabinbhandari.android:permissions:3.8'
implementation 'com.amitshekhar.android:android-networking:1.0.2'

Expand Down
14 changes: 11 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="live.videosdk.rtc.android.java">

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

<application
android:name=".Common.MainApplication"
Expand All @@ -23,6 +26,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.VideoSDKRTC"
android:usesCleartextTraffic="true">
<service
android:name=".Common.Services.MicrophoneService"
android:foregroundServiceType="microphone"
tools:ignore="ForegroundServicePermission" />

<activity
android:name=".GroupCall.Activity.GroupCallActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package live.videosdk.rtc.android.java.Common.Services;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

public class MicrophoneService extends Service {
private static final String NOTIFICATION_CHANNEL_ID = "1001";
private static final int NOTIFICATION_ID = 1001;
private static final String NOTIFICATION_CHANNEL_DESC = "Microphone notification Channel";

private final IBinder mBinder = new MicrophoneService.LocalBinder();

@Nullable
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}

public class LocalBinder extends Binder {
MicrophoneService getService() {
return MicrophoneService.this;
}
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
generateForegroundNotification();
return START_STICKY;
}

private void generateForegroundNotification() {
Log.d("TAG", "generateForegroundNotification: ");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//Call Start foreground with notification
Intent notificationIntent = new Intent(this, getApplication().getClass());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);

ApplicationInfo ai = getApplicationInfo();
String notificationTitle = null;
String notificationContent = null;
int resourceId = 0;

try {
ai = getPackageManager().getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
if (ai != null) {
Bundle bundle = ai.metaData;
if (bundle != null) {
notificationTitle = bundle.getString("notificationTitle");
notificationContent = bundle.getString("notificationContent");
resourceId = bundle.getInt("notificationIcon");
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

if (notificationTitle == null) {
notificationTitle = "VideoSDK RTC is sharing your screen";
}
if (notificationContent == null) {
notificationContent = "meeting is running";
}

if (resourceId == 0) {
resourceId = getApplicationInfo().icon;
}

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle(notificationTitle)
.setSmallIcon(resourceId)
.setContentText(notificationContent)
.setContentIntent(pendingIntent);
Notification notification = notificationBuilder.build();
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Microphone notification Channel", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(NOTIFICATION_CHANNEL_DESC);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(NOTIFICATION_ID, notification);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
} else {
startForeground(NOTIFICATION_ID, notification);
}
}
}

@Override
public void onDestroy() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import live.videosdk.rtc.android.Stream;
import live.videosdk.rtc.android.VideoSDK;
import live.videosdk.rtc.android.VideoView;
import live.videosdk.rtc.android.java.Common.Services.MicrophoneService;
import live.videosdk.rtc.android.java.GroupCall.Adapter.ParticipantViewAdapter;
import live.videosdk.rtc.android.java.GroupCall.Utils.ParticipantState;
import live.videosdk.rtc.android.java.R;
Expand Down Expand Up @@ -194,9 +195,11 @@ protected void onCreate(Bundle savedInstanceState) {
// pass the token generated from api server
VideoSDK.config(token);

VideoSDK.setActivityForLifeCycle(GroupCallActivity.this);

Map<String, CustomStreamTrack> customTracks = new HashMap<>();

CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.TEXT, true, this);
CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.TEXT, true, this,null);
customTracks.put("video", videoCustomTrack);

CustomStreamTrack audioCustomTrack = VideoSDK.createAudioTrack("high_quality", this);
Expand Down Expand Up @@ -255,6 +258,9 @@ public void onClick(View view) {

viewAdapter = new ParticipantViewAdapter(GroupCallActivity.this, meeting);

viewPager2.setOffscreenPageLimit(1);
viewPager2.setAdapter(viewAdapter);

onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Expand Down Expand Up @@ -429,6 +435,10 @@ public void onMeetingJoined() {
toggleMicIcon();
toggleWebcamIcon();

if(micEnabled){
GroupCallActivity.this.startService(new Intent(GroupCallActivity.this, MicrophoneService.class));
}

setLocalListeners();

new NetworkUtils(GroupCallActivity.this).fetchMeetingTime(meeting.getMeetingId(), token, new ResponseListener<Integer>() {
Expand All @@ -439,10 +449,6 @@ public void onResponse(Integer meetingTime) {
}
});

viewPager2.setOffscreenPageLimit(1);
viewPager2.setAdapter(viewAdapter);


raiseHandListener = new PubSubMessageListener() {
@Override
public void onMessageReceived(PubSubMessage pubSubMessage) {
Expand Down Expand Up @@ -534,6 +540,7 @@ public void onClick(View v) {
public void onMeetingLeft() {
handler.removeCallbacks(runnable);
if (!isDestroyed()) {
GroupCallActivity.this.stopService(new Intent(GroupCallActivity.this, MicrophoneService.class));
Intent intents = new Intent(GroupCallActivity.this, CreateOrJoinActivity.class);
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Expand Down Expand Up @@ -755,7 +762,7 @@ private void toggleWebCam() {
if (webcamEnabled) {
meeting.disableWebcam();
} else {
CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.DETAIL, true, this);
CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.DETAIL, true, this,null);
meeting.enableWebcam(videoCustomTrack);
}
}
Expand Down Expand Up @@ -1064,7 +1071,7 @@ private void toggleRecording() {
JsonUtils.jsonPut(config, "layout", layout);
JsonUtils.jsonPut(config, "orientation", "portrait");
JsonUtils.jsonPut(config, "theme", "DARK");
meeting.startRecording(null, null, config);
meeting.startRecording(null, null, config,null);

} else {
meeting.stopRecording();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ public void onSpeakerChanged(List<List<Participant>> participantList, Participan
else
activeSpeakerLayout(activeSpeaker);
}

@Override
public void onMeetingStateChanged(String state) {
if(state == "FAILED")
{
if(participantGridLayout != null) {
for (int i = 0; i < participantGridLayout.getChildCount(); i++) {
View view = participantGridLayout.getChildAt(i);
VideoView videoView = view.findViewById(R.id.participantVideoView);
if (videoView != null) {
videoView.clearImage();
videoView.removeTrack();
videoView.releaseSurfaceViewRenderer();
}
}
}
}
}
};

participantState = ParticipantState.getInstance(meeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ParticipantChangeListener {
void onPresenterChanged(boolean screenShare);

void onSpeakerChanged(List<List<Participant>> participantList, Participant activeSpeaker);

void onMeetingStateChanged(String state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public void onSpeakerChanged(String participantId) {
participantChangeListenerList.get(i).onSpeakerChanged(null, activeSpeaker);
}
}

@Override
public void onMeetingStateChanged(String state) {
for (int i = 0; i < participantChangeListenerList.size(); i++) {
participantChangeListenerList.get(i).onMeetingStateChanged(state);
}
super.onMeetingStateChanged(state);
}
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.webrtc.VideoTrack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
Expand All @@ -89,6 +88,7 @@
import live.videosdk.rtc.android.java.Common.Adapter.ParticipantListAdapter;
import live.videosdk.rtc.android.java.Common.Listener.ResponseListener;
import live.videosdk.rtc.android.java.Common.Modal.ListItem;
import live.videosdk.rtc.android.java.Common.Services.MicrophoneService;
import live.videosdk.rtc.android.java.GroupCall.Utils.ParticipantState;
import live.videosdk.rtc.android.java.R;
import live.videosdk.rtc.android.java.Common.Roboto_font;
Expand Down Expand Up @@ -225,18 +225,12 @@ protected void onCreate(Bundle savedInstanceState) {
// pass the token generated from api server
VideoSDK.config(token);

Map<String, CustomStreamTrack> customTracks = new HashMap<>();

CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.TEXT, true,this);
customTracks.put("video", videoCustomTrack);

CustomStreamTrack audioCustomTrack = VideoSDK.createAudioTrack("high_quality", this);
customTracks.put("mic", audioCustomTrack);
VideoSDK.setActivityForLifeCycle(OneToOneCallActivity.this);

// create a new meeting instance
meeting = VideoSDK.initMeeting(
OneToOneCallActivity.this, meetingId, localParticipantName,micEnabled,
webcamEnabled, null, null, false, customTracks,null
OneToOneCallActivity.this, meetingId, localParticipantName,false,
false, null, null, false, null,null
);

meeting.addEventListener(meetingEventListener);
Expand Down Expand Up @@ -468,6 +462,10 @@ public void onMeetingJoined() {
micEnabled = !micEnabled;
webcamEnabled = !webcamEnabled;

if(!micEnabled){
OneToOneCallActivity.this.startService(new Intent(OneToOneCallActivity.this, MicrophoneService.class));
}

toggleMic();
toggleWebCam();

Expand Down Expand Up @@ -563,6 +561,7 @@ public void onClick(View view) {
@Override
public void onMeetingLeft() {
if (!isDestroyed()) {
OneToOneCallActivity.this.stopService(new Intent(OneToOneCallActivity.this, MicrophoneService.class));
Intent intents = new Intent(OneToOneCallActivity.this, CreateOrJoinActivity.class);
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Expand Down Expand Up @@ -688,6 +687,16 @@ public void onMeetingStateChanged(String state) {
HelperClass.setSnackBarStyle(snackbar.getView(), getResources().getColor(R.color.md_red_400));
snackbar.getView().setOnClickListener(view -> snackbar.dismiss());
snackbar.show();
if(localVideoView != null){
localVideoView.clearImage();
localVideoView.removeTrack();
localVideoView.releaseSurfaceViewRenderer();
}
if(participantVideoView != null){
participantVideoView.clearImage();
participantVideoView.removeTrack();
participantVideoView.releaseSurfaceViewRenderer();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (handler.hasCallbacks(runnable))
handler.removeCallbacks(runnable);
Expand Down Expand Up @@ -895,12 +904,11 @@ private void toggleWebCam() {
if (webcamEnabled) {
meeting.disableWebcam();
} else {
CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.DETAIL, true,this);
CustomStreamTrack videoCustomTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.DETAIL, true,this,null);
meeting.enableWebcam(videoCustomTrack);
}
webcamEnabled = !webcamEnabled;
toggleWebcamIcon(webcamEnabled);

}

private void setActionListeners() {
Expand Down Expand Up @@ -1130,7 +1138,7 @@ private void toggleRecording() {
JsonUtils.jsonPut(config, "layout", layout);
JsonUtils.jsonPut(config, "orientation", "portrait");
JsonUtils.jsonPut(config, "theme", "DARK");
meeting.startRecording(null,null,config);
meeting.startRecording(null,null,config,null);

} else {
meeting.stopRecording();
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
Expand All @@ -20,6 +21,7 @@ allprojects {
google()
mavenCentral()
maven { url "https://maven.aliyun.com/repository/jcenter" }
maven { url 'https://jitpack.io' }
}
}

Expand Down