问题
I am implementing twilio's video call in my iOS application. The problem is that I am looking for a way to know when the counterpart application is dead to send him a VoIP Push notification.
The solution I was trying to implement was that, when the call returns "User is unavailable" error then i would tell my backend to send VoIP notification to the counterpart, the problem with this solution is that I found a twilio's bug where sometimes if the user rejects the call twilio's SDK returns a wrong error message saying "User is unavailable" instead an error with "User rejects the call" message. So I can't know if the user was really unavailable (to send the VoiP notification) or if the user just rejected the call
How to reproduce the error? 1. Connect two clients with fixed identity id. For example "identity1" and "identity2" 2. Make a call from "identity1" to "identity2" and rejects it from "identity2". You will receive the correct error message "User rejects the call" 3. Close the app in "identity2" WITHOUT CALLING UNLISTEN, just kill the app. 4. Then start the app again in "identity2" (change the token if you want but let the same identity id). 5. Make a call from "identity1" to "identity2" and rejects it from "identity2". You will receive the wrong error message "User is unavailable" instead "User rejects the call".
Thats the problem is like twilio would not remove the old client's instance if we don't call unlisten. And if I can't difference when user is unavailable or when just rejects the call then I can't send the VoIP push when is really needed.
回答1:
In order to receive incoming call, you have to call listen
API on each launch of the app. It seems you might be killing the app after listen
but after relaunch listen
was not called on client. So when the remote party makes an outbound call, it is getting TWCErrorCodeConversationParticipantNotAvailable.
Once conversation client starts listening for incoming calls, remote party should receive TWCErrorCodeConversationRejected
on reject.
In other words, if A calls B, and B is not listening (i.e. not called listen
on client), A will receive “user is unavailable".
The example in Swift:
/* Create an AccessManager - this provides a single place to update your Twilio
Access Token when using multiple Twilio SDKs */
var accessManager = TwilioAccessManager(token:self.accessToken, delegate:self)
// Create a Conversations Client and listen for IncomingInvites
var client = TwilioConversationsClient(accessManager: accessManager, delegate: self)
client!.listen()
// MARK: TwilioConversationsClientDelegate
// Selectively handle IncomingInvites based on the originator
func conversationsClient(conversationsClient: TwilioConversationsClient,
didReceiveInvite invite: TWCIncomingInvite) {
if (invite.from == "ringo") {
invite.reject()
} else {
/* See the "Specify Local Media Constraints when Creating a
Conversation" guide for instructions on constructing LocalMedia */
invite.acceptWithLocalMedia(self.localMedia!) { conversation, error in
self.conversation = conversation
self.conversation!.delegate = self
}
}
}
Please let me know if this helps at all!
来源:https://stackoverflow.com/questions/38659489/twilio-ios-video-call-getting-user-is-unavailable-error-message-when-user-rej