电话会议iOS / android?

时间:2016-01-20 09:49:02

标签: java android ios objective-c twilio

我没有得到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 个答案:

答案 0 :(得分:2)

Twilio开发者传道者在这里。

正如我们在评论中所做的那样,您正在使用具有Python服务器的iOS客户端快速入门。如果您在整个过程中都遵循快速入门,则会知道当您发送一个To参数作为电话号码时,您的应用程序将调用该号码,并在您发送To参数时一个以“client:”开头的字符串,然后您的应用程序将调用另一个基于客户端的应用程序。这一切都在服务器by these lines上进行控制。

当您从应用程序拨出时,Twilio会使用您设置的参数调用您的Python服务器,以了解下一步该做什么。服务器返回带有指令的TwiML(XML的子集)。目前,它会返回各种形式的<Dial>,使用<Client>拨打另一个客户端或只输入拨打电话网络的号码。

我们想要的是拨打电话会议。

我们可以扩展Python服务器来执行此操作。您需要使用以下内容更新Python服务器:

@app.route('/call', methods=['GET', 'POST'])
def call():
  resp = twilio.twiml.Response()
  from_value = request.values.get('From')
  to = request.values.get('To')
  if not (from_value and to):
    return str(resp.say("Invalid request"))
  from_client = from_value.startswith('client')
  caller_id = os.environ.get("CALLER_ID", CALLER_ID)
  if not from_client:
    # PSTN -> client
    resp.dial(callerId=from_value).client(CLIENT)
  elif to.startswith("client:"):
    # client -> client
    resp.dial(callerId=from_value).client(to[7:])
  elif to.startswith("conference:"):
    # client -> conference
    resp.dial(callerId=from_value).conference(to[11:])
  else:
    # client -> PSTN
    resp.dial(to, callerId=caller_id)
  return str(resp)

我添加了以下几行:

  elif to.startswith("conference:"):
    # client -> conference
    resp.dial(callerId=from_value).conference(to[11:])

这允许您指定看起来像“conference:CONF_NAME”的To参数。如果服务器收到此消息,它将返回如下所示的TwiML:

<Response>
  <Dial>
    <Conference>CONF_NAME</Conference>
  </Dial>
</Response>

这会将来电者放入名为CONF_NAME的会议中。其他呼叫者可以通过提供相同的名称拨入同一会议。

这是快速入门的扩展,但希望您能看到如何使用它来创建会议。

如果有帮助,请告诉我。