簡體   English   中英

電話會議iOS / android?

[英]conference call iOS/android?

我沒有來自twilio支持的合適答案所以我在這里。

在這一點上,我們在我們的應用程序中使用voip產品(一對一),但我們需要一對一。

我想知道是否可以通過twilio會議產品在移動設備(iOS / android)上召開電話會議,是否可以將其與twilio客戶端一起使用,或者我們是否必須通過自己對服務器進行一些http請求?

或者任何線索?

按此處要求的代碼用於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];
}

Twilio開發者傳道者在這里。

正如我們在評論中所做的那樣,您正在使用具有Python服務器的iOS客戶端快速入門。 如果您在整個過程中都遵循快速入門,您將會知道當您發送一個To參數作為電話號碼時,您的應用程序將調用該號碼,並且當您發送To參數時,該參數是以“client:”開頭的字符串。然后您的應用程序將調用另一個基於客戶端的應用程序 這是所有控制的服務器上由這些線

發生的事情是,當您從應用程序撥出時,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的會議中。 其他呼叫者可以通過提供相同的名稱撥入同一會議。

這是快速入門的擴展,但希望您可以看到如何使用它來創建會議。

如果這有幫助,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM