cordova-plugin-salus-call 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.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # cordova-plugin-salus-call
2
+
3
+ Plugin proprietário do Salus para integrar a interface Cordova ao ciclo de vida nativo de chamadas VoIP no Android e no iOS.
4
+
5
+ > Estado atual: a ponte Cordova e o contrato de eventos estão implementados. Android Telecom, WebRTC, PushKit e CallKit serão adicionados nas próximas versões.
6
+
7
+ ## Instalação
8
+
9
+ ```xml
10
+ <plugin name="cordova-plugin-salus-call" spec="0.1.0" />
11
+ ```
12
+
13
+ ## API
14
+
15
+ ```javascript
16
+ SalusCall.initialize(options);
17
+ SalusCall.getCapabilities();
18
+ SalusCall.startCall(call);
19
+ SalusCall.answer(callId);
20
+ SalusCall.reject(callId, reason);
21
+ SalusCall.hangup(callId, reason);
22
+ SalusCall.setMuted(muted);
23
+ SalusCall.setVideoEnabled(enabled);
24
+ SalusCall.switchCamera();
25
+ SalusCall.onEvent(listener, onError);
26
+ ```
27
+
28
+ Cada chamada utiliza um `callId` UUID fornecido pelo servidor. O ID do usuário nunca deve ser usado como ID de sala.
29
+
30
+ ## Publicação para o Volt Builder
31
+
32
+ O plano Pro do Volt Builder instala plugins disponíveis no npm. Depois da publicação:
33
+
34
+ 1. adicionar a versão publicada ao `config.xml` do aplicativo;
35
+ 2. enviar o projeto ao Volt Builder sem depender da cópia local do plugin;
36
+ 3. confirmar no log do build a instalação de `cordova-plugin-salus-call@0.1.0`.
37
+
38
+ ## Licença
39
+
40
+ Código proprietário. Todos os direitos reservados.
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "cordova-plugin-salus-call",
3
+ "version": "0.1.0",
4
+ "description": "Integração nativa de chamadas VoIP para o aplicativo Salus.",
5
+ "license": "UNLICENSED",
6
+ "private": false,
7
+ "main": "www/SalusCall.js",
8
+ "files": [
9
+ "plugin.xml",
10
+ "www/",
11
+ "src/",
12
+ "README.md"
13
+ ],
14
+ "keywords": [
15
+ "ecosystem:cordova",
16
+ "cordova-android",
17
+ "cordova-ios",
18
+ "voip",
19
+ "webrtc",
20
+ "callkit",
21
+ "telecom"
22
+ ],
23
+ "cordova": {
24
+ "id": "cordova-plugin-salus-call",
25
+ "platforms": [
26
+ "android",
27
+ "ios"
28
+ ]
29
+ },
30
+ "engines": {
31
+ "cordovaDependencies": {
32
+ "0.1.0": {
33
+ "cordova": ">=12.0.0",
34
+ "cordova-android": ">=14.0.0"
35
+ }
36
+ }
37
+ }
38
+ }
package/plugin.xml ADDED
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
+ xmlns:android="http://schemas.android.com/apk/res/android"
4
+ id="cordova-plugin-salus-call"
5
+ version="0.1.0">
6
+ <name>Salus Call</name>
7
+ <description>Ponte nativa para chamadas de interfone do Salus.</description>
8
+ <license>UNLICENSED</license>
9
+
10
+ <js-module src="www/SalusCall.js" name="SalusCall">
11
+ <clobbers target="SalusCall" />
12
+ </js-module>
13
+
14
+ <platform name="android">
15
+ <config-file target="res/xml/config.xml" parent="/*">
16
+ <feature name="SalusCall">
17
+ <param name="android-package" value="br.com.salus.call.SalusCallPlugin" />
18
+ </feature>
19
+ </config-file>
20
+ <source-file src="src/android/SalusCallPlugin.java"
21
+ target-dir="src/br/com/salus/call" />
22
+ </platform>
23
+
24
+ <platform name="ios">
25
+ <config-file target="config.xml" parent="/*">
26
+ <feature name="SalusCall">
27
+ <param name="ios-package" value="SalusCallPlugin" />
28
+ </feature>
29
+ </config-file>
30
+ <source-file src="src/ios/SalusCallPlugin.swift" />
31
+ </platform>
32
+ </plugin>
@@ -0,0 +1,68 @@
1
+ package br.com.salus.call;
2
+
3
+ import org.apache.cordova.CallbackContext;
4
+ import org.apache.cordova.CordovaPlugin;
5
+ import org.apache.cordova.PluginResult;
6
+ import org.json.JSONArray;
7
+ import org.json.JSONException;
8
+ import org.json.JSONObject;
9
+
10
+ public class SalusCallPlugin extends CordovaPlugin {
11
+ private CallbackContext eventCallback;
12
+
13
+ @Override
14
+ public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException {
15
+ switch (action) {
16
+ case "initialize":
17
+ JSONObject initialized = capabilities();
18
+ initialized.put("initialized", true);
19
+ callback.success(initialized);
20
+ return true;
21
+ case "getCapabilities":
22
+ callback.success(capabilities());
23
+ return true;
24
+ case "registerEventListener":
25
+ eventCallback = callback;
26
+ PluginResult listening = new PluginResult(PluginResult.Status.NO_RESULT);
27
+ listening.setKeepCallback(true);
28
+ callback.sendPluginResult(listening);
29
+ return true;
30
+ case "startCall":
31
+ case "answer":
32
+ case "reject":
33
+ case "hangup":
34
+ case "setMuted":
35
+ case "setVideoEnabled":
36
+ case "switchCamera":
37
+ callback.error(notImplemented(action));
38
+ return true;
39
+ default:
40
+ return false;
41
+ }
42
+ }
43
+
44
+ private JSONObject capabilities() throws JSONException {
45
+ JSONObject result = new JSONObject();
46
+ result.put("platform", "android");
47
+ result.put("nativeCalling", false);
48
+ result.put("audio", false);
49
+ result.put("video", false);
50
+ result.put("incomingCallUi", false);
51
+ return result;
52
+ }
53
+
54
+ private JSONObject notImplemented(String action) throws JSONException {
55
+ JSONObject error = new JSONObject();
56
+ error.put("code", "NATIVE_CALLING_NOT_IMPLEMENTED");
57
+ error.put("action", action);
58
+ error.put("message", "O núcleo Android Telecom/WebRTC ainda não foi ativado.");
59
+ return error;
60
+ }
61
+
62
+ protected void emitEvent(JSONObject event) {
63
+ if (eventCallback == null) return;
64
+ PluginResult result = new PluginResult(PluginResult.Status.OK, event);
65
+ result.setKeepCallback(true);
66
+ eventCallback.sendPluginResult(result);
67
+ }
68
+ }
@@ -0,0 +1,72 @@
1
+ import Foundation
2
+
3
+ @objc(SalusCallPlugin)
4
+ final class SalusCallPlugin: CDVPlugin {
5
+ private var eventCallbackId: String?
6
+
7
+ @objc(initialize:)
8
+ func initialize(command: CDVInvokedUrlCommand) {
9
+ var result = capabilities()
10
+ result["initialized"] = true
11
+ send(result, command.callbackId)
12
+ }
13
+
14
+ @objc(getCapabilities:)
15
+ func getCapabilities(command: CDVInvokedUrlCommand) {
16
+ send(capabilities(), command.callbackId)
17
+ }
18
+
19
+ @objc(registerEventListener:)
20
+ func registerEventListener(command: CDVInvokedUrlCommand) {
21
+ eventCallbackId = command.callbackId
22
+ let result = CDVPluginResult(status: CDVCommandStatus_NO_RESULT)
23
+ result?.setKeepCallbackAs(true)
24
+ commandDelegate.send(result, callbackId: command.callbackId)
25
+ }
26
+
27
+ @objc(startCall:)
28
+ func startCall(command: CDVInvokedUrlCommand) { notImplemented("startCall", command) }
29
+
30
+ @objc(answer:)
31
+ func answer(command: CDVInvokedUrlCommand) { notImplemented("answer", command) }
32
+
33
+ @objc(reject:)
34
+ func reject(command: CDVInvokedUrlCommand) { notImplemented("reject", command) }
35
+
36
+ @objc(hangup:)
37
+ func hangup(command: CDVInvokedUrlCommand) { notImplemented("hangup", command) }
38
+
39
+ @objc(setMuted:)
40
+ func setMuted(command: CDVInvokedUrlCommand) { notImplemented("setMuted", command) }
41
+
42
+ @objc(setVideoEnabled:)
43
+ func setVideoEnabled(command: CDVInvokedUrlCommand) { notImplemented("setVideoEnabled", command) }
44
+
45
+ @objc(switchCamera:)
46
+ func switchCamera(command: CDVInvokedUrlCommand) { notImplemented("switchCamera", command) }
47
+
48
+ private func capabilities() -> [String: Any] {
49
+ return [
50
+ "platform": "ios",
51
+ "nativeCalling": false,
52
+ "audio": false,
53
+ "video": false,
54
+ "incomingCallUi": false
55
+ ]
56
+ }
57
+
58
+ private func notImplemented(_ action: String, _ command: CDVInvokedUrlCommand) {
59
+ let error: [String: Any] = [
60
+ "code": "NATIVE_CALLING_NOT_IMPLEMENTED",
61
+ "action": action,
62
+ "message": "O núcleo PushKit/CallKit/WebRTC ainda não foi ativado."
63
+ ]
64
+ let result = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: error)
65
+ commandDelegate.send(result, callbackId: command.callbackId)
66
+ }
67
+
68
+ private func send(_ value: [String: Any], _ callbackId: String) {
69
+ let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: value)
70
+ commandDelegate.send(result, callbackId: callbackId)
71
+ }
72
+ }
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ var exec = require('cordova/exec');
4
+
5
+ var STATES = Object.freeze({
6
+ IDLE: 'idle',
7
+ INVITING: 'inviting',
8
+ RINGING: 'ringing',
9
+ CONNECTING: 'connecting',
10
+ ACTIVE: 'active',
11
+ ENDING: 'ending',
12
+ ENDED: 'ended',
13
+ FAILED: 'failed'
14
+ });
15
+
16
+ function callNative(action, args) {
17
+ return new Promise(function(resolve, reject) {
18
+ exec(resolve, reject, 'SalusCall', action, args || []);
19
+ });
20
+ }
21
+
22
+ function validateCall(call) {
23
+ if (!call || typeof call !== 'object') {
24
+ throw new TypeError('Os dados da chamada são obrigatórios.');
25
+ }
26
+ if (!call.callId) {
27
+ throw new TypeError('callId é obrigatório.');
28
+ }
29
+ if (!call.remoteUserId) {
30
+ throw new TypeError('remoteUserId é obrigatório.');
31
+ }
32
+ }
33
+
34
+ module.exports = {
35
+ STATES: STATES,
36
+
37
+ initialize: function(options) {
38
+ return callNative('initialize', [options || {}]);
39
+ },
40
+
41
+ getCapabilities: function() {
42
+ return callNative('getCapabilities');
43
+ },
44
+
45
+ startCall: function(call) {
46
+ validateCall(call);
47
+ return callNative('startCall', [call]);
48
+ },
49
+
50
+ answer: function(callId) {
51
+ return callNative('answer', [callId]);
52
+ },
53
+
54
+ reject: function(callId, reason) {
55
+ return callNative('reject', [callId, reason || 'declined']);
56
+ },
57
+
58
+ hangup: function(callId, reason) {
59
+ return callNative('hangup', [callId, reason || 'local_hangup']);
60
+ },
61
+
62
+ setMuted: function(muted) {
63
+ return callNative('setMuted', [Boolean(muted)]);
64
+ },
65
+
66
+ setVideoEnabled: function(enabled) {
67
+ return callNative('setVideoEnabled', [Boolean(enabled)]);
68
+ },
69
+
70
+ switchCamera: function() {
71
+ return callNative('switchCamera');
72
+ },
73
+
74
+ onEvent: function(listener, onError) {
75
+ if (typeof listener !== 'function') {
76
+ throw new TypeError('O listener de eventos deve ser uma função.');
77
+ }
78
+ exec(listener, onError || function() {}, 'SalusCall', 'registerEventListener', []);
79
+ }
80
+ };