voip-callkit 0.0.1

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.
Files changed (44) hide show
  1. package/README.md +154 -0
  2. package/VoipCallkit.podspec +17 -0
  3. package/android/build.gradle +58 -0
  4. package/android/src/main/.DS_Store +0 -0
  5. package/android/src/main/AndroidManifest.xml +55 -0
  6. package/android/src/main/java/.DS_Store +0 -0
  7. package/android/src/main/java/com/.DS_Store +0 -0
  8. package/android/src/main/java/com/test/.DS_Store +0 -0
  9. package/android/src/main/java/com/test/callkit/.DS_Store +0 -0
  10. package/android/src/main/java/com/test/callkit/CallKitVoip.java +12 -0
  11. package/android/src/main/java/com/test/callkit/CallKitVoipPlugin.java +81 -0
  12. package/android/src/main/java/com/test/callkit/MyConnectionService.java +200 -0
  13. package/android/src/main/java/com/test/callkit/MyFirebaseMessagingService.java +90 -0
  14. package/android/src/main/java/com/test/callkit/androidcall/ApiCalls.java +48 -0
  15. package/android/src/main/java/com/test/callkit/androidcall/CallActivity.java +1223 -0
  16. package/android/src/main/java/com/test/callkit/androidcall/RetreivedTokenCallback.java +5 -0
  17. package/android/src/main/java/com/test/callkit/androidcall/SettingsActivity.java +174 -0
  18. package/android/src/main/java/com/test/callkit/androidcall/VoipBackgroundService.java +103 -0
  19. package/android/src/main/java/com/test/callkit/androidcall/VoipForegroundService.java +210 -0
  20. package/android/src/main/java/com/test/callkit/androidcall/VoipForegroundServiceActionReceiver.java +77 -0
  21. package/android/src/main/java/com/test/callkit/androidcall/util/CameraCapturerCompat.java +185 -0
  22. package/android/src/main/java/com/test/callkit/androidcall/util/CodecUtils.kt +23 -0
  23. package/android/src/main/java/com/test/callkit/androidcall/util/Dialog.java +37 -0
  24. package/android/src/main/res/.gitkeep +0 -0
  25. package/dist/docs.json +262 -0
  26. package/dist/esm/definitions.d.ts +19 -0
  27. package/dist/esm/definitions.js +2 -0
  28. package/dist/esm/definitions.js.map +1 -0
  29. package/dist/esm/index.d.ts +4 -0
  30. package/dist/esm/index.js +7 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/web.d.ts +8 -0
  33. package/dist/esm/web.js +11 -0
  34. package/dist/esm/web.js.map +1 -0
  35. package/dist/plugin.cjs.js +27 -0
  36. package/dist/plugin.cjs.js.map +1 -0
  37. package/dist/plugin.js +30 -0
  38. package/dist/plugin.js.map +1 -0
  39. package/ios/Plugin/CallKitVoip.swift +1 -0
  40. package/ios/Plugin/CallKitVoipPlugin.h +10 -0
  41. package/ios/Plugin/CallKitVoipPlugin.m +8 -0
  42. package/ios/Plugin/CallKitVoipPlugin.swift +129 -0
  43. package/ios/Plugin/Info.plist +24 -0
  44. package/package.json +78 -0
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # voip-callkit
2
+
3
+ capacitor plugin for callkit and voip
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install voip-callkit
9
+ npx cap sync
10
+ ```
11
+
12
+ ## API
13
+
14
+ <docgen-index>
15
+
16
+ * [`register(...)`](#register)
17
+ * [`incomingCall(...)`](#incomingcall)
18
+ * [`addListener('registration', ...)`](#addlistenerregistration)
19
+ * [`addListener('callAnswered', ...)`](#addlistenercallanswered)
20
+ * [`addListener('callStarted', ...)`](#addlistenercallstarted)
21
+ * [Interfaces](#interfaces)
22
+ * [Type Aliases](#type-aliases)
23
+
24
+ </docgen-index>
25
+
26
+ <docgen-api>
27
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
28
+
29
+ ### register(...)
30
+
31
+ ```typescript
32
+ register(options: { topic: string; }) => Promise<void>
33
+ ```
34
+
35
+ | Param | Type |
36
+ | ------------- | ------------------------------- |
37
+ | **`options`** | <code>{ topic: string; }</code> |
38
+
39
+ --------------------
40
+
41
+
42
+ ### incomingCall(...)
43
+
44
+ ```typescript
45
+ incomingCall(options: { from: string; }) => Promise<void>
46
+ ```
47
+
48
+ | Param | Type |
49
+ | ------------- | ------------------------------ |
50
+ | **`options`** | <code>{ from: string; }</code> |
51
+
52
+ --------------------
53
+
54
+
55
+ ### addListener('registration', ...)
56
+
57
+ ```typescript
58
+ addListener(eventName: 'registration', listenerFunc: (token: Token) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
59
+ ```
60
+
61
+ | Param | Type |
62
+ | ------------------ | ----------------------------------------------------------- |
63
+ | **`eventName`** | <code>'registration'</code> |
64
+ | **`listenerFunc`** | <code>(token: <a href="#token">Token</a>) =&gt; void</code> |
65
+
66
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
67
+
68
+ --------------------
69
+
70
+
71
+ ### addListener('callAnswered', ...)
72
+
73
+ ```typescript
74
+ addListener(eventName: 'callAnswered', listenerFunc: (callDate: CallData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
75
+ ```
76
+
77
+ | Param | Type |
78
+ | ------------------ | -------------------------------------------------------------------- |
79
+ | **`eventName`** | <code>'callAnswered'</code> |
80
+ | **`listenerFunc`** | <code>(callDate: <a href="#calldata">CallData</a>) =&gt; void</code> |
81
+
82
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
83
+
84
+ --------------------
85
+
86
+
87
+ ### addListener('callStarted', ...)
88
+
89
+ ```typescript
90
+ addListener(eventName: 'callStarted', listenerFunc: (callDate: CallData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
91
+ ```
92
+
93
+ | Param | Type |
94
+ | ------------------ | -------------------------------------------------------------------- |
95
+ | **`eventName`** | <code>'callStarted'</code> |
96
+ | **`listenerFunc`** | <code>(callDate: <a href="#calldata">CallData</a>) =&gt; void</code> |
97
+
98
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
99
+
100
+ --------------------
101
+
102
+
103
+ ### Interfaces
104
+
105
+
106
+ #### PluginListenerHandle
107
+
108
+ | Prop | Type |
109
+ | ------------ | ----------------------------------------- |
110
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
111
+
112
+
113
+ #### Token
114
+
115
+ | Prop | Type |
116
+ | ----------- | ------------------- |
117
+ | **`token`** | <code>string</code> |
118
+
119
+
120
+ #### CallData
121
+
122
+ | Prop | Type |
123
+ | ------------------ | ------------------- |
124
+ | **`connectionId`** | <code>string</code> |
125
+ | **`username`** | <code>string</code> |
126
+
127
+
128
+ #### MessageCallData
129
+
130
+ | Prop | Type |
131
+ | ---------------- | ---------------------- |
132
+ | **`type`** | <code>'message'</code> |
133
+ | **`callbackId`** | <code>string</code> |
134
+ | **`pluginId`** | <code>string</code> |
135
+ | **`methodName`** | <code>string</code> |
136
+ | **`options`** | <code>any</code> |
137
+
138
+
139
+ #### ErrorCallData
140
+
141
+ | Prop | Type |
142
+ | ----------- | ---------------------------------------------------------------------------------------------- |
143
+ | **`type`** | <code>'js.error'</code> |
144
+ | **`error`** | <code>{ message: string; url: string; line: number; col: number; errorObject: string; }</code> |
145
+
146
+
147
+ ### Type Aliases
148
+
149
+
150
+ #### CallData
151
+
152
+ <code><a href="#messagecalldata">MessageCallData</a> | <a href="#errorcalldata">ErrorCallData</a></code>
153
+
154
+ </docgen-api>
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'VoipCallkit'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '12.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ jcenter()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:4.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
25
+ versionCode 1
26
+ versionName "1.0"
27
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
+ }
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ }
34
+ }
35
+ lintOptions {
36
+ abortOnError false
37
+ }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_1_8
40
+ targetCompatibility JavaVersion.VERSION_1_8
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ google()
46
+ mavenCentral()
47
+ jcenter()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }
Binary file
@@ -0,0 +1,55 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.test.callkit">
3
+
4
+ <uses-permission android:name="android.permission.CALL_PHONE"/>
5
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
6
+ <uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
7
+ <uses-permission android:name="android.permission.INTERNET" />
8
+
9
+ <uses-permission android:name="android.permission.VIBRATE" />
10
+
11
+ <application
12
+ android:usesCleartextTraffic="true"
13
+ >
14
+ <activity
15
+ android:name=".androidcall.CallActivity"
16
+ android:label="@string/app_name"
17
+ android:launchMode="singleTop"
18
+ android:configChanges="locale"
19
+
20
+ android:turnScreenOn="true"
21
+ android:autoRemoveFromRecents="true"
22
+ android:showWhenLocked="true"
23
+ android:windowSoftInputMode="adjustResize|stateHidden"
24
+ android:screenOrientation="portrait"
25
+ android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
26
+ <service android:name="com.test.callkit.MyConnectionService"
27
+ android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"
28
+ android:exported="false">
29
+ <intent-filter>
30
+ <action android:name="android.telecom.ConnectionService" />
31
+ </intent-filter>
32
+ </service>
33
+ <service
34
+ android:name="com.test.callkit.androidcall.VoipForegroundService"
35
+ android:enabled="true"
36
+ android:stopWithTask="true"
37
+ android:exported="true"></service>
38
+ <receiver
39
+ android:name="com.test.callkit.androidcall.VoipForegroundServiceActionReceiver">
40
+ </receiver>
41
+ <service
42
+ android:name="com.test.callkit.androidcall.VoipBackgroundService"
43
+ android:enabled="true"
44
+ android:exported="false"
45
+ android:stopWithTask="true">
46
+
47
+ </service>
48
+ <service
49
+ android:name="com.test.callkit.MyFirebaseMessagingService">
50
+ <intent-filter>
51
+ <action android:name="com.google.firebase.MESSAGING_EVENT" />
52
+ </intent-filter>
53
+ </service>
54
+ </application>
55
+ </manifest>
Binary file
@@ -0,0 +1,12 @@
1
+ package com.test.callkit;
2
+
3
+ import android.util.Log;
4
+
5
+ public class CallKitVoip {
6
+
7
+ public String echo(String value) {
8
+
9
+ Log.d("CallKitVoip","called");
10
+ return value;
11
+ }
12
+ }
@@ -0,0 +1,81 @@
1
+ package com.test.callkit;
2
+
3
+ import com.getcapacitor.Bridge;
4
+ import com.getcapacitor.JSObject;
5
+ import com.getcapacitor.Logger;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginHandle;
9
+ import com.getcapacitor.PluginMethod;
10
+ import com.google.firebase.messaging.FirebaseMessaging;
11
+
12
+
13
+ import android.content.Context;
14
+ import android.util.Log;
15
+ import android.widget.Toast;
16
+
17
+ import androidx.annotation.NonNull;
18
+ import androidx.annotation.RequiresApi;
19
+
20
+ public class CallKitVoipPlugin extends Plugin {
21
+ public static Bridge staticBridge = null;
22
+ public MyFirebaseMessagingService messagingService;
23
+
24
+
25
+ @Override
26
+ public void load(){
27
+ staticBridge = this.bridge;
28
+
29
+
30
+ this.getActivity().getApplicationContext();
31
+
32
+ }
33
+
34
+ @PluginMethod
35
+ public void register(PluginCall call) {
36
+ final String topicName = call.getString("userToken");
37
+ Log.d("CallKitVoip","register");
38
+
39
+ if(topicName == null){
40
+ call.reject("Topic name hasn't been specified correctly");
41
+ return;
42
+ }
43
+ FirebaseMessaging
44
+ .getInstance()
45
+ .subscribeToTopic(topicName)
46
+ .addOnSuccessListener(unused -> {
47
+ JSObject ret = new JSObject();
48
+ Logger.debug("CallKit: Subscribed");
49
+ ret.put("message", "Subscribed to topic " + topicName);
50
+ call.resolve(ret);
51
+
52
+ })
53
+ .addOnFailureListener(e -> {
54
+ Logger.debug("CallKit: Cannot subscribe");
55
+ call.reject("Cant subscribe to topic" + topicName);
56
+ });
57
+ call.resolve();
58
+ }
59
+ public void notifyEvent(String eventName, String username, String connectionId){
60
+ Log.d("notifyEvent",eventName + " " + username + " " + connectionId);
61
+
62
+ // JSObject data = new JSObject();
63
+ // data.put("username", username);
64
+ // data.put("connectionId", connectionId);
65
+ // notifyListeners("callAnswered", data);
66
+ }
67
+
68
+
69
+
70
+ public static CallKitVoipPlugin getInstance() {
71
+ if (staticBridge == null || staticBridge.getWebView() == null)
72
+ return null;
73
+
74
+ PluginHandle handler = staticBridge.getPlugin("CallKitVoip");
75
+
76
+ return handler == null
77
+ ? null
78
+ : (CallKitVoipPlugin) handler.getInstance();
79
+ }
80
+
81
+ }
@@ -0,0 +1,200 @@
1
+ package com.test.callkit;
2
+
3
+ import android.content.Intent;
4
+ import android.graphics.drawable.Icon;
5
+ import android.os.Build;
6
+ import android.os.Bundle;
7
+ import android.telecom.Connection;
8
+ import android.telecom.ConnectionRequest;
9
+ import android.telecom.ConnectionService;
10
+ import android.telecom.DisconnectCause;
11
+ import android.telecom.PhoneAccountHandle;
12
+ import android.telecom.StatusHints;
13
+ import android.telecom.TelecomManager;
14
+ import android.os.Handler;
15
+ import android.net.Uri;
16
+ import java.util.ArrayList;
17
+ import android.util.Log;
18
+
19
+ import androidx.annotation.RequiresApi;
20
+
21
+ import com.getcapacitor.Logger;
22
+
23
+ @RequiresApi(api = Build.VERSION_CODES.M)
24
+ public class MyConnectionService extends ConnectionService {
25
+
26
+ private static String TAG = "MyConnectionService";
27
+ private static Connection conn;
28
+
29
+ public static Connection getConnection() {
30
+ return conn;
31
+ }
32
+
33
+ public static void deinitConnection() {
34
+ conn = null;
35
+ }
36
+
37
+ @RequiresApi(api = Build.VERSION_CODES.M)
38
+ @Override
39
+ public Connection onCreateIncomingConnection(final PhoneAccountHandle connectionManagerPhoneAccount, final ConnectionRequest request) {
40
+ final Connection connection = new Connection() {
41
+ @RequiresApi(api = Build.VERSION_CODES.O)
42
+ @Override
43
+ public void onAnswer() {
44
+ this.setActive();
45
+ CallKitVoipPlugin plugin = CallKitVoipPlugin.getInstance();
46
+
47
+
48
+
49
+ if(plugin != null)
50
+ plugin.notifyEvent("callAnswered",
51
+ request.getExtras().getString("username"),
52
+ request.getExtras().getString("connectionId")
53
+ );
54
+
55
+
56
+ Intent launchIntent = getPackageManager().getLaunchIntentForPackage("app.appname");
57
+ if (launchIntent != null) {
58
+ startActivity(launchIntent);//null pointer check in case package name was not found
59
+ }
60
+
61
+ this.setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
62
+
63
+ }
64
+
65
+ @Override
66
+ public void onReject() {
67
+ DisconnectCause cause = new DisconnectCause(DisconnectCause.REJECTED);
68
+ this.setDisconnected(cause);
69
+ this.destroy();
70
+ conn = null;
71
+ // ArrayList<CallbackContext> callbackContexts = AndroidCall.getCallbackContexts().get("reject");
72
+ // for (final CallbackContext callbackContext : callbackContexts) {
73
+ // AndroidCall.getCordova().getThreadPool().execute(new Runnable() {
74
+ // public void run() {
75
+ // PluginResult result = new PluginResult(PluginResult.Status.OK, "reject event called successfully");
76
+ // result.setKeepCallback(true);
77
+ // callbackContext.sendPluginResult(result);
78
+ // }
79
+ // });
80
+ // }
81
+ }
82
+
83
+ @Override
84
+ public void onAbort() {
85
+ super.onAbort();
86
+ }
87
+
88
+ @Override
89
+ public void onDisconnect() {
90
+ DisconnectCause cause = new DisconnectCause(DisconnectCause.LOCAL);
91
+ this.setDisconnected(cause);
92
+ this.destroy();
93
+ conn = null;
94
+ // ArrayList<CallbackContext> callbackContexts = AndroidCall.getCallbackContexts().get("hangup");
95
+ // for (final CallbackContext callbackContext : callbackContexts) {
96
+ // AndroidCall.getCordova().getThreadPool().execute(new Runnable() {
97
+ // public void run() {
98
+ // PluginResult result = new PluginResult(PluginResult.Status.OK, "hangup event called successfully");
99
+ // result.setKeepCallback(true);
100
+ // callbackContext.sendPluginResult(result);
101
+ // }
102
+ // });
103
+ // }
104
+ }
105
+ };
106
+ connection.setAddress(Uri.parse(request.getExtras().getString("from")), TelecomManager.PRESENTATION_ALLOWED);
107
+ // Icon icon = AndroidCall.getIcon();
108
+ // if(icon != null) {
109
+ // StatusHints statusHints = new StatusHints((CharSequence)"", icon, new Bundle());
110
+ // connection.setStatusHints(statusHints);
111
+ // }
112
+ conn = connection;
113
+ // ArrayList<CallbackContext> callbackContexts = AndroidCall.getCallbackContexts().get("receiveCall");
114
+ // for (final CallbackContext callbackContext : callbackContexts) {
115
+ // AndroidCall.getCordova().getThreadPool().execute(new Runnable() {
116
+ // public void run() {
117
+ // PluginResult result = new PluginResult(PluginResult.Status.OK, "receiveCall event called successfully");
118
+ // result.setKeepCallback(true);
119
+ // callbackContext.sendPluginResult(result);
120
+ // }
121
+ // });
122
+ // }
123
+ return connection;
124
+ }
125
+
126
+ @RequiresApi(api = Build.VERSION_CODES.M)
127
+ @Override
128
+ public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
129
+ final Connection connection = new Connection() {
130
+ @Override
131
+ public void onAnswer() {
132
+ super.onAnswer();
133
+ }
134
+
135
+ @Override
136
+ public void onReject() {
137
+ super.onReject();
138
+ }
139
+
140
+ @Override
141
+ public void onAbort() {
142
+ super.onAbort();
143
+ }
144
+
145
+ @Override
146
+ public void onDisconnect() {
147
+ DisconnectCause cause = new DisconnectCause(DisconnectCause.LOCAL);
148
+ this.setDisconnected(cause);
149
+ this.destroy();
150
+ conn = null;
151
+ // ArrayList<CallbackContext> callbackContexts = AndroidCall.getCallbackContexts().get("hangup");
152
+ // for (final CallbackContext callbackContext : callbackContexts) {
153
+ // AndroidCall.getCordova().getThreadPool().execute(new Runnable() {
154
+ // public void run() {
155
+ // PluginResult result = new PluginResult(PluginResult.Status.OK, "hangup event called successfully");
156
+ // result.setKeepCallback(true);
157
+ // callbackContext.sendPluginResult(result);
158
+ // }
159
+ // });
160
+ // }
161
+ }
162
+
163
+ @Override
164
+ public void onStateChanged(int state) {
165
+ if(state == Connection.STATE_DIALING) {
166
+ final Handler handler = new Handler();
167
+ handler.postDelayed(new Runnable() {
168
+ @Override
169
+ public void run() {
170
+ // Intent intent = new Intent(AndroidCall.getCapacitor().getActivity().getApplicationContext(), AndroidCall.getCordova().getActivity().getClass());
171
+ // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
172
+ // AndroidCall.getCapacitor().getActivity().getApplicationContext().startActivity(intent);
173
+ }
174
+ }, 500);
175
+ }
176
+ }
177
+ };
178
+ connection.setAddress(Uri.parse(request.getExtras().getString("to")), TelecomManager.PRESENTATION_ALLOWED);
179
+ // Icon icon = AndroidCall.getIcon();
180
+ // if(icon != null) {
181
+ // StatusHints statusHints = new StatusHints((CharSequence)"", icon, new Bundle());
182
+ // connection.setStatusHints(statusHints);
183
+ // }
184
+ connection.setDialing();
185
+ conn = connection;
186
+ // ArrayList<CallbackContext> callbackContexts = AndroidCall.getCallbackContexts().get("sendCall");
187
+ // if(callbackContexts != null) {
188
+ // for (final CallbackContext callbackContext : callbackContexts) {
189
+ // AndroidCall.getCordova().getThreadPool().execute(new Runnable() {
190
+ // public void run() {
191
+ // PluginResult result = new PluginResult(PluginResult.Status.OK, "sendCall event called successfully");
192
+ // result.setKeepCallback(true);
193
+ // callbackContext.sendPluginResult(result);
194
+ // }
195
+ // });
196
+ // }
197
+ // }
198
+ return connection;
199
+ }
200
+ }
@@ -0,0 +1,90 @@
1
+ package com.test.callkit;
2
+
3
+
4
+ import android.annotation.SuppressLint;
5
+ import android.app.ActivityManager;
6
+ import android.content.Intent;
7
+ import android.os.Build;
8
+ import android.util.Log;
9
+
10
+ import androidx.annotation.RequiresApi;
11
+
12
+ import com.test.callkit.androidcall.VoipBackgroundService;
13
+ import com.google.firebase.messaging.FirebaseMessagingService;
14
+ import com.google.firebase.messaging.RemoteMessage;
15
+
16
+
17
+ /**
18
+ * NOTE: There can only be one service in each app that receives FCM messages. If multiple
19
+ * are declared in the Manifest then the first one will be chosen.
20
+ * <p>
21
+ * In order to make this Java sample functional, you must remove the following from the Kotlin messaging
22
+ * service in the AndroidManifest.xml:
23
+ * <p>
24
+ * <intent-filter>
25
+ * <action android:name="com.google.firebase.MESSAGING_EVENT" />
26
+ * </intent-filter>
27
+ */
28
+ @SuppressLint("MissingFirebaseInstanceTokenRefresh")
29
+ public class MyFirebaseMessagingService extends FirebaseMessagingService {
30
+
31
+ private static final String TAG = "MyFirebaseMsgService";
32
+
33
+ public MyFirebaseMessagingService() {
34
+ super();
35
+ Log.d(TAG, "class instantiated");
36
+ }
37
+
38
+ /**
39
+ * Called when message is received.
40
+ *
41
+ * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
42
+ */
43
+
44
+ @Override
45
+ public void onMessageReceived(RemoteMessage remoteMessage) {
46
+ Log.d(TAG, "received " + remoteMessage.getData());
47
+
48
+ if (remoteMessage.getData().containsKey("type") && remoteMessage.getData().get("type").equals("call")) {
49
+ show_call_notification(remoteMessage.getData().get("connectionId"), remoteMessage.getData().get("username"));
50
+ }
51
+
52
+ if (remoteMessage.getData().containsKey("type") && remoteMessage.getData().get("type").equals("stopCall")) {
53
+
54
+ }
55
+
56
+ private boolean isServiceRunning(String service_name) {
57
+ ActivityManager manager = (ActivityManager) getApplicationContext().getSystemService(getApplicationContext().ACTIVITY_SERVICE);
58
+ for (ActivityManager.RunningServiceInfo service_running : manager.getRunningServices(Integer.MAX_VALUE)) {
59
+ if (service_name.equals(service_running.service.getClassName())) {
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+
66
+ public void show_call_notification(String connectionId, String username) {
67
+ Intent voip_service = new Intent(getApplicationContext(), VoipBackgroundService.class);
68
+ voip_service.putExtra("connectionId", connectionId);
69
+ voip_service.putExtra("username", username);
70
+ Log.d("show_call_notification", "called");
71
+
72
+ if (!isServiceRunning("com.test.callkit.androidcall.VoipBackgroundService")) {
73
+ try {
74
+ getApplicationContext().startService(voip_service);
75
+ } catch (Exception e) {
76
+ }
77
+ } else {
78
+ try {
79
+ getApplicationContext().stopService(voip_service);
80
+ } catch (Exception e) {
81
+ }
82
+ try {
83
+ getApplicationContext().startService(voip_service);
84
+ } catch (Exception e) {
85
+ Log.d("sip_call_init", e.toString());
86
+ }
87
+ }
88
+
89
+ }
90
+ }