[*] 优化
This commit is contained in:
@@ -160,9 +160,7 @@ public class LocalClient extends RoomClient {
|
|||||||
}
|
}
|
||||||
Log.i(RemoteClient.class.getSimpleName(), "关闭本地终端生产者:" + this.clientId + " - " + producerId);
|
Log.i(RemoteClient.class.getSimpleName(), "关闭本地终端生产者:" + this.clientId + " - " + producerId);
|
||||||
synchronized (this.mediaStream) {
|
synchronized (this.mediaStream) {
|
||||||
final Long pointer = this.tracks.get(producerId);
|
final Long pointer = this.tracks.remove(producerId);
|
||||||
// TODO:测试remove方法
|
|
||||||
// final Long pointer = this.tracks.remove(producerId);
|
|
||||||
if(pointer == null) {
|
if(pointer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async sessionCall() {
|
async sessionCall() {
|
||||||
this.taoyao.sessionCall(this.room.callClientId);
|
this.taoyao.sessionCall(this.room.callClientId);
|
||||||
|
// this.taoyao.sessionCall(this.room.callClientId, false, false);
|
||||||
this.roomVisible = false;
|
this.roomVisible = false;
|
||||||
},
|
},
|
||||||
async roomCreate() {
|
async roomCreate() {
|
||||||
|
|||||||
@@ -253,6 +253,10 @@ class Session {
|
|||||||
sessionId;
|
sessionId;
|
||||||
// 本地媒体流
|
// 本地媒体流
|
||||||
localStream;
|
localStream;
|
||||||
|
// 是否打开音频
|
||||||
|
audioEnabled;
|
||||||
|
// 是否打开视频
|
||||||
|
videoEnabled;
|
||||||
// 本地音频
|
// 本地音频
|
||||||
localAudioTrack;
|
localAudioTrack;
|
||||||
localAudioEnabled;
|
localAudioEnabled;
|
||||||
@@ -272,31 +276,35 @@ class Session {
|
|||||||
name,
|
name,
|
||||||
clientId,
|
clientId,
|
||||||
sessionId,
|
sessionId,
|
||||||
|
audioEnabled,
|
||||||
|
videoEnabled
|
||||||
}) {
|
}) {
|
||||||
this.id = sessionId;
|
this.id = sessionId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
|
this.audioEnabled = audioEnabled;
|
||||||
|
this.videoEnabled = videoEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
async pause(type) {
|
async pause(type) {
|
||||||
if(type === 'audio') {
|
if(type === 'audio' && this.localAudioTrack) {
|
||||||
this.localAudioEnabled = false;
|
this.localAudioEnabled = false;
|
||||||
this.localAudioTrack.enabled = false;
|
this.localAudioTrack.enabled = false;
|
||||||
}
|
}
|
||||||
if(type === 'video') {
|
if(type === 'video' && this.localVideoTrack) {
|
||||||
this.localVideoEnabled = false;
|
this.localVideoEnabled = false;
|
||||||
this.localVideoTrack.enabled = false;
|
this.localVideoTrack.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async resume(type) {
|
async resume(type) {
|
||||||
if(type === 'audio') {
|
if(type === 'audio' && this.localAudioTrack) {
|
||||||
this.localAudioEnabled = true;
|
this.localAudioEnabled = true;
|
||||||
this.localAudioTrack.enabled = true;
|
this.localAudioTrack.enabled = true;
|
||||||
}
|
}
|
||||||
if(type === 'video') {
|
if(type === 'video' && this.localVideoTrack) {
|
||||||
this.localVideoEnabled = true;
|
this.localVideoEnabled = true;
|
||||||
this.localVideoTrack.enabled = true;
|
this.localVideoTrack.enabled = true;
|
||||||
}
|
}
|
||||||
@@ -2243,9 +2251,11 @@ class Taoyao extends RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 发起会话
|
* 发起会话
|
||||||
*
|
*
|
||||||
* @param {*} clientId 接收者ID
|
* @param {*} clientId 接收者ID
|
||||||
|
* @param {*} audioEnabled 是否打开音频
|
||||||
|
* @param {*} videoEnabled 是否打开视频
|
||||||
*/
|
*/
|
||||||
async sessionCall(clientId) {
|
async sessionCall(clientId, audioEnabled = true, videoEnabled = true) {
|
||||||
const me = this;
|
const me = this;
|
||||||
if (!clientId) {
|
if (!clientId) {
|
||||||
this.callbackError("无效终端");
|
this.callbackError("无效终端");
|
||||||
@@ -2257,7 +2267,7 @@ class Taoyao extends RemoteClient {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
const { name, sessionId } = response.body;
|
const { name, sessionId } = response.body;
|
||||||
const session = new Session({name, clientId, sessionId});
|
const session = new Session({name, clientId, sessionId, audioEnabled, videoEnabled});
|
||||||
this.sessionClients.set(sessionId, session);
|
this.sessionClients.set(sessionId, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2404,15 +2414,23 @@ class Taoyao extends RemoteClient {
|
|||||||
// TODO:重连
|
// TODO:重连
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const localStream = await me.getStream();
|
const localStream = await me.getStream();
|
||||||
session.localStream = localStream;
|
session.localStream = localStream;
|
||||||
session.peerConnection = peerConnection;
|
session.peerConnection = peerConnection;
|
||||||
session.localAudioTrack = localStream.getAudioTracks()[0];
|
if(session.audioEnabled) {
|
||||||
session.localAudioEnabled = true;
|
session.localAudioTrack = localStream.getAudioTracks()[0];
|
||||||
session.localVideoTrack = localStream.getVideoTracks()[0];
|
session.localAudioEnabled = true;
|
||||||
session.localVideoEnabled = true;
|
await session.peerConnection.addTrack(session.localAudioTrack, localStream);
|
||||||
await session.peerConnection.addTrack(session.localAudioTrack, localStream);
|
} else {
|
||||||
await session.peerConnection.addTrack(session.localVideoTrack, localStream);
|
session.localAudioEnabled = false;
|
||||||
|
}
|
||||||
|
if(session.videoEnabled) {
|
||||||
|
session.localVideoTrack = localStream.getVideoTracks()[0];
|
||||||
|
session.localVideoEnabled = true;
|
||||||
|
await session.peerConnection.addTrack(session.localVideoTrack, localStream);
|
||||||
|
} else {
|
||||||
|
session.localVideoEnabled = false;
|
||||||
|
}
|
||||||
return peerConnection;
|
return peerConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user