在多方通话场景下,可以使用以下示例代码中的onConnectionDisconnected()方法来捕获断开事件:
const AWS = require('aws-sdk');
const connect = new AWS.Connect();
connect
.startContactRecording({
ContactId: "CONTACT_ID",
VoiceRecordingConfiguration: {
VoiceRecordingTrack: "FROM_AGENT",
},
})
.promise()
.then(() => {
const { agent, customer } = new connect.Contact("CONTACT_ID").getConnections();
agent.onConnectionDisconnected((event) => {
console.log("Agent disconnected ", event);
});
customer.onConnectionDisconnected((event) => {
console.log("Customer disconnected ", event);
});
})
.catch((err) => console.log(err));
在上述代码中,我们使用onConnectionDisconnected()方法来捕获代理和客户端的断开事件,并在控制台上打印相关事件信息。另外,如果您使用流方法而不是上面代码中的Promise,则可以按照以下方式使用onConnectionDisconnected()方法:
agent.getConnectionEvents().on('connectionDisconnect', (event) => {
console.log("Agent disconnected", event);
});
customer.getConnectionEvents().on('connectionDisconnect', (event) => {
console.log("Customer disconnected", event);
});
需要注意的是,该解决方案仅限于使用connect streams实现多方通话的情况。