[+] 优化逻辑
This commit is contained in:
@@ -96,8 +96,10 @@
|
|||||||
|
|
||||||
<!-- 终端 -->
|
<!-- 终端 -->
|
||||||
<div class="clients">
|
<div class="clients">
|
||||||
<LocalClient ref="local" :client="taoyao" :taoyao="taoyao"></LocalClient>
|
<!-- 本地终端 -->
|
||||||
<RemoteClient :ref="'remote-' + kv[0]" v-for="(kv, index) in remoteClients" :key="index" :client="kv[1]" :taoyao="taoyao"></RemoteClient>
|
<LocalClient ref="local-client" v-if="this.taoyao" :client="taoyao" :taoyao="taoyao"></LocalClient>
|
||||||
|
<!-- 远程终端 -->
|
||||||
|
<RemoteClient :ref="'remote-client-' + kv[0]" v-for="(kv, index) in remoteClients" :key="index" :client="kv[1]" :taoyao="taoyao"></RemoteClient>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -140,7 +142,7 @@ export default {
|
|||||||
async connectSignal() {
|
async connectSignal() {
|
||||||
const me = this;
|
const me = this;
|
||||||
me.taoyao = new Taoyao({ ...this.config });
|
me.taoyao = new Taoyao({ ...this.config });
|
||||||
await me.taoyao.connectSignal(me.callback, me.callbackMedia);
|
await me.taoyao.connectSignal(me.callback);
|
||||||
me.signalVisible = false;
|
me.signalVisible = false;
|
||||||
me.remoteClients = me.taoyao.remoteClients;
|
me.remoteClients = me.taoyao.remoteClients;
|
||||||
// 全局绑定
|
// 全局绑定
|
||||||
@@ -197,26 +199,6 @@ export default {
|
|||||||
}
|
}
|
||||||
return false;
|
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: {
|
components: {
|
||||||
LocalClient,
|
LocalClient,
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.audio = this.$refs.audio;
|
this.audio = this.$refs.audio;
|
||||||
this.video = this.$refs.video;
|
this.video = this.$refs.video;
|
||||||
|
this.client.proxy = this;
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
"client": {
|
"client": {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.audio = this.$refs.audio;
|
this.audio = this.$refs.audio;
|
||||||
this.video = this.$refs.video;
|
this.video = this.$refs.video;
|
||||||
|
this.client.proxy = this;
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
"client": {
|
"client": {
|
||||||
|
|||||||
@@ -234,6 +234,8 @@ class RemoteClient {
|
|||||||
clientId;
|
clientId;
|
||||||
// 音量
|
// 音量
|
||||||
volume = 0;
|
volume = 0;
|
||||||
|
// 代理对象
|
||||||
|
proxy;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
name,
|
name,
|
||||||
@@ -263,8 +265,6 @@ class Taoyao extends RemoteClient {
|
|||||||
roomId;
|
roomId;
|
||||||
// 回调事件
|
// 回调事件
|
||||||
callback;
|
callback;
|
||||||
// 媒体回调
|
|
||||||
callbackMedia;
|
|
||||||
// 请求回调
|
// 请求回调
|
||||||
callbackMapping = new Map();
|
callbackMapping = new Map();
|
||||||
// 音频媒体配置
|
// 音频媒体配置
|
||||||
@@ -348,15 +348,13 @@ class Taoyao extends RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 连接信令
|
* 连接信令
|
||||||
*
|
*
|
||||||
* @param {*} callback 信令回调
|
* @param {*} callback 回调事件
|
||||||
* @param {*} callbackMedia 媒体回调
|
|
||||||
*
|
*
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async connectSignal(callback, callbackMedia) {
|
async connectSignal(callback) {
|
||||||
const self = this;
|
const self = this;
|
||||||
self.callback = callback;
|
self.callback = callback;
|
||||||
self.callbackMedia = callbackMedia;
|
|
||||||
self.signalChannel = signalChannel;
|
self.signalChannel = signalChannel;
|
||||||
signalChannel.taoyao = self;
|
signalChannel.taoyao = self;
|
||||||
return self.signalChannel.connect(
|
return self.signalChannel.connect(
|
||||||
@@ -636,9 +634,12 @@ class Taoyao extends RemoteClient {
|
|||||||
// );
|
// );
|
||||||
self.push(message);
|
self.push(message);
|
||||||
console.log("消费者", consumer);
|
console.log("消费者", consumer);
|
||||||
|
const remoteClient = self.remoteClients.get(consumer.sourceId);
|
||||||
self.callbackMedia("remote", consumer.track, consumer);
|
if(remoteClient) {
|
||||||
|
remoteClient.proxy.media(consumer.track, consumer);
|
||||||
|
} else {
|
||||||
|
console.warn("远程终端无效:", consumer);
|
||||||
|
}
|
||||||
// If audio-only mode is enabled, pause it.
|
// If audio-only mode is enabled, pause it.
|
||||||
if (consumer.kind === "video" && !self.videoProduce) {
|
if (consumer.kind === "video" && !self.videoProduce) {
|
||||||
// this.pauseConsumer(consumer);
|
// this.pauseConsumer(consumer);
|
||||||
@@ -1108,7 +1109,7 @@ class Taoyao extends RemoteClient {
|
|||||||
console.debug("enableWebcam() | calling getUserMedia()");
|
console.debug("enableWebcam() | calling getUserMedia()");
|
||||||
// TODO:参数
|
// TODO:参数
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({
|
const stream = await navigator.mediaDevices.getUserMedia({
|
||||||
video: true,
|
video: self.videoConfig,
|
||||||
});
|
});
|
||||||
track = stream.getVideoTracks()[0];
|
track = stream.getVideoTracks()[0];
|
||||||
// TODO:验证修改API videoTrack.applyCapabilities
|
// TODO:验证修改API videoTrack.applyCapabilities
|
||||||
@@ -1130,9 +1131,7 @@ class Taoyao extends RemoteClient {
|
|||||||
} else {
|
} else {
|
||||||
// TODO:异常
|
// TODO:异常
|
||||||
}
|
}
|
||||||
|
self.proxy.media(track);
|
||||||
self.callbackMedia("local", track);
|
|
||||||
|
|
||||||
let codec;
|
let codec;
|
||||||
let encodings;
|
let encodings;
|
||||||
const codecOptions = {
|
const codecOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user