【发布时间】:2016-01-20 09:49:01
【问题描述】:
我没有来自 twilio 支持的合适答案,所以我来了。
此时,我们在应用中使用 voip 产品(一对一),但我们需要一对多。
我想知道是否可以使用 twilio 会议产品在移动设备 (iOS/android) 上进行电话会议,是否可以将其与 twilio 客户端一起使用,或者我们是否必须向自己做服务器?
或者有什么线索?
按照此处的要求,用于 1 - 1 的代码(仅限 iOS,android 不是我做的) 在这里我得到了令牌。
+ (BOOL)getTwilioToken{
if(![self isCapabilityTokenValid]){
if([APP_DELEGATE currentUser].firstName && [APP_DELEGATE currentUser].lastName){
NSString *fullName = [NSString stringWithFormat:@"%@%@",[APP_DELEGATE currentUser].firstName,[APP_DELEGATE currentUser].lastName];
NSString *urlString = [NSString stringWithFormat:@"%@%@%@",TWILIO_BASE_URL,TWILIO_TOKEN_URL, fullName];
NSURL *url = [NSURL URLWithString:urlString];
NSString *token = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"capabilityToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
return true;
}else{
return false;
}
}else{
return true;
}
}
以下代码用于处理 voip
- (void)setTwilioToken{
NSString* token = [[NSUserDefaults standardUserDefaults] objectForKey:@"capabilityToken"];
if(token){
self.phone = [[TCDevice alloc] initWithCapabilityToken:token delegate:self];
}
}
-(IBAction)callPressed:(id)sender{
//[self callResponder:sender];
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
//responder full name for twilio, client is required for twilio
NSString *responderFullName = [NSString stringWithFormat:@"client:%@%@",[[self.responders objectAtIndex:indexPath.row] firstName],[[self.responders objectAtIndex:indexPath.row] lastName]];
NSDictionary *params = @{@"To": responderFullName};
//Check to see if we can make an outgoing call and attempt a connection if so
NSNumber* hasOutgoing = [self.phone.capabilities objectForKey:TCDeviceCapabilityOutgoingKey];
if ( [hasOutgoing boolValue] == YES ){
//Disconnect if we've already got a connection in progress
if(self.connection){
[self.connection disconnect];
}
self.connection = [self.phone connect:params delegate:self];
[self closeNoddersView:nil];
}
}
- (void)connectionDidConnect:(TCConnection *)connection{
NSLog(@"Twilio connectionDidConnect");
NSError *errorAudio;
BOOL success = [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&errorAudio];
[[AVAudioSession sharedInstance]setMode:AVAudioSessionModeVoiceChat error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
isSpeaker = success;
if(!success){
NSLog(@" error Audio %@", [errorAudio debugDescription]);
}
}
-(void)connection:(TCConnection*)connection didFailWithError:(NSError*)error
{
//Connection failed to responder failed
NSLog(@" %@", [error debugDescription]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[error localizedDescription]
message:@"We can't reach your responder"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[self.connection disconnect];
}
【问题讨论】:
-
您能否分享一下您现在用来拨打 1 对 1 电话的代码,我会看看是否可以建议您如何更新以进行电话会议。
-
@philnash 完成,感谢您的帮助
-
感谢@Bryan D,很抱歉让您感到痛苦,您能否分享一下您用来设置呼叫的 TwiML,这在这种情况下更有用。谢谢!
-
@philnash 现在我很抱歉,我对 twilio 很陌生,所以你能更准确吗?你需要服务器端代码吗(我们按照 python 快速入门),你需要“url”吗?
-
啊,好的,你已经使用了 Python 快速入门,这应该足够我继续了!答案马上来了。
标签: java android ios objective-c twilio