Connection to an existing session¶
Since iOS SDK build 2.6.76, it is possible to connect to an existing websocket session on the server to accept an incoming call when push notification is received:
-
Set
keepAlive
option when conection is established for the first time- (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; }
-
Keep a session token after successful connection
Then, the session can be disconnected on mobile device when application goes to background, but the session will be kept on server during 1 hour by default.[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]; } }];
-
When push notification is received, connect to the existing session by token
-
Receive incoming call event and create answer/hangup alert dialog
[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]; }];
-
Accept the incoming call