capacitor-plugin-vonage 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
2
  <application>
3
3
  <activity android:name="com.managemyhealth.plugin.vonage.VideoCallActivity"
4
+ android:launchMode="singleTask"
4
5
  android:screenOrientation="portrait">
5
6
  </activity>
6
7
  </application>
@@ -0,0 +1,28 @@
1
+ package com.managemyhealth.plugin.vonage;
2
+
3
+ import android.content.Context;
4
+ import android.view.Gravity;
5
+ import android.view.LayoutInflater;
6
+ import android.view.View;
7
+ import android.widget.TextView;
8
+ import android.widget.Toast;
9
+
10
+ public class CustomToastUtils {
11
+
12
+ public static void showGreenToast(Context context, String message) {
13
+ LayoutInflater inflater = LayoutInflater.from(context);
14
+ View layout = inflater.inflate(R.layout.custom_toast_green_layout, null);
15
+
16
+ TextView text = layout.findViewById(R.id.toastView);
17
+ text.setText(message);
18
+
19
+ Toast toast = new Toast(context);
20
+ toast.setDuration(Toast.LENGTH_SHORT);
21
+ toast.setView(layout);
22
+
23
+ // Set toast position to top right corner
24
+ toast.setGravity(Gravity.TOP | Gravity.END, 0, 0);
25
+
26
+ toast.show();
27
+ }
28
+ }
@@ -3,6 +3,9 @@ package com.managemyhealth.plugin.vonage;
3
3
 
4
4
 
5
5
  import android.annotation.SuppressLint;
6
+ import android.app.Activity;
7
+ import android.app.Application;
8
+ import android.content.Context;
6
9
  import android.graphics.Color;
7
10
  import android.graphics.PorterDuff;
8
11
  import android.os.AsyncTask;
@@ -13,8 +16,10 @@ import android.graphics.BitmapFactory;
13
16
  import android.opengl.GLSurfaceView;
14
17
  import android.os.Bundle;
15
18
  import android.os.Handler;
19
+ import android.os.Looper;
16
20
  import android.util.Log;
17
21
  import android.view.Gravity;
22
+ import android.view.LayoutInflater;
18
23
  import android.view.View;
19
24
  import android.widget.Button;
20
25
  import android.widget.FrameLayout;
@@ -51,12 +56,13 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
51
56
  import pub.devrel.easypermissions.EasyPermissions;
52
57
 
53
58
 
54
- public class VideoCallActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
59
+ public class VideoCallActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks , Application.ActivityLifecycleCallbacks{
55
60
  private static final String TAG = VideoCallActivity.class.getSimpleName();
56
61
  private static final int PERMISSIONS_REQUEST_CODE = 124;
57
62
 
58
63
  public Session session;
59
64
  private static Bridge staticBridge = null;
65
+ private String dummyProfile = "https://www.gravatar.com/avatar/?d=mp";
60
66
 
61
67
  public static VideoCallActivity instance;
62
68
  private Publisher publisher;
@@ -66,6 +72,7 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
66
72
  boolean isPatientOnline = false;
67
73
  boolean isMuted = false;
68
74
  boolean isCamOff = false;
75
+ boolean isCallinprogress = false;
69
76
  public boolean temptest = false;
70
77
  boolean isTimeron = false;
71
78
  boolean isEndall = false;
@@ -73,11 +80,13 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
73
80
  private FrameLayout publisherViewContainer;
74
81
  private LinearLayout ProviderViewLayout;
75
82
  private FrameLayout subscriberViewContainer;
83
+ private TextView publisherNameTextView;
76
84
  private FloatingActionButton fabCameraOff;
77
85
  private ImageView imageViewEndcall;
78
86
  private ImageView imageViewMute;
79
87
  private ImageView imageViewCamOff;
80
88
  private ImageView circleAvatar;
89
+ private boolean isAppInForeground;
81
90
 
82
91
  private ImageView imageViewCamSwitch;
83
92
  public static Button sendNotifications ;
@@ -86,6 +95,7 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
86
95
  public static Button admit;
87
96
  public static Button deny ;
88
97
 
98
+
89
99
  private static final int LOG_INTERVAL_MILLIS = 1000; // Log every 100 milliseconds
90
100
 
91
101
  private final Handler handler = new Handler();
@@ -120,6 +130,7 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
120
130
  public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
121
131
  Log.d(TAG, "onStreamCreated: Publisher Stream Created. Own stream " + stream.getStreamId());
122
132
 
133
+
123
134
  }
124
135
 
125
136
  @Override
@@ -137,88 +148,68 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
137
148
  private final Session.SessionListener sessionListener = new Session.SessionListener() {
138
149
  @Override
139
150
  public void onConnected(Session session) {
140
- Log.d(TAG, "onConnected: Connected to session: " + session.getSessionId());
141
- // JSObject eventData = new JSObject();
142
- // eventData.put("key", "value");
143
- // notifyListeners("", eventData);
144
151
  publisher = new Publisher.Builder(VideoCallActivity.this).build();
145
152
  publisher.setPublisherListener(publisherListener);
146
153
  publisher.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
147
- Log.d("publisherViewContainer", "publisherViewContainer.toString()");
148
154
  FrameLayout Framelayout = findViewById(R.id.publisher_container);
149
-
150
155
  try {
151
156
  if (Framelayout != null) {
152
- Log.d("publisherViewContainer", "Inside if =======");
153
157
  Framelayout.addView(publisher.getView());
154
- }
155
- } catch (Exception e) {
156
- Log.d("publisherViewContainer", e.toString());
157
- }
158
+ LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
159
+ View xmlDefinedView = inflater.inflate(R.layout.video_call_layout, Framelayout, false);
160
+ Framelayout.addView(xmlDefinedView);
161
+ publisherNameTextView.bringToFront();
158
162
 
163
+ }
164
+ } catch (Exception e) {}
159
165
  if (publisher.getView() instanceof GLSurfaceView) {
160
166
  ((GLSurfaceView) publisher.getView()).setZOrderOnTop(true);
161
167
  }
162
-
163
168
  session.publish(publisher);
164
169
  }
165
-
166
170
  @Override
167
171
  public void onDisconnected(Session session) {
168
172
  notifyObservers("deny");
169
173
  if(publisher!=null) {
170
-
171
174
  publisher.setPublishAudio(false);
172
175
  imageViewMute.setImageResource(R.drawable.microphoneoff);
173
-
174
176
  }
175
177
  if(publisher!=null) {
176
-
177
178
  publisher.setPublishVideo(false);
178
179
  imageViewCamOff.setImageResource(R.drawable.cameraoff);
179
180
  imageViewCamSwitch.setVisibility(View.GONE);
180
-
181
-
182
-
183
181
  }
184
182
  VideoCallActivity temp = new VideoCallActivity();
185
183
  temp.session = null;
186
-
187
- isTimeron=false;
188
-
189
- Log.d(TAG, "onDisconnected: Disconnected from session: " + session.getSessionId());
190
- if (publisher != null) {
184
+ isTimeron=false;
185
+ if (publisher != null) {
191
186
  publisher = null;
192
187
  publisherViewContainer.removeAllViews();
193
188
  }
194
- Intent resultIntent = new Intent();
195
- String resultcode = "";
196
-
197
- if(isEndall){
198
- resultcode= "111";
199
- }else{
200
- resultcode = ISPROVIDER ? "999" : "888";
201
- }
202
- resultIntent.putExtra("result_key", resultcode);
203
- setResult(RESULT_OK, resultIntent);
204
- // setResult(RESULT_CANCELED); // Use this to indicate cancellation
205
-
206
-
207
- finish();
189
+ Intent resultIntent = new Intent();
190
+ String resultcode = "";
191
+ if(isEndall){
192
+ resultcode= "111";
193
+ }else{
194
+ resultcode = ISPROVIDER ? "999" : "888";
195
+ }
196
+ resultIntent.putExtra("result_key", resultcode);
197
+ setResult(RESULT_OK, resultIntent);
198
+ finish();
208
199
  }
209
-
210
200
  @Override
211
201
  public void onStreamReceived(Session session, Stream stream) {
212
-
213
- Log.d(TAG, "onStreamReceived: New Stream Received " + stream.getStreamId() + " in session: " + session.getSessionId());
202
+ isCallinprogress = true;
214
203
  ProviderViewLayout = findViewById(R.id.providerViewLayout);
215
204
  if(ISPROVIDER) {
216
205
  ProviderViewLayout.setVisibility(View.VISIBLE);
217
206
  }
218
207
  circleAvatar.setVisibility(View.GONE); // Hide the view
219
208
  patientStatus.setVisibility(View.GONE); // Hide the view
220
- publishernameView.setVisibility(View.GONE); // Hide the view
221
-
209
+ publishernameView.setVisibility(View.GONE);// Hide the view
210
+ admit.setVisibility(View.GONE);
211
+ deny.setVisibility(View.GONE);
212
+ sendNotifications.setVisibility(View.GONE);
222
213
 
223
214
  if (subscriber == null) {
224
215
  subscriber = new Subscriber.Builder(VideoCallActivity.this, stream).build();
@@ -228,22 +219,14 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
228
219
  session.subscribe(subscriber);
229
220
  try {
230
221
  subscriberViewContainer.addView(subscriber.getView());
231
- } catch (Exception e) {
232
- Log.d("subscriberViewContainer", e.toString());
233
-
234
- }
222
+ } catch (Exception e) {}
235
223
  showToast(SUBSCRIBERNAME + "joined the call");
236
-
237
224
  }
238
225
  }
239
226
 
240
227
  @Override
241
228
  public void onStreamDropped(Session session, Stream stream) {
242
-
243
- Log.d(TAG, "onStreamDropped: Stream Dropped: " + stream.getStreamId() + " in session: " + session.getSessionId());
244
-
245
- circleAvatar.setVisibility(View.VISIBLE); // Show the view
246
-
229
+ circleAvatar.setVisibility(View.VISIBLE); // Show the view
247
230
  if(!ISPROVIDER){
248
231
  if(session!=null){
249
232
  session.disconnect();
@@ -273,6 +256,20 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
273
256
  finishWithMessage("Session error: " + opentokError.getMessage());
274
257
  }
275
258
  };
259
+ SubscriberKit.AudioStatsListener aaa = new SubscriberKit.AudioStatsListener(){
260
+ @Override
261
+ public void onAudioStats(SubscriberKit subscriberKit, SubscriberKit.SubscriberAudioStats subscriberAudioStats) {
262
+
263
+ }
264
+ };
265
+ SubscriberKit.AudioLevelListener sss = new SubscriberKit.AudioLevelListener(){
266
+
267
+ @Override
268
+ public void onAudioLevelUpdated(SubscriberKit subscriberKit, float v) {
269
+
270
+ }
271
+ };
272
+
276
273
  SubscriberKit.VideoListener videoListener = new SubscriberKit.VideoListener() {
277
274
 
278
275
  @Override
@@ -389,7 +386,7 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
389
386
  ISPROVIDER = intent.getBooleanExtra("isProvider",false);
390
387
  publisherViewContainer = findViewById(R.id.publisher_container);
391
388
  subscriberViewContainer = findViewById(R.id.subscriber_container);
392
- TextView publisherNameTextView = findViewById(R.id.publisherName);
389
+ publisherNameTextView = findViewById(R.id.publisherName);
393
390
  publishernameView = findViewById(R.id.publisherNameView);
394
391
  TextView subscriberNameTextView = findViewById(R.id.subscriberName);
395
392
 
@@ -424,9 +421,11 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
424
421
  }else{
425
422
  ProviderViewLayout.setVisibility(View.GONE);
426
423
  }
427
- new urltoSource((ImageView) findViewById(R.id.image_view)).execute(profilePicApiUrl);
424
+ String dummyImage = profilePicApiUrl.length()>10?profilePicApiUrl:dummyProfile;
425
+ new urltoSource((ImageView) findViewById(R.id.image_view)).execute(dummyImage);
428
426
  initializeSession(API_KEY,SESSION_ID , TOKEN);
429
427
 
428
+
430
429
  }
431
430
 
432
431
 
@@ -474,8 +473,6 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
474
473
  if(session!=null){
475
474
  session.disconnect();
476
475
  }
477
- // session.cl=
478
-
479
476
  }
480
477
  });
481
478
 
@@ -677,19 +674,23 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
677
674
 
678
675
  private void showToast(String message) {
679
676
  try{
680
- Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG);
681
- View view = toast.getView();
682
- int color = Color.parseColor("#1fc600");
683
- int colorText = Color.parseColor("#ffffff");
684
- view.getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
685
- TextView text = view.findViewById(android.R.id.message);
686
- text.setTextColor(Color.BLACK);
687
- toast.setGravity(Gravity.TOP, 0, 0);
688
- toast.show();
677
+ if(isAppInForeground()){
678
+ showGreenToast(getApplicationContext(),message);
679
+ }
680
+ // Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG);
681
+ // View view = toast.getView();
682
+ // int color = Color.parseColor("#1fc600");
683
+ // int colorText = Color.parseColor("#ffffff");
684
+ // view.getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
685
+ // TextView text = view.findViewById(android.R.id.message);
686
+ // text.setTextColor(Color.BLACK);
687
+ // toast.setGravity(Gravity.TOP, 0, 0);
688
+ // toast.show();
689
689
  }catch(Exception e){
690
690
  Log.d("toastlogex",e.toString());
691
691
  }
692
692
  }
693
+
693
694
  private void finishWithMessage(String message) {
694
695
  Log.e(TAG, message);
695
696
  // Toast.makeText(this, message, Toast.LENGTH_LONG).show();
@@ -712,33 +713,54 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
712
713
  Log.d("patientStatusChanged2", String.valueOf(isOnline));
713
714
  Log.d("patientStatusChanged2", String.valueOf(isOnline));
714
715
 
715
- runOnUiThread(new Runnable() {
716
- @Override
717
- public void run() {
718
- temptest= isOnline;
719
- if(isOnline){
720
- Log.d("isOnline", String.valueOf(isOnline));
721
-
722
- patientStatus.setText("WAITING");
723
- sendNotifications.setVisibility(View.GONE);
724
- admit.setVisibility(View.VISIBLE);
725
- deny.setVisibility(View.VISIBLE);
726
- patientStatus.setBackgroundResource(R.color.waiting);
716
+ if(!isCallinprogress){
717
+ runOnUiThread(new Runnable() {
718
+ @Override
719
+ public void run() {
720
+ temptest = isOnline;
721
+ if (isOnline) {
722
+ Log.d("isOnline", String.valueOf(isOnline));
723
+
724
+ patientStatus.setText("WAITING");
725
+ sendNotifications.setVisibility(View.GONE);
726
+ admit.setVisibility(View.VISIBLE);
727
+ deny.setVisibility(View.VISIBLE);
728
+ patientStatus.setBackgroundResource(R.color.waiting);
727
729
  // patientStatus.setBackgroundColor(getResources().getColor(R.color.waiting));
728
- }else{
729
- Log.d("OFFLINE", String.valueOf(isOnline));
730
- patientStatus.setText("OFFLINE");
731
- admit.setVisibility(View.GONE);
732
- deny.setVisibility(View.GONE);
733
- sendNotifications.setVisibility(View.VISIBLE);
734
- patientStatus.setText("OFFLINE");
735
- patientStatus.setBackgroundResource(R.color.offline);
730
+ } else {
731
+ Log.d("OFFLINE", String.valueOf(isOnline));
732
+ patientStatus.setText("OFFLINE");
733
+ admit.setVisibility(View.GONE);
734
+ deny.setVisibility(View.GONE);
735
+ sendNotifications.setVisibility(View.VISIBLE);
736
+ patientStatus.setText("OFFLINE");
737
+ patientStatus.setBackgroundResource(R.color.offline);
736
738
  // patientStatus.setBackgroundColor(getResources().getColor(R.color.offline));
739
+ }
740
+
741
+
737
742
  }
743
+ });
744
+ }
745
+ }
746
+ public static void showGreenToast(Context context, String message) {
747
+ LayoutInflater inflater = LayoutInflater.from(context);
748
+ View layout = inflater.inflate(R.layout.custom_toast_green_layout, null);
738
749
 
750
+ TextView text = layout.findViewById(R.id.toastView);
751
+ text.setText(message);
739
752
 
740
- }
741
- });
753
+ Toast toast = new Toast(context);
754
+ toast.setDuration(Toast.LENGTH_SHORT);
755
+ toast.setView(layout);
756
+
757
+ // Set toast position to top right corner
758
+ toast.setGravity(Gravity.TOP | Gravity.END, 0, 0);
759
+
760
+ toast.show();
761
+ }
762
+ private boolean isAppInForeground() {
763
+ return isAppInForeground;
742
764
  }
743
765
 
744
766
  public void notifyObservers(String value) {
@@ -746,6 +768,43 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
746
768
  temp.update(value);
747
769
  }
748
770
 
771
+ @Override
772
+ public void onActivityCreated(@NonNull Activity activity, @androidx.annotation.Nullable Bundle bundle) {
773
+
774
+ }
775
+
776
+ @Override
777
+ public void onActivityStarted(@NonNull Activity activity) {
778
+
779
+ }
780
+
781
+ @Override
782
+ public void onActivityResumed(@NonNull Activity activity) {
783
+ Log.d("isAppInForeground", String.valueOf(isAppInForeground));
784
+ isAppInForeground = true;
785
+ }
786
+
787
+ @Override
788
+ public void onActivityPaused(@NonNull Activity activity) {
789
+ Log.d("isAppInForeground", String.valueOf(isAppInForeground));
790
+ isAppInForeground = false;
791
+ }
792
+
793
+ @Override
794
+ public void onActivityStopped(@NonNull Activity activity) {
795
+
796
+ }
797
+
798
+ @Override
799
+ public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
800
+
801
+ }
802
+
803
+ @Override
804
+ public void onActivityDestroyed(@NonNull Activity activity) {
805
+
806
+ }
807
+
749
808
  private class urltoSource extends AsyncTask<String, Void, Bitmap> {
750
809
  ImageView imageView;
751
810
  public urltoSource(ImageView imageView) {
@@ -50,9 +50,10 @@ public class vonagePlugin extends Plugin{
50
50
  @PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
51
51
  public void setPatientOnlineStatus(PluginCall call) {
52
52
  final Boolean isOnline = call.getBoolean("isOnline");
53
-
53
+ showLog("isOnline");
54
+ showLog(isOnline.toString());
54
55
  Handler mainHandler = new Handler(Looper.getMainLooper());
55
- Context appCon = this.bridge.getContext();
56
+
56
57
  Runnable myRunnable = new Runnable() {
57
58
  @Override
58
59
  public void run() {
@@ -121,6 +122,8 @@ public class vonagePlugin extends Plugin{
121
122
  intent.putExtra("isProvider", ISPROVIDER);
122
123
  intent.putExtra("isPatientOnline", isPatientOnline);
123
124
  intent.putExtra("profilePicApiUrl", profilePicApiUrl);
125
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
126
+
124
127
 
125
128
  Handler handler = new Handler();
126
129
  int delayMillis = 2000;
@@ -134,7 +137,7 @@ public class vonagePlugin extends Plugin{
134
137
  }, delayMillis);
135
138
 
136
139
  eventData.put("isProvider", isProvid);
137
- showLog("testing resolve endPluginCal");
140
+
138
141
  endPluginCal.resolve(eventData);
139
142
  this.startActivityForResult(call, intent, "onAcitivtyClosed");
140
143
  call.setKeepAlive(false);
@@ -148,8 +151,7 @@ public class vonagePlugin extends Plugin{
148
151
  JSObject eventData1 = new JSObject();
149
152
  eventData1.put("key", "value test value");
150
153
  eventData1.put("isProvider", isProvid);
151
- showLog("eventData");
152
- showLog(eventData1.toString());
154
+
153
155
  handler.postDelayed(new Runnable() {
154
156
  @Override
155
157
  public void run() {
@@ -238,7 +240,7 @@ public class vonagePlugin extends Plugin{
238
240
  // session.connect(token);
239
241
  // }
240
242
  private void showLog(String log){
241
- Log.d(Tag,log);
243
+ // Log.d(Tag,log);
242
244
  }
243
245
  private void test(PluginCall call){
244
246
  JSObject eventData = new JSObject();
@@ -0,0 +1,18 @@
1
+ <!-- custom_toast_green_layout.xml -->
2
+ <LinearLayout
3
+ xmlns:android="http://schemas.android.com/apk/res/android"
4
+ android:layout_width="wrap_content"
5
+ android:layout_height="wrap_content"
6
+ android:orientation="vertical"
7
+ android:padding="16dp"
8
+ android:background="#00FF00">
9
+
10
+ <TextView
11
+ android:id="@+id/toastView"
12
+ android:layout_width="wrap_content"
13
+ android:layout_height="wrap_content"
14
+ android:text="Custom Toast"
15
+ android:textColor="#0B6623"
16
+ android:textStyle="bold"
17
+ android:layout_gravity="center_horizontal"/>
18
+ </LinearLayout>
@@ -58,7 +58,7 @@
58
58
  android:layout_height="wrap_content"
59
59
  android:layout_gravity="bottom|start"
60
60
  android:paddingBottom="100dp"
61
- android:paddingLeft="10dp"
61
+ android:paddingStart="10dp"
62
62
  android:text="00:00:00"
63
63
  android:visibility="visible"
64
64
  android:textColor="@android:color/white"
@@ -70,24 +70,29 @@
70
70
  android:layout_height="120dp"
71
71
  android:layout_gravity="bottom|end"
72
72
  android:layout_marginEnd="16dp"
73
- android:layout_marginRight="16dp"
74
- android:layout_marginBottom="80dp"
73
+ android:layout_marginBottom="110dp"
75
74
  android:background="#9b9c98"
76
- android:layout_below="@id/publisherName"
77
75
 
78
76
  android:padding="2dp" >
79
- <TextView
80
- android:id="@+id/subscriberName"
81
- android:layout_width="100dp"
82
- android:layout_height="wrap_content"
83
- android:layout_gravity="center_vertical|bottom"
84
- android:paddingBottom="6dp"
85
- android:text="@string/subscriber_name"
86
- android:textColor="@android:color/white"
87
- android:visibility="visible"
88
- android:textSize="12sp" />
77
+
89
78
 
90
79
  </FrameLayout>
80
+ <TextView
81
+ android:id="@+id/subscriberName"
82
+ android:layout_width="100dp"
83
+ android:layout_height="wrap_content"
84
+ android:layout_gravity="bottom|end"
85
+ android:paddingBottom="6dp"
86
+ android:layout_marginEnd="16dp"
87
+ android:layout_marginBottom="80dp"
88
+ android:maxLines="1"
89
+ android:ellipsize="end"
90
+ android:text="@string/subscriber_name"
91
+ android:textColor="@android:color/white"
92
+ android:visibility="visible"
93
+ android:gravity="center"
94
+ android:textSize="12sp" />
95
+
91
96
 
92
97
  <de.hdodenhof.circleimageview.CircleImageView
93
98
  xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -48,8 +48,9 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
48
48
  var timerLabel = UILabel()
49
49
  var subscriberImg = UIImageView()
50
50
  var counter = 0
51
- var timer = Timer()
51
+ var timer : Timer?
52
52
  var activityView: UIActivityIndicatorView?
53
+ weak var delegate: VonageSDKInteractionDelegate?
53
54
  override func viewDidLoad() {
54
55
 
55
56
  super.viewDidLoad()
@@ -122,14 +123,13 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
122
123
  override func viewDidDisappear(_ animated: Bool) {
123
124
  print("viewDidDisappear")
124
125
  super.viewDidDisappear(animated)
125
- let userInfo = ["userInfo": ["isProvider": self.isProvider]]
126
- if(!isCallEnded){
127
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
128
-
129
- // NotificationCenter.default.removeObserver(self, name: NSNotification.Name("EndVideoCall"), object: nil)
130
-
131
- NotificationCenter.default.post(name: NSNotification.Name("RemoveObservers"),object: nil,userInfo: userInfo)
132
- }
126
+ // let userInfo = ["userInfo": ["isProvider": self.isProvider]]
127
+ // if(!isCallEnded){
128
+ //// NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
129
+ ////
130
+ //// NotificationCenter.default.post(name: NSNotification.Name("RemoveObservers"),object: nil,userInfo: userInfo)
131
+ // delegate?.videoCallEnded(userInfo)
132
+ // }
133
133
  NotificationCenter.default.removeObserver(self)
134
134
  }
135
135
  @objc func appMovedToBackground() {
@@ -171,15 +171,23 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
171
171
  NotificationCenter.default.removeObserver(self, name: NSNotification.Name("EndVideoCall"), object: nil)
172
172
  }
173
173
  func startTimer(){
174
- if(timer != nil && timer.isValid){
175
- timer.invalidate()
174
+ // if(timer != nil && timer.isValid){
175
+ // timer.invalidate()
176
+ // }
177
+ if let timerObj = timer, timerObj.isValid{
178
+ timer?.invalidate()
176
179
  }
177
180
  timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
178
181
  }
179
182
  func stopTimer(){
180
- if(timer != nil && timer.isValid){
181
- timer.invalidate()
183
+ // if(timer != nil && timer.isValid){
184
+ // timer.invalidate()
185
+ // counter = 0
186
+ // }
187
+ if let timerObj = timer, timerObj.isValid{
188
+ timer?.invalidate()
182
189
  counter = 0
190
+ timer = nil
183
191
  }
184
192
 
185
193
  }
@@ -362,14 +370,7 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
362
370
 
363
371
 
364
372
  }
365
- deinit{
366
- if(!isCallEnded){
367
- let userInfo = ["userInfo": ["isProvider": self.isProvider]]
368
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
369
- NotificationCenter.default.post(name: NSNotification.Name("RemoveObservers"),object: nil,userInfo: userInfo)
370
- }
371
-
372
- }
373
+
373
374
  func patientStatusChanged(){
374
375
  if(isProvider && isPatientOnLine){
375
376
  centerView.isHidden = false
@@ -407,7 +408,8 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
407
408
  subscriberNameLabel.isHidden = false
408
409
  subscriberStatusLabel.text = "Please Wait.."
409
410
  let userInfo = ["userInfo": ["isProvider": isProvider]]
410
- NotificationCenter.default.post(name: NSNotification.Name("SendNotification"),object: nil,userInfo: userInfo)
411
+ // NotificationCenter.default.post(name: NSNotification.Name("SendNotification"),object: nil,userInfo: userInfo)
412
+ delegate?.videoCallSendNotification(userInfo)
411
413
  // self.session?.disconnect(nil)
412
414
  // self.stopTimer()
413
415
  // self.dismiss(animated: true, completion: nil)
@@ -428,14 +430,16 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
428
430
  // self.stopTimer()
429
431
  // self.dismiss(animated: true, completion: nil)
430
432
  let userInfo = ["userInfo": ["isProvider": isProvider]]
431
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoStarted),object: nil,userInfo: userInfo)
433
+ // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoStarted),object: nil,userInfo: userInfo)
434
+ delegate?.videoCallStarted(userInfo)
432
435
  }
433
436
  @objc func denybuttonClicked() {
434
437
  print("deny button clicked")
435
438
  centerView.isHidden = true
436
439
  let userInfo = ["userInfo": ["isProvider": isProvider]]
437
440
 
438
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
441
+ // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
442
+ delegate?.videoCallEnded(userInfo)
439
443
  // self.session?.disconnect(nil)
440
444
  // self.stopTimer()
441
445
  // self.dismiss(animated: true, completion: nil)
@@ -446,7 +450,8 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
446
450
  @objc func callBtnbuttonClicked() {
447
451
 
448
452
  let userInfo = ["userInfo": ["isProvider": isProvider]]
449
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
453
+ // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
454
+ delegate?.videoCallEnded(userInfo)
450
455
  self.endVonageCall()
451
456
  }
452
457
 
@@ -545,11 +550,12 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
545
550
  func sessionDidDisconnect(_ session: OTSession) {
546
551
  print("The client disconnected from the OpenTok session.")
547
552
  // self.session?.disconnect(nil)
548
- if(!isCallEnded){
549
- let userInfo = ["userInfo": ["isProvider": self.isProvider]]
550
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
551
- }
552
- self.dismiss(animated: true, completion: nil)
553
+ // if(!isCallEnded){
554
+ // let userInfo = ["userInfo": ["isProvider": self.isProvider]]
555
+ // // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
556
+ // delegate?.videoCallEnded(userInfo)
557
+ // }
558
+ // self.dismiss(animated: true, completion: nil)
553
559
  }
554
560
 
555
561
  func session(_ session: OTSession, didFailWithError error: OTError) {
@@ -561,10 +567,6 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
561
567
  guard let subscriber = subscriber else {
562
568
  return
563
569
  }
564
-
565
- if !stream.hasAudio {
566
- print("Stream audio \(stream.hasAudio)")
567
- }
568
570
  self.subscriber = subscriber
569
571
  var error: OTError?
570
572
  session.subscribe(subscriber, error: &error)
@@ -582,6 +584,9 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
582
584
  if(stream.videoType == .screen){
583
585
  subscriberView.accessibilityValue = "from screen"
584
586
  }
587
+ adminBtn.isHidden = true
588
+ denyBtn.isHidden = true
589
+ sendNotificationBtn.isHidden = true
585
590
  remoteView.addSubview(subscriberView)
586
591
  }
587
592
 
@@ -596,7 +601,8 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
596
601
  if let subStream = subscriber?.stream, subStream.streamId == stream.streamId,!isProvider, stream.videoType != .screen {
597
602
  // cleanupSubscriber()
598
603
  let userInfo = ["userInfo": ["isProvider": isProvider]]
599
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
604
+ // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
605
+ delegate?.videoCallEnded(userInfo)
600
606
  // self.session?.disconnect(nil)
601
607
  self.endVonageCall()
602
608
  //self.dismiss(animated: true, completion: nil)
@@ -676,26 +682,27 @@ class VideoChatViewController: UIViewController,OTSessionDelegate,OTPublisherDel
676
682
  isCallEnded = true
677
683
  let userInfo = ["userInfo": ["isProvider": self.isProvider]]
678
684
 
679
- NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
685
+ // NotificationCenter.default.post(name: NSNotification.Name(NotificationNames.videoEnded),object: nil,userInfo: userInfo)
686
+ delegate?.videoCallEnded(userInfo)
680
687
  endVonageCall()
681
688
  }
682
689
  fileprivate func endVonageCall(){
683
690
  isCallEnded = true
684
- let userInfo = ["userInfo": ["isProvider": self.isProvider]]
685
- NotificationCenter.default.post(name: NSNotification.Name("RemoveObservers"),object: nil,userInfo: userInfo)
686
- DispatchQueue.main.async {
691
+ //let userInfo = ["userInfo": ["isProvider": self.isProvider]]
692
+ // NotificationCenter.default.post(name: NSNotification.Name("RemoveObservers"),object: nil,userInfo: userInfo)
693
+ // DispatchQueue.main.async {
687
694
  print("video ended called")
688
695
  // self.publisher?.publishVideo = false
689
- self.publisher?.videoCapture?.stop()
696
+ // self.publisher?.videoCapture?.stop()
690
697
  // self.publisher?.publishAudio = false
691
698
  self.session?.disconnect(nil)
692
- self.cleanupSubscriber()
693
- self.cleanupPublisher()
699
+ // self.cleanupSubscriber()
700
+ //self.cleanupPublisher()
694
701
  self.stopTimer()
695
702
  self.dismiss(animated: true) {
696
703
  print("video ended")
697
704
  }
698
- }
705
+ //}
699
706
  }
700
707
  fileprivate func cleanupSubscriber() {
701
708
  subscriber?.view?.removeFromSuperview()
@@ -6,7 +6,7 @@ import Capacitor
6
6
  * here: https://capacitorjs.com/docs/plugins/ios
7
7
  */
8
8
  @objc(vonagePlugin)
9
- public class vonagePlugin: CAPPlugin {
9
+ public class vonagePlugin: CAPPlugin,VonageSDKInteractionDelegate {
10
10
  @objc func openVideoCallWindow(_ call: CAPPluginCall) {
11
11
 
12
12
  let sessionId = call.getString("sessionId") ?? ""
@@ -30,24 +30,14 @@ public class vonagePlugin: CAPPlugin {
30
30
  vc.profilePicApiUrl = profilePhoto
31
31
  // vc.videoCallParam = value
32
32
  vc.modalPresentationStyle = .fullScreen
33
+ vc.delegate = self
33
34
  self.bridge?.viewController?.present(vc, animated: true, completion: nil)
34
35
  }
35
- NotificationCenter.default.addObserver(self,selector:#selector(videoEnded(_:)),name: NSNotification.Name (NotificationNames.videoEnded),object: nil)
36
- NotificationCenter.default.addObserver(self,selector:#selector(videoStarted(_:)),name: NSNotification.Name (NotificationNames.videoStarted),object: nil)
37
- NotificationCenter.default.addObserver(self,selector:#selector(sendNotification(_:)),name: NSNotification.Name ("SendNotification"),object: nil)
38
- NotificationCenter.default.addObserver(self,selector:#selector(removeObservers(_:)),name: NSNotification.Name ("RemoveObservers"),object: nil)
39
- // if let visibleViewCtrl = UIApplication.topViewController() {
40
- // // do whatever you want with your `visibleViewCtrl`
41
- // print(visibleViewCtrl)
42
- // DispatchQueue.main.async(execute: {
43
- // let vc = VideoChatViewController()
44
- // vc.kApiKey = apiKey
45
- // vc.kToken = token
46
- // vc.kSessionId = sessionId
47
- // // vc.videoCallParam = value
48
- // vc.modalPresentationStyle = .fullScreen
49
- // visibleViewCtrl.present(vc, animated: true, completion: nil)})
50
- // }
36
+ // NotificationCenter.default.addObserver(self,selector:#selector(videoEnded(_:)),name: NSNotification.Name (NotificationNames.videoEnded),object: nil)
37
+ // NotificationCenter.default.addObserver(self,selector:#selector(videoStarted(_:)),name: NSNotification.Name (NotificationNames.videoStarted),object: nil)
38
+ // NotificationCenter.default.addObserver(self,selector:#selector(sendNotification(_:)),name: NSNotification.Name ("SendNotification"),object: nil)
39
+ // NotificationCenter.default.addObserver(self,selector:#selector(removeObservers(_:)),name: NSNotification.Name ("RemoveObservers"),object: nil)
40
+
51
41
 
52
42
  call.resolve(["value": "Video call initiated"])
53
43
  }
@@ -78,6 +68,15 @@ public class vonagePlugin: CAPPlugin {
78
68
  @objc func removeObservers(_ notification: Notification){
79
69
  NotificationCenter.default.removeObserver(self)
80
70
  }
71
+ func videoCallStarted(_ data: [String: Any]){
72
+ self.notifyListeners(NotificationNames.videoStarted, data: data)
73
+ }
74
+ func videoCallEnded(_ data: [String: Any]){
75
+ self.notifyListeners(NotificationNames.videoEnded, data: data)
76
+ }
77
+ func videoCallSendNotification(_ data: [String: Any]){
78
+ self.notifyListeners("SendNotification", data: data)
79
+ }
81
80
  }
82
81
  extension UIApplication {
83
82
  class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
@@ -102,3 +101,8 @@ struct NotificationNames {
102
101
  static let videoStarted = "VideoCallStarted"
103
102
  static let videoEnded = "VideoCallEnded"
104
103
  }
104
+ protocol VonageSDKInteractionDelegate: AnyObject {
105
+ func videoCallStarted(_ data: [String: Any])
106
+ func videoCallEnded(_ data: [String: Any])
107
+ func videoCallSendNotification(_ data: [String: Any])
108
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-vonage",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "opentok sdk capacitor plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,36 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
- xmlns:app="http://schemas.android.com/apk/res-auto"
4
- xmlns:tools="http://schemas.android.com/tools"
5
- android:layout_width="match_parent"
6
- android:layout_height="match_parent"
7
- tools:context=".VideoCallActivity">
8
-
9
- <FrameLayout
10
- android:layout_width="fill_parent"
11
- android:layout_height="fill_parent"
12
- app:layout_constraintBottom_toBottomOf="parent"
13
- app:layout_constraintEnd_toEndOf="parent"
14
- app:layout_constraintStart_toStartOf="parent"
15
- android:background="#DDDDDD"
16
- app:layout_constraintTop_toTopOf="parent">
17
-
18
- <FrameLayout
19
- android:id="@+id/subscriber_container"
20
- android:layout_width="fill_parent"
21
- android:layout_height="fill_parent" />
22
-
23
- <FrameLayout
24
- android:id="@+id/publisher_container"
25
- android:layout_width="90dp"
26
- android:layout_height="120dp"
27
- android:layout_gravity="bottom|end"
28
- android:layout_marginEnd="16dp"
29
- android:layout_marginRight="16dp"
30
- android:layout_marginBottom="16dp"
31
- android:background="#FFFFFF"
32
- android:padding="2dp" />
33
-
34
- </FrameLayout>
35
-
36
- </androidx.constraintlayout.widget.ConstraintLayout>