Objective-C

Realizar una llamada

Añadir un NXMCall a la interfaz para mantener una referencia a cualquier llamada en curso:

@interface ViewController () <NXMClientDelegate>
@property UIButton *callButton;
@property UILabel *connectionStatusLabel;
@property NXMClient *client;
@property NXMCall * call;
@end

Basado en el objeto al que hace referencia el call la propiedad callButtonPressed puede utilizarse ahora para realizar o finalizar llamadas; el método placeCall y endCall para cada caso.

Asegúrese de sustituir PHONE_NUMBER a continuación con el número de teléfono real al que desea llamar. Nota: debe ser el mismo que el especificado en el gist NCCO:

- (void)callButtonPressed {
    if (!self.call) {
        [self placeCall];
    } else {
        [self endCall];
    }
}

- (void)placeCall {
    [self.client serverCallWithCallee:@"PHONE_NUMBER" customData:nil completionHandler:^(NSError * _Nullable error, NXMCall * _Nullable call) {
        if (error) {
            self.connectionStatusLabel.text = error.localizedDescription;
            return;
        }
        
        self.call = call;
        dispatch_async(dispatch_get_main_queue(), ^{
          [self.callButton setTitle:@"End call" forState:UIControlStateNormal];
        });
    }];
}

- (void)endCall {
    [self.call hangup];
    self.call = nil;
    [self.callButton setTitle:@"Call" forState:UIControlStateNormal];
}

NOTA: Asegúrese de sustituir PHONE_NUMBER a continuación con el número de teléfono real al que desea llamar, en el formato E.164 (por ejemplo, 447700900000).

NOTA: Además, asegúrese de que el servidor webhook que construyó en los pasos anteriores sigue funcionando.

Ya está. ¡Ya puedes construir, ejecutar y realizar la llamada! ¡Mágico!

Cuando recibas la llamada, podrás responder y escuchar la llamada de voz dentro de la aplicación.

Además, a medida que la convocatoria avanza por las distintas fases, /voice/event se envían eventos:

NCCO request: - callee: 447700900000

Además, a medida que la convocatoria avanza por las distintas fases, /voice/event se envían eventos:

... --- VOICE EVENT: { from: null, to: 'Alice', uuid: '2da93da3-bcac-47ee-b48e-4a18fae7db08', conversation_uuid: 'CON-1a28b1f8-0831-44e6-8d58-42739e7d4c77', status: 'started', direction: 'inbound', timestamp: '2021-03-10T10:36:21.285Z' } --- VOICE EVENT: { headers: {}, from: 'Alice', to: '447700900000', uuid: '8aa86e22-8d45-4201-b8d8-3dcd76e76429', conversation_uuid: 'CON-1a28b1f8-0831-44e6-8d58-42739e7d4c77', status: 'started', direction: 'outbound', timestamp: '2021-03-10T10:36:27.080Z' } --- ... --- VOICE EVENT: { start_time: null, headers: {}, rate: null, from: 'Alice', to: '447700900000', uuid: '8aa86e22-8d45-4201-b8d8-3dcd76e76429', conversation_uuid: 'CON-1a28b1f8-0831-44e6-8d58-42739e7d4c77', status: 'answered', direction: 'outbound', network: null, timestamp: '2021-03-10T10:36:31.604Z' } --- VOICE EVENT: { headers: {}, end_time: '2021-03-10T10:36:36.000Z', uuid: '8aa86e22-8d45-4201-b8d8-3dcd76e76429', network: '23433', duration: '5', start_time: '2021-03-10T10:36:31.000Z', rate: '0.10000000', price: '0.00833333', from: 'Unknown', to: '447700900000', conversation_uuid: 'CON-1a28b1f8-0831-44e6-8d58-42739e7d4c77', status: 'completed', direction: 'outbound', timestamp: '2021-03-10T10:36:35.585Z' } --- VOICE EVENT: { headers: {}, end_time: '2021-03-10T10:36:35.000Z', uuid: '2da93da3-bcac-47ee-b48e-4a18fae7db08', network: null, duration: '15', start_time: '2021-03-10T10:36:20.000Z', rate: '0.00', price: '0', from: null, to: 'Alice', conversation_uuid: 'CON-1a28b1f8-0831-44e6-8d58-42739e7d4c77', status: 'completed', direction: 'inbound', timestamp: '2021-03-10T10:36:36.187Z' }

NOTA: A medida que se completa la llamada, los eventos también contendrán información sobre la duración y el precio.