電話を受ける

このガイドでは、Vonage Client SDKで電話を受ける方法を説明します。始める前に、お使いのアプリにSDKが追加されていることを確認してください。アンドロイド, iOS, JS).

注:iOSでは、発着信にCallKitを使用することが想定されています。以下の手順に従ってください。 プッシュ通知ガイド.

招待電話を受け取る

アプリ内着信を受信するには、着信通知を聞く必要があります:

アプリ内着信を受信するには callInvite イベントを開催する:

// After creating a session
client.on("callInvite", (callId, from, channelType) => {
  // Answer / Reject Call
  console.log( { callId, from, channelType } );
});
client.setCallInviteListener { callId, from, channelType ->
    // Handling incoming call invite
}

現在の ViewControllerなどを音声クライアントのデリゲートとして使用する:

client.delegate = self

ViewController に準拠しなければならなくなった。 VGVoiceClientDelegateその didReceiveInviteForCall 関数は、着信招待があったときに呼び出される。この関数は callId というのも、これはさらなる操作を行うために必要となるからだ:

extension ViewController: VGVoiceClientDelegate {

    func voiceClient(_ client: VGVoiceClient, didReceiveInviteForCall callId: String, from caller: String, withChannelType type: VGVoiceChannelType) {
        // Handling incoming callId
    }

    ...
}

その後、招待に答えるか拒否するかを選択できる。

回答

// After creating a session
client.answer(callId)
    .then(() => {
        console.log("Success answering call.");
    })
    .catch(error => {
        console.error("Error answering call: ", error);
    });
client.answer(callID) {
    err ->
    when {
        err != null -> {
            // Handle invite answer error
        }
        else -> {
            // Handle active call
        }
    }
}
client.answer(callID) { error in
    if error == nil {
        self.callID = callID
    } else {
        // Handle answer error
    }
}

却下

// After creating a session
client.reject(callId)
    .then(() => {
        console.log("Success rejecting call.");
    })
    .catch(error => {
        console.error("Error rejecting call: ", error);
    });
client.reject(callID) {
    err ->
    when {
        err != null -> {
            // Handle inviate reject error
        }
    }
}
client.reject(callID) { error in
    if error != nil {
        // Handle invite reject error
    }
}

電話を切る

継続的な call:

// After creating a session
client.hangup(callId)
    .then(() => {
        console.log("Success hanging up call.");
    })
    .catch(error => {
        console.error("Error hanging up call: ", error);
    });
client.hangup(callID) {
    err ->
    when {
        err != null -> {
            // Handle hang up error
        }
    }
}
client.hangup(callID) { error in
    if error != nil {
        // Handle hang up error
    }
}

コールイベントを聞く

通話の状態の更新を確認するには、例えば、相手のメンバーが通話に出たか、 切ったかを知るには、レッグステータスイベントを聞く必要がある。

コールとメンバーの近況を見る:

// After creating a session
client.on("legStatusUpdate", (callId, legId, status) => {
    console.log({callId, legId, status});
});
client.setOnLegStatusUpdate { callId, legId, status -> 
    // Call leg updates
}

について didReceiveLegStatusUpdateForCall 関数は、アクティブな通話のコールレグの変更を更新する:

extension ViewController: VGVoiceClientDelegate {
    
    func voiceClient(_ client: VGVoiceClient, didReceiveLegStatusUpdateForCall callId: String, withLegId legId: String, andStatus status: String) {
        // Call leg updates
    }

    ...
}

参考