Browse Source

Novos pacotes para capturar recursos externos e mais verbose para debug

dev-home
Matheo Bonucia 3 months ago
parent
commit
8d5647c760
  1. 41
      asset/context/CallContext.js
  2. 2
      asset/screens/ConfigScreen/ConfigScreen.js
  3. 29
      package-lock.json
  4. 1
      package.json

41
asset/context/CallContext.js

@ -9,7 +9,7 @@ import React, {
import {StackActions, useNavigation} from '@react-navigation/native'; import {StackActions, useNavigation} from '@react-navigation/native';
import InCallManager from 'react-native-incall-manager'; import InCallManager from 'react-native-incall-manager';
import JsSIP from 'react-native-jssip'; import JsSIP from 'react-native-jssip';
import {Alert} from 'react-native'; import {Alert, Platform} from 'react-native';
import {AuthContext} from './AuthContext'; import {AuthContext} from './AuthContext';
export const CallContext = createContext(); export const CallContext = createContext();
@ -30,6 +30,8 @@ export const CallProvider = ({children}) => {
const [statusColor, setStatusColor] = useState('black'); const [statusColor, setStatusColor] = useState('black');
const [currentAlert, setCurrentAlert] = useState(null); const [currentAlert, setCurrentAlert] = useState(null);
JsSIP.debug.enable('JsSIP:*');
const controlStatus = status => { const controlStatus = status => {
switch (status) { switch (status) {
case 'registrado': case 'registrado':
@ -68,10 +70,12 @@ export const CallProvider = ({children}) => {
const setupPhone = authData => { const setupPhone = authData => {
const {servidor, porta, ramal, senha, username} = authData; const {servidor, porta, ramal, senha, username} = authData;
const protocolo = 'ws';
const socket = new JsSIP.WebSocketInterface( const socket = new JsSIP.WebSocketInterface(
`${'ws'}://${servidor}:${porta}/ws`, `${protocolo}://${servidor}:${porta}/ws`,
); );
const configuration = { const configuration = {
uri: `sip:${ramal}@${servidor}`, uri: `sip:${ramal}@${servidor}`,
password: senha, password: senha,
@ -82,7 +86,7 @@ export const CallProvider = ({children}) => {
hack_via_ws: true, hack_via_ws: true,
display_name: username !== null ? username : ramal, display_name: username !== null ? username : ramal,
user_agent: 'Softphone React Native', user_agent: 'Softphone React Native',
contact_uri: `sip:${ramal}@${servidor};transport=${'ws'}`, contact_uri: `sip:${ramal}@${servidor};transport=${protocolo}`,
pcConfig: { pcConfig: {
iceServers: [ iceServers: [
{urls: 'stun:stun.l.google.com:19302'}, {urls: 'stun:stun.l.google.com:19302'},
@ -99,6 +103,34 @@ export const CallProvider = ({children}) => {
const phone = new JsSIP.UA(configuration); const phone = new JsSIP.UA(configuration);
phone.on('connecting', () => {
console.log('JsSIP: Conectando ao servidor...');
});
phone.on('connected', () => {
console.log('JsSIP: Conexão estabelecida com sucesso.');
});
phone.on('disconnected', data => {
console.warn('JsSIP: Desconectado do servidor.', data);
});
phone.on('newMessage', data => {
console.log('JsSIP: Nova mensagem recebida.', data);
});
phone.on('newRTCSession', data => {
console.log('JsSIP: Nova sessão RTC estabelecida.', data);
});
phone.on('registrationFailed', data => {
console.error('JsSIP: Falha no registro.', data);
});
phone.on('error', data => {
console.error('JsSIP: Erro ocorrido.', data);
});
phone.on('registrationFailed', function (ev) { phone.on('registrationFailed', function (ev) {
console.log('Registering on SIP server failed with error: ' + ev.cause); console.log('Registering on SIP server failed with error: ' + ev.cause);
configuration.uri = null; configuration.uri = null;
@ -235,6 +267,9 @@ export const CallProvider = ({children}) => {
} }
}); });
phone.start(); phone.start();
if (Platform.OS === 'android' && !__DEV__) {
console.log = () => {}; // Suprimir logs no APK release fora do modo de desenvolvimento
}
setUa(phone); setUa(phone);
}; };
const cleanup = () => { const cleanup = () => {

2
asset/screens/ConfigScreen/ConfigScreen.js

@ -32,7 +32,7 @@ const ConfigScreen = () => {
value={authData.servidor || ''} value={authData.servidor || ''}
onChangeText={value => handleInputChange('servidor', value)} onChangeText={value => handleInputChange('servidor', value)}
placeholder="Servidor" placeholder="Servidor"
keyboardType="number-pad" keyboardType="default"
/> />
<LabeledInput <LabeledInput
label="Porta" label="Porta"

29
package-lock.json generated

@ -17,6 +17,7 @@
"react-native": "^0.73.0", "react-native": "^0.73.0",
"react-native-animatable": "^1.4.0", "react-native-animatable": "^1.4.0",
"react-native-encrypted-storage": "^4.0.3", "react-native-encrypted-storage": "^4.0.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.17.1", "react-native-gesture-handler": "^2.17.1",
"react-native-incall-manager": "^4.2.0", "react-native-incall-manager": "^4.2.0",
"react-native-jssip": "^3.7.6", "react-native-jssip": "^3.7.6",
@ -7026,6 +7027,11 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/base-64": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
"integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA=="
},
"node_modules/base/node_modules/define-property": { "node_modules/base/node_modules/define-property": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz", "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz",
@ -15854,6 +15860,24 @@
"react-native": "*" "react-native": "*"
} }
}, },
"node_modules/react-native-fs": {
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.20.0.tgz",
"integrity": "sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ==",
"dependencies": {
"base-64": "^0.1.0",
"utf8": "^3.0.0"
},
"peerDependencies": {
"react-native": "*",
"react-native-windows": "*"
},
"peerDependenciesMeta": {
"react-native-windows": {
"optional": true
}
}
},
"node_modules/react-native-gesture-handler": { "node_modules/react-native-gesture-handler": {
"version": "2.17.1", "version": "2.17.1",
"resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.17.1.tgz", "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.17.1.tgz",
@ -21463,6 +21487,11 @@
"which": "bin/which" "which": "bin/which"
} }
}, },
"node_modules/utf8": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz",
"integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ=="
},
"node_modules/util-deprecate": { "node_modules/util-deprecate": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

1
package.json

@ -19,6 +19,7 @@
"react-native": "^0.73.0", "react-native": "^0.73.0",
"react-native-animatable": "^1.4.0", "react-native-animatable": "^1.4.0",
"react-native-encrypted-storage": "^4.0.3", "react-native-encrypted-storage": "^4.0.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.17.1", "react-native-gesture-handler": "^2.17.1",
"react-native-incall-manager": "^4.2.0", "react-native-incall-manager": "^4.2.0",
"react-native-jssip": "^3.7.6", "react-native-jssip": "^3.7.6",

Loading…
Cancel
Save