Source: directives/voip/voip.js

  1. /**
  2. * @ngdoc directives
  3. * @name Voip
  4. * @module s4c.directives.voip.Voip
  5. *
  6. * @description
  7. * `voipCtrl` Responsável por exibir as funções do voip na tela, bem como o seu funcionamento
  8. * também possui acesso a api do backe
  9. *
  10. *@example
  11. * <s4c-voip>
  12. * </s4c-voip>
  13. */
  14. (function () {
  15. 'use strict';
  16. voipCtrl.$inject = [
  17. '$scope',
  18. '$http',
  19. '$mdDialog',
  20. '$state',
  21. 'API_ENDPOINT',
  22. '$q',
  23. 'TarefaService',
  24. 'MainState',
  25. 'CommService',
  26. 'AuthService',
  27. 'TarefaManager',
  28. 'localize',
  29. 'CamadasService',
  30. 'Base',
  31. 'Usuario',
  32. 'ParametrosS4C',
  33. 'DetalhamentoManager',
  34. 'MapaService',
  35. 'VoipManager',
  36. 'VoipService'
  37. ];
  38. /** This is a description of the voip function. */
  39. function voipCtrl($scope, $http, $mdDialog, $state,
  40. API_ENDPOINT, $q, TarefaService, MainState, CommService, AuthService, TarefaManager, localize, CamadasService, Base, Usuario, ParametrosS4C, DetalhamentoManager, MapaService, VoipManager, VoipService) {
  41. $scope.res = $scope.$root.res;
  42. var ringtone_ = document.getElementById("ringtone");
  43. var ringbacktone_ = document.getElementById("ringbacktone");
  44. var audioRemote = document.getElementById("audio_remote");
  45. var audioLocal = document.getElementById("audio_remote");
  46. $("#voip_button").css('opacity', '0.5');
  47. /**
  48. * keybord numeric voip multivis Fusion
  49. *
  50. *@autor - Rafael Araujo
  51. *@param div classPai, textoBtn, input
  52. */
  53. $scope.numClick = function (classPai, textoBtn, input) {
  54. $('.' + classPai).on('click', function () {
  55. var num = $(this);
  56. var text = $.trim(num.find('.' + textoBtn).clone().children().remove().end().text());
  57. var telNumber = $(input);
  58. $(telNumber).val(telNumber.val() + text);
  59. // $('.campoTel').addClass('md-input-focused')
  60. $('#ramal').focus()
  61. });
  62. };
  63. /**
  64. * Limpar campo
  65. *
  66. *@autor - Rafael Araujo
  67. *@param Input, btnAcao
  68. */
  69. $scope.limparCampo = function (inputNumero, btnAcao) {
  70. $('.' + btnAcao).on('click', function () {
  71. var telNumber = $(inputNumero);
  72. $(telNumber).val('');
  73. });
  74. };
  75. $scope.numClick('num', 'txt', '[data-set="numero"]');
  76. $scope.limparCampo('[data-set="numero"]', 'limpar');
  77. /**
  78. * @method hangup
  79. * @param {*} ramal_
  80. */
  81. CommService.on('hangup', function (ramal_) {
  82. if (ramal_ != null && ramal_ == VoipService.usuarioRamal) {
  83. desligar();
  84. }
  85. });
  86. /**
  87. * @method mute
  88. * @param {*} ramal_
  89. */
  90. CommService.on('mute', function (ramal_) {
  91. if (ramal_ != null && ramal_ == VoipService.usuarioRamal) {
  92. mute();
  93. }
  94. });
  95. /**
  96. * @method readyCallback
  97. * @param {*} e
  98. */
  99. var readyCallback = function (e) {
  100. if (MainState.isToShow('voip')) {
  101. createSipStack(); // see next section
  102. }
  103. };
  104. /**
  105. * @method errorCallback
  106. * @param {*} e
  107. */
  108. var errorCallback = function (e) {
  109. console.error('Failed to initialize the engine: ' + e.message);
  110. }
  111. /**
  112. * @method eventsListener
  113. * @param {*} e
  114. */
  115. var eventsListener = function (e) {
  116. console.info('session event = ' + e.type);
  117. if (e.type == 'started') {
  118. login();
  119. }
  120. else if (e.type == 'i_new_message') { // incoming new SIP MESSAGE (SMS-like)
  121. acceptMessage(e);
  122. }
  123. else if (e.type == 'i_new_call') { // incoming audio/video call
  124. startRingTone();
  125. VoipService.sipSessionCall = e.newSession;
  126. VoipManager.abrir();
  127. $("#making_call").hide();
  128. $("#discador").hide();
  129. $("#dicador").hide();
  130. $("#receiving_call").show();
  131. $("#in_call").hide();
  132. $("#making_call_field").hide();
  133. $("#receiving_call_field").show();
  134. $('#ramal').focus()
  135. setTimeout(function () { $('#ramal').focus(); }, 500);
  136. VoipService.s_user_name = e.o_event.o_message.o_hdr_From.o_uri.s_user_name;
  137. VoipService.displayName = e.o_event.o_message.o_hdr_From.s_display_name;
  138. if (VoipService.displayName == null) {
  139. VoipService.displayName = VoipService.s_user_name;
  140. } else if (VoipService.displayName != null && VoipService.s_user_name != null) {
  141. VoipService.displayName += ", ramal " + VoipService.s_user_name;
  142. }
  143. $("#mensagem").text("Você está recebendo uma ligação do " + VoipService.displayName);
  144. } else if (e.type == 'connected' && e.session == VoipService.registerSession) {
  145. publishPresence();
  146. subscribePresence(VoipService.usuarioRamal); // watch johndoe's presence status change
  147. }
  148. else if (e.type == 'connected' && e.description == 'In Call') {
  149. if ($('#in_call').is(':visible')) {
  150. $("#mensagem").text("A chamada está ativa com o ramal " + VoipService.displayName);
  151. stopRingBackTone();
  152. }
  153. }
  154. else if (e.type == 'i_request_cancel' && e.description == 'Media Removed') {
  155. $("#mensagem").text("A ligação foi encerrada");
  156. stopRingTone();
  157. hangupCall(e);
  158. }
  159. else if (e.type == 'i_notify') {
  160. console.info('NOTIFY content = ' + e.getContentString());
  161. console.info('NOTIFY content-type = ' + e.getContentType());
  162. if (e.getContentType() == 'application/pidf+xml') {
  163. if (window.DOMParser) {
  164. var parser = new DOMParser();
  165. var xmlDoc = parser ? parser.parseFromString(e.getContentString(), "text/xml") : null;
  166. var presenceNode = xmlDoc ? xmlDoc.getElementsByTagName("presence")[0] : null;
  167. if (presenceNode) {
  168. var entityUri = presenceNode.getAttribute("entity");
  169. var tupleNode = presenceNode.getElementsByTagName("tuple")[0];
  170. if (entityUri && tupleNode) {
  171. var statusNode = tupleNode.getElementsByTagName("status")[0];
  172. if (statusNode) {
  173. var basicNode = statusNode.getElementsByTagName("basic")[0];
  174. if (basicNode) {
  175. console.info('Presence notification: Uri = ' + entityUri + ' status = ' + basicNode.textContent);
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. } else if (e.type == 'terminated' && e.description == 'Call terminated') {
  183. hangupCall(e);
  184. } else if (e.type == 'i_ao_request' && e.description == 'Busy Here') {
  185. stopRingBackTone();
  186. } else if (e.type == 'terminated' && e.description == 'Busy Here') {
  187. hangupCall(e);
  188. } else if (e.type == 'failed_to_start') {
  189. VoipService.isConnecting = false;
  190. $mdDialog.show($mdDialog.alert()
  191. .title($scope.res('COMUM_AVISO'))
  192. .content($scope.res('VOIP_CANNOT_CONECT'))
  193. .ok($scope.res('COMUM_OK')));
  194. $('#voip_button_div').attr('ng-click', '');
  195. $("#voip_button_div").click(function () {
  196. if (!VoipService.isConnecting && !VoipService.isConnected) {
  197. $mdDialog.show($mdDialog.alert()
  198. .title($scope.res('COMUM_AVISO'))
  199. .content($scope.res('VOIP_RETRY_CONECT'))
  200. .ok($scope.res('COMUM_OK')));
  201. createSipStack();
  202. }
  203. });
  204. }
  205. }
  206. /**
  207. * @method createSipStack
  208. */
  209. function createSipStack() {
  210. Usuario.obterPorId(AuthService.user.info.id).then(function (usuario) {
  211. if (ParametrosS4C.parametros.domainVoip == null || usuario.voipRamal == null || ParametrosS4C.parametros.urlServerVoip == null || usuario.senhaVoipRamal == null) {
  212. VoipService.isSetCorrectly = false;
  213. return;
  214. }
  215. try {
  216. if (ParametrosS4C.parametros.domainVoip != null && ParametrosS4C.parametros.urlServerVoip != null && !VoipService.isConnected && !VoipService.isConnecting) {
  217. VoipService.isConnecting = true;
  218. VoipService.isSetCorrectly = true;
  219. VoipService.usuarioRamal = usuario.voipRamal;
  220. VoipService.sipStack = new SIPml.Stack({
  221. realm: ParametrosS4C.parametros.domainVoip, // mandatory: domain name
  222. impi: usuario.voipRamal, // mandatory: authorization name (IMS Private Identity)
  223. impu: 'sip:' + usuario.voipRamal + '@' + ParametrosS4C.parametros.domainVoip, // mandatory: valid SIP Uri (IMS Public Identity)
  224. password: usuario.senhaVoipRamal, // optional
  225. ice_servers: [], // Array vazio para desabilitar o Stun / turn, quando a rede não tiver um nat.
  226. //display_name: 'Bob legend', // optional
  227. websocket_proxy_url: ParametrosS4C.parametros.urlServerVoip, // optional
  228. // outbound_proxy_url: 'udp://example.org:5060', // optional
  229. //enable_rtcweb_breaker: false, // optional
  230. events_listener: { events: '*', listener: eventsListener }, // optional: '*' means all events
  231. sip_headers: [ // optional
  232. { name: 'User-Agent', value: 'IM-client/OMA1.0 sipML5-v1.0.0.0' },
  233. { name: 'Organization', value: 'Doubango Telecom' }
  234. ]
  235. });
  236. VoipService.sipStack.start();
  237. }
  238. } catch (Err) {
  239. $mdDialog.show($mdDialog.alert()
  240. .title($scope.res('COMUM_AVISO'))
  241. .content($scope.res('VOIP_CANNOT_CONECT'))
  242. .ok($scope.res('COMUM_OK')));
  243. }
  244. });
  245. }
  246. /**
  247. * @method login
  248. */
  249. var login = function () {
  250. if (VoipService.sipStack == null) {
  251. _verfiyConfig();
  252. return;
  253. }
  254. VoipService.registerSession = VoipService.sipStack.newSession('register', {
  255. events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
  256. });
  257. //VoipService.registerSession.unregister();
  258. VoipService.registerSession.register();
  259. }
  260. /**
  261. * @method makeCall
  262. * @param {*} callid
  263. */
  264. var makeCall = function (callid) {
  265. if (VoipService.sipStack == null) {
  266. _verfiyConfig();
  267. return;
  268. }
  269. VoipService.sipSessionCall = VoipService.sipStack.newSession('call-audio', VoipService.oConfigMakeCall);
  270. VoipService.sipSessionCall.call(callid);
  271. startRingBackTone();
  272. }
  273. /**
  274. * @method acceptCall
  275. */
  276. var acceptCall = function () {
  277. VoipService.sipSessionCall.accept(VoipService.oConfigMakeCall);
  278. }
  279. /**
  280. * @method rejectCall
  281. */
  282. var rejectCall = function () {
  283. VoipService.displayName = '';
  284. VoipService.sipSessionCall.reject(VoipService.oConfigMakeCall); // e.newSession.reject() to reject the call
  285. }
  286. /**
  287. * @method hangupCall
  288. * @param {*} e
  289. */
  290. var hangupCall = function (e) {
  291. if (VoipService.sipStack == null) {
  292. _verfiyConfig();
  293. return;
  294. }
  295. if (e.session != null) {
  296. e.session.hangup({
  297. events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
  298. }); // e.newSession.reject() to reject the call
  299. }
  300. //publishPresence();
  301. //subscribePresence(VoipService.usuarioRamal);
  302. $("#making_call").show();
  303. $("#discador").show();
  304. $("#receiving_call").hide();
  305. $("#in_call").hide();
  306. $("#making_call_field").show();
  307. $("#receiving_call_field").hide();
  308. stopRingBackTone();
  309. VoipService.displayName = '';
  310. VoipService.b_mute = false;
  311. $("#mute").show();
  312. $("#sound").hide();
  313. }
  314. /**
  315. * @method sendMessage
  316. */
  317. var sendMessage = function () {
  318. if (VoipService.sipStack == null) {
  319. _verfiyConfig();
  320. return;
  321. }
  322. VoipService.messageSession = VoipService.sipStack.newSession('message', {
  323. events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
  324. });
  325. // VoipService.messageSession.send('johndoe', 'Pêche à la moule', 'text/plain;charset=utf-8');
  326. }
  327. /**
  328. * @method acceptMessage
  329. * @param {*} e
  330. */
  331. var acceptMessage = function (e) {
  332. if (VoipService.sipStack == null) {
  333. _verfiyConfig();
  334. return;
  335. }
  336. e.newSession.accept(); // e.newSession.reject(); to reject the message
  337. $mdDialog.show($mdDialog.alert()
  338. .title('SMS received')
  339. .content(e.getContentString())
  340. .ok($scope.res('COMUM_OK')));
  341. console.info('SMS-content = ' + e.getContentString() + ' and SMS-content-type = ' + e.getContentType());
  342. }
  343. /**
  344. * @method publishPresence
  345. */
  346. var publishPresence = function () {
  347. if (VoipService.sipStack == null) {
  348. _verfiyConfig();
  349. return;
  350. }
  351. VoipService.publishSession = VoipService.sipStack.newSession('publish', {
  352. events_listener: { events: '*', listener: eventsListener } // optional: '*' means all events
  353. });
  354. var contentType = 'application/pidf+xml';
  355. var content = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n' +
  356. '<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n' +
  357. ' xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"' +
  358. ' entity=\"sip:bob@example.com\">\n' +
  359. '<tuple id=\"s8794\">\n' +
  360. '<status>\n' +
  361. ' <basic>open</basic>\n' +
  362. ' <im:im>away</im:im>\n' +
  363. '</status>\n' +
  364. '<contact priority=\"0.8\">tel:+33600000000</contact>\n' +
  365. '<note xml:lang=\"fr\">Bonjour de Paris :)</note>\n' +
  366. '</tuple>\n' +
  367. '</presence>';
  368. // send the PUBLISH request
  369. VoipService.publishSession.publish(content, contentType, {
  370. expires: 200,
  371. sip_caps: [
  372. { name: '+g.oma.sip-im' },
  373. { name: '+sip.ice' },
  374. { name: 'language', value: '\"en,fr\"' }
  375. ],
  376. sip_headers: [
  377. { name: 'Event', value: 'presence' },
  378. { name: 'Organization', value: 'Doubango Telecom' }
  379. ]
  380. });
  381. }
  382. /**
  383. * @method subscribePresence
  384. * @param {*} to
  385. */
  386. var subscribePresence = function (to) {
  387. if (VoipService.sipStack == null) {
  388. _verfiyConfig();
  389. return;
  390. }
  391. VoipService.subscribeSession = VoipService.sipStack.newSession('subscribe', {
  392. expires: 200,
  393. events_listener: { events: '*', listener: eventsListener },
  394. sip_headers: [
  395. { name: 'Event', value: 'presence' }, // only notify for 'presence' events
  396. { name: 'Accept', value: 'application/pidf+xml' } // supported content types (COMMA-sparated)
  397. ],
  398. sip_caps: [
  399. { name: '+g.oma.sip-im', value: null },
  400. { name: '+audio', value: null },
  401. { name: 'language', value: '\"en,fr\"' }
  402. ]
  403. });
  404. // start watching for entity's presence status (You may track event type 'connected' to be sure that the request has been accepted by the server)
  405. //subscribeSession.unsubscribe();
  406. VoipService.subscribeSession.subscribe(to);
  407. VoipService.isConnected = true;
  408. VoipService.isConnecting = false;
  409. $("#voip_button").css('opacity', '1');
  410. }
  411. /**
  412. * @method startTalking
  413. */
  414. function startTalking() {
  415. try { audioRemote.play(); }
  416. catch (e) { }
  417. }
  418. /**
  419. * @method stopTalking
  420. */
  421. function stopTalking() {
  422. try { audioRemote.stop(); }
  423. catch (e) { }
  424. }
  425. /**
  426. * @method startRingTone
  427. */
  428. function startRingTone() {
  429. try { ringtone_.play(); }
  430. catch (e) { }
  431. }
  432. /**
  433. * @method stopRingTone
  434. */
  435. function stopRingTone() {
  436. try { ringtone_.pause(); }
  437. catch (e) { }
  438. }
  439. /**
  440. * @method startRingBackTone
  441. */
  442. function startRingBackTone() {
  443. try { ringbacktone_.play(); }
  444. catch (e) { }
  445. }
  446. /**
  447. * @method stopRingBackTone
  448. *
  449. */
  450. function stopRingBackTone() {
  451. try { ringbacktone_.pause(); }
  452. catch (e) { }
  453. }
  454. /**
  455. * Definição do Objeto oConfigMakeCall
  456. * @instance oConfigMakeCall
  457. */
  458. VoipService.oConfigMakeCall = {
  459. from: VoipService.usuarioRamal,
  460. audio_remote: audioRemote,
  461. //audio_local: audioLocal,
  462. events_listener: { events: '*', listener: eventsListener },
  463. sip_caps: [
  464. { name: '+g.oma.sip-im' },
  465. { name: 'language', value: '\"en,fr\"' }
  466. ]
  467. };
  468. /**
  469. * @method _verfiyConfig
  470. */
  471. function _verfiyConfig() {
  472. $mdDialog.show($mdDialog.alert()
  473. .title($scope.res('COMUM_AVISO'))
  474. .content($scope.res('CHECK_VOIP_CONFIG'))
  475. .ok($scope.res('COMUM_OK')));
  476. }
  477. /**
  478. * @method ligar
  479. * @param {*} ramal_
  480. */
  481. function ligar(ramal_) {
  482. if (VoipService.sipStack == null) {
  483. _verfiyConfig();
  484. return;
  485. }
  486. var ramal = null;
  487. if (ramal_ != null && ramal_ != "") {
  488. ramal = ramal_;
  489. } else if ($("#ramal").val() != null && $("#ramal").val() != "") {
  490. ramal = $("#ramal").val();
  491. }
  492. if (ramal != null) {
  493. makeCall(ramal);
  494. $("#making_call").hide();
  495. $("#discador").hide();
  496. $("#receiving_call").hide();
  497. $("#in_call").show();
  498. $("#making_call_field").hide();
  499. $("#receiving_call_field").show();
  500. $("#mensagem").text("Você está ligando para o ramal " + ramal);
  501. $("#ramal").val("");
  502. VoipService.displayName = ramal;
  503. Base.obter('pois/ramal/' + ramal).then(function (pois) {
  504. if (pois != null && pois.length > 0) {
  505. var latlng = {
  506. lat: pois[0].latitude,
  507. lng: pois[0].longitude
  508. };
  509. if (!DetalhamentoManager.samePoi(pois[0].id)) {
  510. DetalhamentoManager.abrirPoi(pois[0].id, latlng);
  511. CamadasService.ativarMenuCategoria(pois[0].CategoriumId);
  512. MapaService.voarPara([
  513. pois[0].longitude,
  514. pois[0].latitude
  515. ]);
  516. MapaService.piscarAzul(latlng);
  517. }
  518. }
  519. });
  520. } else {
  521. $mdDialog.show($mdDialog.alert()
  522. .title($scope.res('COMUM_AVISO'))
  523. .content($scope.res('INFORMAR_RAMAL'))
  524. .ok($scope.res('COMUM_OK')));
  525. }
  526. //document.getElementById("ligar").innerHTML = '<md-button class="md-primary md-raised" ng-click="desligar()" aria-label="Ligar" ><span class="ng-scope">Encerrar</span></md-button>';
  527. }
  528. /**
  529. * @method desligar
  530. */
  531. function desligar() {
  532. if (VoipService.sipStack == null) {
  533. _verfiyConfig();
  534. return;
  535. }
  536. VoipService.b_mute = false;
  537. $("#mute").show();
  538. $("#sound").hide();
  539. $("#making_call").show();
  540. $("#discador").show();
  541. $("#receiving_call").hide();
  542. $("#in_call").hide();
  543. $("#making_call_field").show();
  544. $("#receiving_call_field").hide();
  545. VoipService.displayName = '';
  546. //document.getElementById("ligar").innerHTML = '<md-button class="md-primary md-raised" ng-click="ligar()" aria-label="Ligar" ><span class="ng-scope">Ligar</span></md-button>';
  547. //document.getElementById("desligar").innerHTML = '<md-button class="md-primary md-raised" ng-click="desligar()" aria-label="Ligar" ></md-button>';
  548. VoipService.sipSessionCall.o_session.hangup({
  549. events_listener: { events: '*', listener: eventsListener }
  550. });
  551. stopRingBackTone();
  552. }
  553. /**
  554. * @method atender
  555. */
  556. function atender() {
  557. if (VoipService.sipStack == null) {
  558. _verfiyConfig();
  559. return;
  560. }
  561. stopRingTone();
  562. stopRingBackTone();
  563. acceptCall();
  564. $("#discador").hide();
  565. $("#making_call").hide();
  566. $("#receiving_call").hide();
  567. $("#in_call").show();
  568. $("#making_call_field").hide();
  569. $("#receiving_call_field").show();
  570. $("#mensagem").text("Ligação em andamento com o ramal " + VoipService.displayName);
  571. if (VoipService.s_user_name != null && VoipService.s_user_name != "") {
  572. Base.obter('pois/ramal/' + VoipService.s_user_name).then(function (pois) {
  573. if (pois != null && pois.length > 0) {
  574. var latlng = {
  575. lat: pois[0].latitude,
  576. lng: pois[0].longitude
  577. };
  578. Base.obter('date_server/time_millis').then(function (time_millis) {
  579. function openWindow(url) {
  580. var token = JSON.parse(window.sessionStorage.getItem('s4cToken')).access_token;
  581. url = url.replace("[token]", token);
  582. url += "&atendimento_voip=true&chave_incidente=" + time_millis;
  583. var win = window.open(url, "Abrir incidente", "toolbar=no,location=no,directories=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes,maximize=yes,width=" + screen.width + ",height=" + screen.height + ",top=0,left=0");
  584. }
  585. MapaService.voarPara([
  586. pois[0].longitude,
  587. pois[0].latitude
  588. ]);
  589. MapaService.piscarAzul(latlng);
  590. if (pois[0].extras && pois[0].extras.informacoes) {
  591. for (var index in pois[0].extras.informacoes) {
  592. if (pois[0].extras.informacoes[index].label == 'Comando_URL') {
  593. var Comando_URL = pois[0].extras.informacoes[index].valor;
  594. openWindow(Comando_URL);
  595. }
  596. }
  597. }
  598. });
  599. }
  600. });
  601. }
  602. }
  603. /**
  604. * @method rejeitar
  605. */
  606. function rejeitar() {
  607. if (VoipService.sipStack == null) {
  608. _verfiyConfig();
  609. return;
  610. }
  611. stopRingTone();
  612. rejectCall();
  613. $("#discador").show();
  614. $("#making_call").show();
  615. $("#receiving_call").hide();
  616. $("#in_call").hide();
  617. $("#making_call_field").show();
  618. $("#receiving_call_field").hide();
  619. $("#mensagem").text("");
  620. }
  621. /**
  622. * @method deslogar
  623. */
  624. function deslogar() {
  625. if (VoipService.sipStack != null) {
  626. VoipService.isConnected = false;
  627. try{
  628. VoipService.sipStack.stop();
  629. }
  630. catch(err){
  631. console.log("Não foi possível deslogar do voip:");
  632. }
  633. }
  634. }
  635. /**
  636. * @method mute
  637. *
  638. */
  639. function mute() {
  640. VoipService.b_mute = !VoipService.b_mute;
  641. if (VoipService.b_mute) {
  642. $("#mute").hide();
  643. $("#sound").show();
  644. } else {
  645. $("#mute").show();
  646. $("#sound").hide();
  647. }
  648. VoipService.sipSessionCall.o_session.set_mute('audio', VoipService.b_mute);
  649. }
  650. angular.extend($scope, {
  651. data: {},
  652. ligar: ligar,
  653. desligar: desligar,
  654. atender: atender,
  655. rejeitar: rejeitar,
  656. mute: mute,
  657. verificaMenuCarregado: verificaMenuCarregado,
  658. $apivoip: {
  659. ligar: ligar,
  660. desligar: desligar,
  661. atender: atender,
  662. rejeitar: rejeitar,
  663. deslogar: deslogar,
  664. mute: mute,
  665. createSipStack: createSipStack
  666. }
  667. });
  668. MainState.registerDirective('voip', $scope.$apivoip);
  669. $scope.$on('$destroy', function () {
  670. MainState.unregisterDirective('voip');
  671. });
  672. /**
  673. * @method verificaMenuCarregado
  674. */
  675. function verificaMenuCarregado() {
  676. if (!CamadasService.isLoaded && $state.current.name == "main") {
  677. setTimeout(function () {
  678. verificaMenuCarregado();
  679. }, 1000);
  680. } else {
  681. setTimeout(function () {
  682. var inicializado = SIPml.isInitialized();
  683. if (!inicializado) {
  684. SIPml.init(readyCallback, errorCallback);
  685. } else if (SIPml.isInitialized && VoipService.sipStack == null) {
  686. createSipStack();
  687. } else if (VoipService.isConnected && $state.current.name == "main") {
  688. $("#voip_button").css('opacity', '1');
  689. }
  690. }, 2000);
  691. }
  692. }
  693. if (MainState.isToShow('voip')) {
  694. verificaMenuCarregado();
  695. }
  696. }
  697. function s4cVoip() {
  698. return {
  699. restrict: 'EA',
  700. templateUrl: 'app/directives/voip/voip.html',
  701. replace: true,
  702. scope: {},
  703. controller: voipCtrl
  704. };
  705. }
  706. /**
  707. * @ngdoc overview
  708. * @name s4c.components.voip
  709. */
  710. angular.module('s4c.components.voip', [])
  711. .directive('s4cVoip', s4cVoip);
  712. }());