我已经在我的角度6中集成了OT视频通话会话。
这是发布商流代码
const publisher = OT.initPublisher('publisher', {
name: 'pubname',
style: { 'buttonDisplayMode': 'off'},
insertMode: 'append',
width: '100%',
fitMode: 'contain',
height: '100%'
});
这是订阅者流代码:
session.subscribe(event.stream, dup_div, {
insertMode: 'append',
name:'subname',
style: { 'buttonDisplayMode': 'off'},
width: '100%',
fitMode: 'contain',
height: '100%'
});
这工作正常。我的流中有4个订阅者。如果是这样,我想得到谁说话。也就是说,如果订户1提出问题,那么其他人应该让Subscriber1发言。所以我希望获得正在发言的用户ID。我如何使用captureStream()
或getAudioTracks()
获得此功能。
请帮我找到这个。我没有得到任何关于此的示例或示例代码。
我能想到有几种选择。
const subscriber = session.subscribe(stream);
subscriber.on('audioLevelUpdated', () => {
if (movingAvg === null || movingAvg <= event.audioLevel) {
movingAvg = event.audioLevel;
} else {
movingAvg = 0.7 * movingAvg + 0.3 * event.audioLevel;
}
// 1.5 scaling to map the -30 - 0 dBm range to [0,1]
let logLevel = (Math.log(movingAvg) / Math.LN10) / 1.5 + 1;
logLevel = Math.min(Math.max(logLevel, 0), 1);
if (logLevel > 0.5) {
// They are speaking, do whatever you need to do here
}
});
const publisher = OT.initPublisher();
// Create a new MediaStream with the audio track from the Publisher
const mediaStream = new MediaStream([publisher.getAudioSource()]);
const speech = hark(mediaStream, options);
speech.on('speaking', () => {
// They are speaking
session.signal({ type: 'speaking'});
});
const subscribersByConnectionId = {};
session.on('streamCreated', (event) => {
const subscriber = session.subscribe(event.stream);
subscribersByConnectionId[event.stream.connection.connectionId] = subscriber;
subscriber.on('destroyed', (event) => {
delete subscribersByConnectionId[event.stream.connection.connectionId];
});
});
session.on('signal:speaking', (event) => {
const subscriberSpeaking = subscribersByConnectionId[event.from.connectionId];
// Do whatever you want with the subscriber that is speaking
});