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