[*] 视频配置

This commit is contained in:
acgist
2023-10-13 08:32:43 +08:00
parent cff7bca9fc
commit 8fefa9f5a7
4 changed files with 72 additions and 19 deletions

View File

@@ -19,8 +19,8 @@
<el-button>视频质量</el-button> <el-button>视频质量</el-button>
</template> </template>
<el-table @cell-click="chooseRatio" :data="taoyao.options"> <el-table @cell-click="chooseRatio" :data="taoyao.options">
<el-table-column width="100" property="value" label="标识" /> <el-table-column width="100" property="label" label="标识" />
<el-table-column width="100" property="label" label="名称" /> <el-table-column width="100" property="value" label="高宽" />
</el-table> </el-table>
</el-popover> </el-popover>
</div> </div>
@@ -84,7 +84,7 @@ export default {
}, },
methods: { methods: {
chooseRatio(row) { chooseRatio(row) {
const { value, label } = row; const { label, value } = row;
this.taoyao.setLocalVideoConfig(label); this.taoyao.setLocalVideoConfig(label);
}, },
media(track, producer) { media(track, producer) {

View File

@@ -21,8 +21,8 @@
<el-button>视频质量</el-button> <el-button>视频质量</el-button>
</template> </template>
<el-table @row-click="chooseRatio" :data="taoyao.options"> <el-table @row-click="chooseRatio" :data="taoyao.options">
<el-table-column width="100" property="value" label="标识" /> <el-table-column width="100" property="label" label="标识" />
<el-table-column width="100" property="label" label="名称" /> <el-table-column width="100" property="value" label="宽高" />
</el-table> </el-table>
</el-popover> </el-popover>
<el-button @click="taoyao.roomExpel(client.clientId)" title="踢出" :icon="CircleClose" circle /> <el-button @click="taoyao.roomExpel(client.clientId)" title="踢出" :icon="CircleClose" circle />
@@ -91,7 +91,7 @@ export default {
}, },
methods: { methods: {
chooseRatio(row) { chooseRatio(row) {
const { value, label } = row; const { label, value } = row;
this.taoyao.setVideoConfig(this.client.clientId, label); this.taoyao.setVideoConfig(this.client.clientId, label);
}, },
media(track, consumer) { media(track, consumer) {

View File

@@ -20,8 +20,8 @@
<el-button>视频质量</el-button> <el-button>视频质量</el-button>
</template> </template>
<el-table @row-click="chooseRatio" :data="taoyao.options"> <el-table @row-click="chooseRatio" :data="taoyao.options">
<el-table-column width="100" property="value" label="标识" /> <el-table-column width="100" property="label" label="标识" />
<el-table-column width="100" property="label" label="名称" /> <el-table-column width="100" property="value" label="宽高" />
</el-table> </el-table>
</el-popover> </el-popover>
<el-button @click="taoyao.sessionClose(client.id)" title="踢出" :icon="CircleClose" circle /> <el-button @click="taoyao.sessionClose(client.id)" title="踢出" :icon="CircleClose" circle />
@@ -89,7 +89,7 @@ export default {
}, },
methods: { methods: {
chooseRatio(row) { chooseRatio(row) {
const { value, label } = row; const { label, value } = row;
this.taoyao.setVideoConfig(this.client.clientId, label); this.taoyao.setVideoConfig(this.client.clientId, label);
}, },
media(track) { media(track) {

View File

@@ -263,10 +263,14 @@ class Session {
videoEnabled; videoEnabled;
// 本地音频 // 本地音频
localAudioTrack; localAudioTrack;
// 本地音频发送者
localAudioSender;
// 本地音频是否可用(暂停关闭) // 本地音频是否可用(暂停关闭)
localAudioEnabled; localAudioEnabled;
// 本地视频 // 本地视频
localVideoTrack; localVideoTrack;
// 本地视频发送者
localVideoSender;
// 本地视频是否可用(暂停关闭) // 本地视频是否可用(暂停关闭)
localVideoEnabled; localVideoEnabled;
// 远程音频 // 远程音频
@@ -1203,9 +1207,10 @@ class Taoyao extends RemoteClient {
ideal: video.frameRate, ideal: video.frameRate,
max : media.maxFrameRate, max : media.maxFrameRate,
}; };
me.options = Object.keys(media.videos).map(key => ({ me.options = Object.keys(media.videos).map(key => ({
value: key, ...media.videos[key],
label: media.videos[key].resolution label: key,
value: media.videos[key].resolution,
})); }));
me.mediaConfig = media; me.mediaConfig = media;
me.webrtcConfig = webrtc; me.webrtcConfig = webrtc;
@@ -1411,8 +1416,8 @@ class Taoyao extends RemoteClient {
* @param {*} clientId 终端ID * @param {*} clientId 终端ID
* @param {*} config 视频配置 * @param {*} config 视频配置
*/ */
controlConfigVideo(clientId, config) { async controlConfigVideo(clientId, config) {
this.request(protocol.buildMessage("control::config::video", { return await this.request(protocol.buildMessage("control::config::video", {
...config, ...config,
to: clientId to: clientId
})); }));
@@ -1425,9 +1430,24 @@ class Taoyao extends RemoteClient {
* @param {*} body 消息主体 * @param {*} body 消息主体
*/ */
defaultControlConfigVideo(message, body) { defaultControlConfigVideo(message, body) {
console.debug("配置视频", message); const {
width,
height,
frameRate,
} = body;
if(width) {
this.videoConfig.width.ideal = width;
}
if(height) {
this.videoConfig.height.ideal = height;
}
if(frameRate) {
this.videoConfig.frameRate.ideal = frameRate;
}
console.debug("配置视频", body, this.videoConfig);
this.push(message); this.push(message);
// TODO配置本地视频 // 更新本地视频
this.setLocalVideoConfig();
} }
/** /**
@@ -2341,6 +2361,10 @@ class Taoyao extends RemoteClient {
* @param {*} 更新视频轨道 * @param {*} 更新视频轨道
*/ */
async updateVideoProducer(videoTrack) { async updateVideoProducer(videoTrack) {
if(!this.videoProducer) {
console.debug("没有发布视频忽略更新");
return;
}
const track = videoTrack || await this.getVideoTrack(); const track = videoTrack || await this.getVideoTrack();
await this.videoProducer.replaceTrack({ await this.videoProducer.replaceTrack({
track track
@@ -2353,6 +2377,22 @@ class Taoyao extends RemoteClient {
} }
} }
/**
* 更新视频轨道
*
* @param {*} videoTrack 更新视频轨道
*/
async updateVideoSession(videoTrack) {
this.sessionClients.forEach(async (v, k) => {
const localStream = await this.getStream();
// TODO更新音频
if(v.localVideoEnabled) {
v.localVideoTrack = videoTrack || localStream.getVideoTracks()[0];
v.localVideoSender.replaceTrack(v.localVideoTrack);
}
});
}
/** /**
* 验证设备 * 验证设备
*/ */
@@ -3469,7 +3509,7 @@ class Taoyao extends RemoteClient {
session.localAudioTrack = localStream.getAudioTracks()[0]; session.localAudioTrack = localStream.getAudioTracks()[0];
if(session.localAudioTrack) { if(session.localAudioTrack) {
session.localAudioEnabled = true; session.localAudioEnabled = true;
await session.peerConnection.addTrack(session.localAudioTrack, localStream); session.localAudioSender = await session.peerConnection.addTrack(session.localAudioTrack, localStream);
} else { } else {
session.localAudioEnabled = false; session.localAudioEnabled = false;
} }
@@ -3480,7 +3520,7 @@ class Taoyao extends RemoteClient {
session.localVideoTrack = localStream.getVideoTracks()[0]; session.localVideoTrack = localStream.getVideoTracks()[0];
if(session.localVideoTrack) { if(session.localVideoTrack) {
session.localVideoEnabled = true; session.localVideoEnabled = true;
await session.peerConnection.addTrack(session.localVideoTrack, localStream); session.localVideoSender = await session.peerConnection.addTrack(session.localVideoTrack, localStream);
} else { } else {
session.localVideoEnabled = false; session.localVideoEnabled = false;
} }
@@ -3596,8 +3636,11 @@ class Taoyao extends RemoteClient {
*/ */
setLocalVideoConfig(label) { setLocalVideoConfig(label) {
const me = this; const me = this;
// TODO设置本地配置 if(label) {
// TODO设置本地配置
}
me.updateVideoProducer(); me.updateVideoProducer();
me.updateVideoSession();
} }
/** /**
@@ -3609,8 +3652,18 @@ class Taoyao extends RemoteClient {
const me = this; const me = this;
if(clientId === me.clientId) { if(clientId === me.clientId) {
me.setLocalVideoConfig(label); me.setLocalVideoConfig(label);
return;
} }
// TODO更新远程配置 // TODO更新远程配置
const option = this.options.find(v => v.label === label);
if(!option) {
console.warn("不支持的视频配置", label, this.options);
return;
}
this.controlConfigVideo(
clientId,
option,
);
} }
/** /**