[+] OKOK
This commit is contained in:
@@ -573,7 +573,7 @@ class Signal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async mediaConsume(message, body) {
|
async mediaConsume(message, body) {
|
||||||
const { roomId, producerId, transportId, rtpCapabilities } = body;
|
const { roomId, clientId, streamId, producerId, transportId, rtpCapabilities } = body;
|
||||||
const room = this.rooms.get(roomId);
|
const room = this.rooms.get(roomId);
|
||||||
const producer = room.producers.get(producerId);
|
const producer = room.producers.get(producerId);
|
||||||
const transport = room.transports.get(transportId);
|
const transport = room.transports.get(transportId);
|
||||||
@@ -590,6 +590,7 @@ class Signal {
|
|||||||
console.warn(
|
console.warn(
|
||||||
"不能消费媒体:",
|
"不能消费媒体:",
|
||||||
roomId,
|
roomId,
|
||||||
|
clientId,
|
||||||
producerId,
|
producerId,
|
||||||
transportId,
|
transportId,
|
||||||
rtpCapabilities
|
rtpCapabilities
|
||||||
@@ -613,6 +614,7 @@ class Signal {
|
|||||||
console.error(
|
console.error(
|
||||||
"创建消费者异常:",
|
"创建消费者异常:",
|
||||||
roomId,
|
roomId,
|
||||||
|
clientId,
|
||||||
producerId,
|
producerId,
|
||||||
transportId,
|
transportId,
|
||||||
rtpCapabilities,
|
rtpCapabilities,
|
||||||
@@ -620,6 +622,8 @@ class Signal {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
consumer.clientId = clientId;
|
||||||
|
consumer.streamId = streamId;
|
||||||
room.consumers.set(consumer.id, consumer);
|
room.consumers.set(consumer.id, consumer);
|
||||||
consumer.on("transportclose", () => {
|
consumer.on("transportclose", () => {
|
||||||
room.consumers.delete(consumer.id);
|
room.consumers.delete(consumer.id);
|
||||||
@@ -677,6 +681,8 @@ class Signal {
|
|||||||
kind: consumer.kind,
|
kind: consumer.kind,
|
||||||
type: consumer.type,
|
type: consumer.type,
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
|
clientId: clientId,
|
||||||
|
streamId: streamId,
|
||||||
producerId: producerId,
|
producerId: producerId,
|
||||||
consumerId: consumer.id,
|
consumerId: consumer.id,
|
||||||
rtpParameters: consumer.rtpParameters,
|
rtpParameters: consumer.rtpParameters,
|
||||||
|
|||||||
@@ -49,21 +49,22 @@ export default {
|
|||||||
*
|
*
|
||||||
* @return 是否继续执行
|
* @return 是否继续执行
|
||||||
*/
|
*/
|
||||||
callback(data, error) {
|
async callback(data, error) {
|
||||||
let self = this;
|
let self = this;
|
||||||
if(data.header.signal === "platform::error") {
|
|
||||||
console.error("发生异常:", data, error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (data.header.signal) {
|
switch (data.header.signal) {
|
||||||
case "client::config":
|
case "client::config":
|
||||||
self.roomVisible = true;
|
self.roomVisible = true;
|
||||||
break;
|
break;
|
||||||
case "client::register":
|
case "client::register":
|
||||||
if(data.code === '3401') {
|
self.signalVisible = data.code !== '0000';
|
||||||
self.signalVisible = true;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
case "platform::error":
|
||||||
|
if(error) {
|
||||||
|
console.error("发生异常:", data, error);
|
||||||
|
} else {
|
||||||
|
console.warn("发生错误:", data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -128,10 +128,11 @@ const signalChannel = {
|
|||||||
/**
|
/**
|
||||||
* 回调策略:
|
* 回调策略:
|
||||||
* 1. 如果注册请求回调,同时执行结果返回true不再执行后面所有回调。
|
* 1. 如果注册请求回调,同时执行结果返回true不再执行后面所有回调。
|
||||||
* 2. 如果注册全局回调,同时执行结果返回true不再执行后面所有回调。
|
* 2. 执行前置回调
|
||||||
* 3. 如果前面所有回调没有返回true执行默认回调。
|
* 3. 如果注册全局回调,同时执行结果返回true不再执行后面所有回调。
|
||||||
|
* 3. 执行后置回调
|
||||||
*/
|
*/
|
||||||
self.channel.onmessage = function (e) {
|
self.channel.onmessage = async function (e) {
|
||||||
console.debug("信令通道消息:", e.data);
|
console.debug("信令通道消息:", e.data);
|
||||||
let done = false;
|
let done = false;
|
||||||
const message = JSON.parse(e.data);
|
const message = JSON.parse(e.data);
|
||||||
@@ -143,13 +144,17 @@ const signalChannel = {
|
|||||||
self.callbackMapping.delete(message.header.id);
|
self.callbackMapping.delete(message.header.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 前置回调
|
||||||
|
if (!done) {
|
||||||
|
await self.preCallback(message);
|
||||||
|
}
|
||||||
// 全局回调
|
// 全局回调
|
||||||
if (!done && self.callback) {
|
if (!done && self.callback) {
|
||||||
done = self.callback(message);
|
done = await self.callback(message);
|
||||||
}
|
}
|
||||||
// 默认回调
|
// 后置回调
|
||||||
if (!done) {
|
if (!done) {
|
||||||
self.defaultCallback(message);
|
await self.postCallback(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -243,26 +248,38 @@ const signalChannel = {
|
|||||||
clearTimeout(self.reconnectTimer);
|
clearTimeout(self.reconnectTimer);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 默认回调
|
* 前置回调
|
||||||
*
|
*
|
||||||
* @param {*} message 消息
|
* @param {*} message
|
||||||
*/
|
*/
|
||||||
defaultCallback(message) {
|
async preCallback(message) {
|
||||||
let self = this;
|
const self = this;
|
||||||
console.debug("没有适配信令消息执行默认处理", message);
|
|
||||||
switch (message.header.signal) {
|
switch (message.header.signal) {
|
||||||
case "client::config":
|
case "client::config":
|
||||||
self.defaultClientConfig(message);
|
self.defaultClientConfig(message);
|
||||||
break;
|
break;
|
||||||
|
case "client::register":
|
||||||
|
console.info("终端注册成功");
|
||||||
|
break;
|
||||||
|
case "media::consume":
|
||||||
|
await self.taoyao.consumeMedia(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 后置回调
|
||||||
|
*
|
||||||
|
* @param {*} message 消息
|
||||||
|
*/
|
||||||
|
async postCallback(message) {
|
||||||
|
const self = this;
|
||||||
|
switch (message.header.signal) {
|
||||||
case "client::reboot":
|
case "client::reboot":
|
||||||
self.defaultClientReboot(message);
|
self.defaultClientReboot(message);
|
||||||
break;
|
break;
|
||||||
case "client::shutdown":
|
case "client::shutdown":
|
||||||
self.defaultClientShutdown(message);
|
self.defaultClientShutdown(message);
|
||||||
break;
|
break;
|
||||||
case "client::register":
|
|
||||||
console.info("终端注册成功");
|
|
||||||
break;
|
|
||||||
case "platform::error":
|
case "platform::error":
|
||||||
self.callbackError(message);
|
self.callbackError(message);
|
||||||
break;
|
break;
|
||||||
@@ -426,7 +443,11 @@ class Taoyao {
|
|||||||
callbackError(message, error) {
|
callbackError(message, error) {
|
||||||
const self = this;
|
const self = this;
|
||||||
if (!self.callback) {
|
if (!self.callback) {
|
||||||
console.warn("没有注册回调:", message, error);
|
if (error) {
|
||||||
|
console.error("没有注册回调:", message, error);
|
||||||
|
} else {
|
||||||
|
console.warn("没有注册回调:", message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 错误回调
|
// 错误回调
|
||||||
self.callback(
|
self.callback(
|
||||||
@@ -641,7 +662,8 @@ class Taoyao {
|
|||||||
self
|
self
|
||||||
.request(
|
.request(
|
||||||
protocol.buildMessage("media::transport::webrtc::connect", {
|
protocol.buildMessage("media::transport::webrtc::connect", {
|
||||||
transportId: this.recvTransport.id,
|
roomId: self.roomId,
|
||||||
|
transportId: self.recvTransport.id,
|
||||||
dtlsParameters,
|
dtlsParameters,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -757,6 +779,97 @@ class Taoyao {
|
|||||||
* TODO:重复点击
|
* TODO:重复点击
|
||||||
*/
|
*/
|
||||||
async produceVideo() {}
|
async produceVideo() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消费媒体
|
||||||
|
*
|
||||||
|
* @param {*} message
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async consumeMedia(message) {
|
||||||
|
const self = this;
|
||||||
|
if (!self.consume) {
|
||||||
|
console.log("没有消费媒体");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const {
|
||||||
|
kind,
|
||||||
|
type,
|
||||||
|
roomId,
|
||||||
|
clientId,
|
||||||
|
streamId,
|
||||||
|
producerId,
|
||||||
|
consumerId,
|
||||||
|
rtpParameters,
|
||||||
|
appData,
|
||||||
|
producerPaused,
|
||||||
|
} = message.body;
|
||||||
|
try {
|
||||||
|
const consumer = await self.recvTransport.consume({
|
||||||
|
id: consumerId,
|
||||||
|
kind,
|
||||||
|
producerId,
|
||||||
|
rtpParameters,
|
||||||
|
// NOTE: Force streamId to be same in mic and webcam and different
|
||||||
|
// in screen sharing so libwebrtc will just try to sync mic and
|
||||||
|
// webcam streams from the same remote peer.
|
||||||
|
//streamId: `${peerId}-${appData.share ? "share" : "mic-webcam"}`,
|
||||||
|
streamId: `${clientId}-${appData.share ? "share" : "mic-webcam"}`,
|
||||||
|
appData, // Trick.
|
||||||
|
});
|
||||||
|
consumer.clientId = clientId;
|
||||||
|
consumer.streamId = streamId;
|
||||||
|
self.consumers.set(consumer.id, consumer);
|
||||||
|
consumer.on("transportclose", () => {
|
||||||
|
self.consumers.delete(consumer.id);
|
||||||
|
});
|
||||||
|
const { spatialLayers, temporalLayers } =
|
||||||
|
mediasoupClient.parseScalabilityMode(
|
||||||
|
consumer.rtpParameters.encodings[0].scalabilityMode
|
||||||
|
);
|
||||||
|
// store.dispatch(
|
||||||
|
// stateActions.addConsumer(
|
||||||
|
// {
|
||||||
|
// id: consumer.id,
|
||||||
|
// type: type,
|
||||||
|
// locallyPaused: false,
|
||||||
|
// remotelyPaused: producerPaused,
|
||||||
|
// rtpParameters: consumer.rtpParameters,
|
||||||
|
// spatialLayers: spatialLayers,
|
||||||
|
// temporalLayers: temporalLayers,
|
||||||
|
// preferredSpatialLayer: spatialLayers - 1,
|
||||||
|
// preferredTemporalLayer: temporalLayers - 1,
|
||||||
|
// priority: 1,
|
||||||
|
// codec: consumer.rtpParameters.codecs[0].mimeType.split("/")[1],
|
||||||
|
// track: consumer.track,
|
||||||
|
// },
|
||||||
|
// peerId
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
self.push(message);
|
||||||
|
console.log(consumer)
|
||||||
|
|
||||||
|
|
||||||
|
const audioElem = document.createElement('video');
|
||||||
|
document.getElementsByTagName('body')[0].appendChild(audioElem)
|
||||||
|
|
||||||
|
const stream = new MediaStream();
|
||||||
|
stream.addTrack(consumer.track);
|
||||||
|
audioElem.srcObject = stream;
|
||||||
|
audioElem.play()
|
||||||
|
.catch((error) => logger.warn('audioElem.play() failed:%o', error));
|
||||||
|
|
||||||
|
|
||||||
|
// If audio-only mode is enabled, pause it.
|
||||||
|
if (consumer.kind === "video" && !self.videoProduce) {
|
||||||
|
// this.pauseConsumer(consumer);
|
||||||
|
// TODO:实现
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
self.callbackError("消费媒体异常", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证设备
|
* 验证设备
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user