您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

183 行
5.0 KiB

  1. import React, {Component} from 'react';
  2. import { StyleSheet, Text, FlatList } from 'react-native';
  3. import { Container, Header, Content, List, ListItem, Left, Body, Right, Title, Button, Icon, View } from 'native-base';
  4. import { api_url, faq, font_title, font_description, get_access_token_for_voice } from '../config/Constants';
  5. import * as colors from '../assets/css/Colors';
  6. import Accordian from '../config/Accordian';
  7. import axios from 'axios';
  8. import TwilioVoice from 'react-native-twilio-programmable-voice';
  9. import {request, check, PERMISSIONS, RESULTS} from 'react-native-permissions';
  10. export default class Call extends Component<Props> {
  11. constructor(props) {
  12. super(props)
  13. this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
  14. this.state={
  15. accessToken:'',
  16. isLoding:false
  17. }
  18. this.permission_check();
  19. this.initTelephony();
  20. TwilioVoice.connect({To: 'kiruthika'})
  21. }
  22. permission_check(){
  23. /*check(PERMISSIONS.ANDROID.RECORD_AUDIO)
  24. .then((result) => {
  25. switch (result) {
  26. case RESULTS.UNAVAILABLE:
  27. alert(
  28. 'This feature is not available (on this device / in this context)',
  29. );
  30. break;
  31. case RESULTS.DENIED:
  32. alert(
  33. 'The permission has not been requested / is denied but requestable',
  34. );
  35. break;
  36. case RESULTS.GRANTED:
  37. alert('The permission is granted');
  38. break;
  39. case RESULTS.BLOCKED:
  40. alert('The permission is denied and not requestable anymore');
  41. break;
  42. }
  43. })
  44. .catch((error) => {
  45. // …
  46. });*/
  47. request(PERMISSIONS.ANDROID.RECORD_AUDIO).then((result) => {
  48. // …
  49. });
  50. }
  51. handleBackButtonClick= () => {
  52. this.props.navigation.goBack(null);
  53. }
  54. async initTelephony() {
  55. try {
  56. await this.getAccessTokenFromServer();
  57. const success = await TwilioVoice.initWithToken(this.state.accessToken);
  58. } catch (err) {
  59. console.log(err)
  60. }
  61. }
  62. getAccessTokenFromServer = async () => {
  63. this.setState({ isLoding : true });
  64. await axios({
  65. method: "get",
  66. url: api_url + get_access_token_for_voice+'/sarath'
  67. })
  68. .then(async (response) => {
  69. this.setState({ isLoding : false });
  70. this.setState({ accessToken : response.data.result});
  71. })
  72. .catch((error) => {
  73. this.setState({ isLoding : false });
  74. });
  75. };
  76. initTelephonyWithToken(token) {
  77. TwilioVoice.initWithAccessToken(token)
  78. // iOS only, configure CallKit
  79. try {
  80. TwilioVoice.configureCallKit({
  81. appName: 'TwilioVoiceExample', // Required param
  82. imageName: 'my_image_name_in_bundle', // OPTIONAL
  83. ringtoneSound: 'my_ringtone_sound_filename_in_bundle' // OPTIONAL
  84. })
  85. } catch (err) {
  86. console.err(err)
  87. }
  88. }
  89. componentDidMount(){
  90. TwilioVoice.addEventListener('deviceReady', function() {
  91. });
  92. TwilioVoice.addEventListener('deviceNotReady', function(data) {
  93. })
  94. TwilioVoice.addEventListener('connectionDidConnect', function(data) {
  95. // {
  96. // call_sid: string, // Twilio call sid
  97. // call_state: 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
  98. // call_from: string, // "+441234567890"
  99. // call_to: string, // "client:bob"
  100. // }
  101. })
  102. TwilioVoice.addEventListener('connectionIsReconnecting', function(data) {
  103. // {
  104. // call_sid: string, // Twilio call sid
  105. // call_from: string, // "+441234567890"
  106. // call_to: string, // "client:bob"
  107. // }
  108. })
  109. TwilioVoice.addEventListener('connectionDidReconnect', function(data) {
  110. // {
  111. // call_sid: string, // Twilio call sid
  112. // call_from: string, // "+441234567890"
  113. // call_to: string, // "client:bob"
  114. // }
  115. })
  116. TwilioVoice.addEventListener('connectionDidDisconnect', function(data: mixed) {
  117. // | null
  118. // | {
  119. // err: string
  120. // }
  121. // | {
  122. // call_sid: string, // Twilio call sid
  123. // call_state: 'CONNECTED' | 'ACCEPTED' | 'CONNECTING' | 'RINGING' | 'DISCONNECTED' | 'CANCELLED',
  124. // call_from: string, // "+441234567890"
  125. // call_to: string, // "client:bob"
  126. // err?: string,
  127. // }
  128. });
  129. }
  130. render() {
  131. return (
  132. <Container>
  133. </Container>
  134. );
  135. }
  136. }
  137. const styles = StyleSheet.create({
  138. container: {
  139. alignItems: 'center'
  140. },
  141. header:{
  142. backgroundColor:colors.theme_bg_three
  143. },
  144. icon:{
  145. color:colors.theme_fg_two
  146. },
  147. header_body: {
  148. flex: 3,
  149. justifyContent: 'center'
  150. },
  151. title:{
  152. alignSelf:'center',
  153. color:colors.theme_fg_two,
  154. alignSelf:'center',
  155. fontSize:16,
  156. fontFamily:font_title
  157. },
  158. faq_title: {
  159. color: colors.theme_fg_two,
  160. fontSize: 15,
  161. fontFamily:font_description
  162. },
  163. });