Skip to end of metadata
Go to start of metadata

Начиная со сборки iOS SDK 2.6.76, поддерживается подключение к существующей websocket сессии на сервере для приема входящего SIP звонка при получении push-уведомления:

1. При создании сессии, установите опцию keepAlive 

- (FPWCSApi2Session *)connectWithOptions:(FPWCSApi2SessionOptions *)options {
    options.urlServer = _connectUrl.text;
    options.keepAlive = true;
    options.sipRegisterRequired = _sipRegRequired.control.isOn;
    options.sipLogin = _sipLogin.input.text;
    options.sipAuthenticationName = _sipAuthName.input.text;
    options.sipPassword = _sipPassword.input.text;
    options.sipDomain = _sipDomain.input.text;
    options.sipOutboundProxy = _sipOutboundProxy.input.text;
    options.sipPort = [NSNumber numberWithInteger: [_sipPort.input.text integerValue]];
    options.appKey = @"defaultApp";
    ...
    session = [FPWCSApi2 createSession:options error:&error];
    ...
    [session connect];
    return session;
}

2. После успешной установки соединения, сохраните токен сессии

    [session on:kFPWCSSessionStatusEstablished callback:^(FPWCSApi2Session *rSession){
        _authToken.input.text = [rSession getAuthToken];
        [self changeConnectionStatus:[rSession getStatus]];
        [self onConnected:rSession];
        if (!_sipRegRequired.control.isOn) {
                [self changeViewState:_callButton enabled:YES];
        }
    }];

После этого сессия может быть разорвана на мобильном устройстве при уходе приложения в фон, но на сервере сохранится, по умолчанию, в течение 1 часа.

3. При получении push уведомления, подключитесь к существующей сессии по токену

- (FPWCSApi2Session *)connectWithToken {
    FPWCSApi2SessionOptions *options = [[FPWCSApi2SessionOptions alloc] init];
    options.authToken = _authToken.input.text;
    return [self connectWithOptions:options];
}

4. Получите сообщение о входящем звонке и создайте диалог для приема/отклонения вызова

    [session onIncomingCallCallback:^(FPWCSApi2Call *rCall) {
        call = rCall;
        ...
        alert = [UIAlertController
                                     alertControllerWithTitle:[NSString stringWithFormat:@"Incoming call from '%@'", [rCall getCallee]]
                                     message:error.localizedDescription
                                     preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* answerButton = [UIAlertAction
                                   actionWithTitle:@"Answer"
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction * action) {
                                       [call answer];
                                   }];
        
        [alert addAction:answerButton];
        UIAlertAction* hangupButton = [UIAlertAction
                                       actionWithTitle:@"Hangup"
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction * action) {
                                           [call hangup];
                                       }];
        
        [alert addAction:hangupButton];
        [self presentViewController:alert animated:YES completion:nil];
    }];

5. Примите входящий звонок

        [call on:kFPWCSCallStatusEstablished callback:^(FPWCSApi2Call *call){
            [self changeCallStatus:call];
            [self toHangupState];
            [self changeViewState:_holdButton enabled:YES];
        }];
  • No labels