voximplant / react-native-voximplant

Voximplant mobile SDK for React Native (iOS/Android)
http://voximplant.com
205 stars 39 forks source link

how can i built a voice calling feature in my react native app? #182

Open xts-bit opened 1 year ago

xts-bit commented 1 year ago

i am developing a college chat app project can anyone tell me how can i built a voice calling feature in my react native app?

i explored a service called voximplant.com that do that How can i do in my case i have two users chatting the first user is me and i am getting my id from asyncstorage and the otheruser id coming coming like this otheruser._id Can anyone tell me how will things will work in my case?

import Voximplant from 'react-native-voximplant';

Voximplant.SDK.init({
  bundleId: 'com.example.app',
  authToken: 'auth_token',
});

// Connect to the Voximplant cloud
Voximplant.SDK.connect();

// Create two users
const user1 = 'user1';
const user2 = 'user2';

// Log in as user1
Voximplant.SDK.login(user1, user1);

// Log in as user2
Voximplant.SDK.login(user2, user2);

// Call user2 from user1
Voximplant.SDK.callUser(user2);

// Handle incoming calls from user1
Voximplant.SDK.on(Voximplant.Event.CallIncoming, (event) => {
  const call = event.call;
  if (call.headers['X-User-Id'] === user1) {
    call.answer();
  } else {
    call.reject();
  }
});

// Handle call events
Voximplant.SDK.on(Voximplant.Event.CallConnected, (event) => {
  console.log('Call connected');
});
Voximplant.SDK.on(Voximplant.Event.CallDisconnected, (event) => {
  console.log('Call disconnected');
});
Voximplant.SDK.on(Voximplant.Event.CallFailed, (event) => {
  console.log('Call failed');
});