From 4ddf66f0d86160493ac71df10b62d3f587c1be6a Mon Sep 17 00:00:00 2001
From: acgist <289547414@qq.com>
Date: Sun, 5 Mar 2023 12:28:28 +0800
Subject: [PATCH] =?UTF-8?q?[+]=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
taoyao-client-web/src/App.vue | 28 ++++---------------
.../src/components/LocalClient.vue | 1 +
.../src/components/RemoteClient.vue | 1 +
taoyao-client-web/src/components/Taoyao.js | 25 ++++++++---------
4 files changed, 19 insertions(+), 36 deletions(-)
diff --git a/taoyao-client-web/src/App.vue b/taoyao-client-web/src/App.vue
index a358cdb..96c29d4 100644
--- a/taoyao-client-web/src/App.vue
+++ b/taoyao-client-web/src/App.vue
@@ -96,8 +96,10 @@
-
-
+
+
+
+
@@ -140,7 +142,7 @@ export default {
async connectSignal() {
const me = this;
me.taoyao = new Taoyao({ ...this.config });
- await me.taoyao.connectSignal(me.callback, me.callbackMedia);
+ await me.taoyao.connectSignal(me.callback);
me.signalVisible = false;
me.remoteClients = me.taoyao.remoteClients;
// 全局绑定
@@ -197,26 +199,6 @@ export default {
}
return false;
},
- /**
- * 媒体回调
- *
- * @param {*} type 类型
- * @param {*} track 媒体Track
- * @param {*} consumer 消费者
- */
- callbackMedia(type, track, consumer) {
- const me = this;
- return new Promise((resolve, reject) => {
- if(type === 'local') {
- me.$refs.local.media(track);
- } else if(type === 'remote') {
- me.$refs['remote-' + consumer.sourceId][0].media(track, consumer);
- } else {
- // 其他
- }
- resolve();
- });
- },
},
components: {
LocalClient,
diff --git a/taoyao-client-web/src/components/LocalClient.vue b/taoyao-client-web/src/components/LocalClient.vue
index 39263c5..17068c2 100644
--- a/taoyao-client-web/src/components/LocalClient.vue
+++ b/taoyao-client-web/src/components/LocalClient.vue
@@ -93,6 +93,7 @@ export default {
mounted() {
this.audio = this.$refs.audio;
this.video = this.$refs.video;
+ this.client.proxy = this;
},
props: {
"client": {
diff --git a/taoyao-client-web/src/components/RemoteClient.vue b/taoyao-client-web/src/components/RemoteClient.vue
index c9ff449..9452c74 100644
--- a/taoyao-client-web/src/components/RemoteClient.vue
+++ b/taoyao-client-web/src/components/RemoteClient.vue
@@ -58,6 +58,7 @@ export default {
mounted() {
this.audio = this.$refs.audio;
this.video = this.$refs.video;
+ this.client.proxy = this;
},
props: {
"client": {
diff --git a/taoyao-client-web/src/components/Taoyao.js b/taoyao-client-web/src/components/Taoyao.js
index 92ece1f..b96a107 100644
--- a/taoyao-client-web/src/components/Taoyao.js
+++ b/taoyao-client-web/src/components/Taoyao.js
@@ -234,6 +234,8 @@ class RemoteClient {
clientId;
// 音量
volume = 0;
+ // 代理对象
+ proxy;
constructor({
name,
@@ -263,8 +265,6 @@ class Taoyao extends RemoteClient {
roomId;
// 回调事件
callback;
- // 媒体回调
- callbackMedia;
// 请求回调
callbackMapping = new Map();
// 音频媒体配置
@@ -348,15 +348,13 @@ class Taoyao extends RemoteClient {
/**
* 连接信令
*
- * @param {*} callback 信令回调
- * @param {*} callbackMedia 媒体回调
+ * @param {*} callback 回调事件
*
* @returns
*/
- async connectSignal(callback, callbackMedia) {
+ async connectSignal(callback) {
const self = this;
self.callback = callback;
- self.callbackMedia = callbackMedia;
self.signalChannel = signalChannel;
signalChannel.taoyao = self;
return self.signalChannel.connect(
@@ -636,9 +634,12 @@ class Taoyao extends RemoteClient {
// );
self.push(message);
console.log("消费者", consumer);
-
- self.callbackMedia("remote", consumer.track, consumer);
-
+ const remoteClient = self.remoteClients.get(consumer.sourceId);
+ if(remoteClient) {
+ remoteClient.proxy.media(consumer.track, consumer);
+ } else {
+ console.warn("远程终端无效:", consumer);
+ }
// If audio-only mode is enabled, pause it.
if (consumer.kind === "video" && !self.videoProduce) {
// this.pauseConsumer(consumer);
@@ -1108,7 +1109,7 @@ class Taoyao extends RemoteClient {
console.debug("enableWebcam() | calling getUserMedia()");
// TODO:参数
const stream = await navigator.mediaDevices.getUserMedia({
- video: true,
+ video: self.videoConfig,
});
track = stream.getVideoTracks()[0];
// TODO:验证修改API videoTrack.applyCapabilities
@@ -1130,9 +1131,7 @@ class Taoyao extends RemoteClient {
} else {
// TODO:异常
}
-
- self.callbackMedia("local", track);
-
+ self.proxy.media(track);
let codec;
let encodings;
const codecOptions = {