[+] 证书终端请求ID

This commit is contained in:
acgist
2023-02-28 08:01:25 +08:00
parent 4f6ae876d7
commit 57c09d3ff2
72 changed files with 874 additions and 501 deletions

View File

@@ -31,7 +31,7 @@ make -C worker
```
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HTTPS / WSS | | SCTP | SRTP / SRTCP |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ICE / SDP / SIP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ICE / SDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TLS | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ DTLS +-+-+-+-+-+-+-+-+-+
| HTTP / WS | NAT / STUN / TURN | | RTP / RTCP |
@@ -44,18 +44,15 @@ make -C worker
### 协议简介
* 会话通道ICE/SIP/SDP
* 会话通道ICE/SDP
* 媒体通道RTP/RTCP/SRTP/SRTCP
* RTP实时传输协议音频视频
* RTCPRTP传输控制协议监控数据传输质量并给予数据发送方反馈
* SCTP流控制传输协议(自定义的应用数据传输)
* RTMP实时消息传送协议
* RTSP可以控制媒体点播
### ICE/SDP/SIP
ICE信息的描述格式通常采用标准的SDP其全称为Session Description Protocol即会话描述协议。<br />
SDP只是一种信息格式的描述标准不属于传输协议但是可以被其他传输协议用来交换必要的信息例如SIP、RTSP等等。
* SDP会话描述协议只是信息格式描述标准不是传输协议
* ICE交互式连接建立使用标准SDP描述
* RTP实时传输协议
* RTCPRTP控制协议监控数据传输质量提供反馈
* SCTP流控制传输协议
* RTSP实时流传输协议依赖RTP协议实时性好适合视频聊天视频监控
* RTMP实时消息传输协议
## 其他常见WebRTC媒体服务

View File

@@ -117,20 +117,20 @@ module.exports = {
// WebRtcServerhttps://mediasoup.org/documentation/v3/mediasoup/api/#WebRtcServerOptions
webRtcServerOptions: {
listenInfos: [
// UDP
{
protocol: "udp",
ip: process.env.MEDIASOUP_LISTEN_IP || "0.0.0.0",
port: 44444,
// 公网地址
announcedIp: process.env.MEDIASOUP_ANNOUNCED_IP || "192.168.1.110",
},
{
protocol: "tcp",
ip: process.env.MEDIASOUP_LISTEN_IP || "0.0.0.0",
port: 44444,
// 公网地址
announcedIp: process.env.MEDIASOUP_ANNOUNCED_IP || "192.168.1.110",
},
// TCP
// {
// protocol: "tcp",
// ip: process.env.MEDIASOUP_LISTEN_IP || "0.0.0.0",
// port: 44444,
// announcedIp: process.env.MEDIASOUP_ANNOUNCED_IP || "192.168.1.110",
// },
],
},
// WebRtcTransporthttps://mediasoup.org/documentation/v3/mediasoup/api/#WebRtcTransportOptions
@@ -138,7 +138,6 @@ module.exports = {
listenIps: [
{
ip: process.env.MEDIASOUP_LISTEN_IP || "0.0.0.0",
// 公网地址
announcedIp: process.env.MEDIASOUP_ANNOUNCED_IP || "192.168.1.110",
},
],
@@ -151,7 +150,6 @@ module.exports = {
plainTransportOptions: {
listenIp: {
ip: process.env.MEDIASOUP_LISTEN_IP || "0.0.0.0",
// 公网地址
announcedIp: process.env.MEDIASOUP_ANNOUNCED_IP || "192.168.1.110",
},
maxSctpMessageSize: 262144,

View File

@@ -44,7 +44,7 @@ async function buildMediasoupWorkers() {
JSON.stringify(config.mediasoup.webRtcServerOptions)
);
for (const listenInfo of webRtcServerOptions.listenInfos) {
listenInfo.port = listenInfo.port + mediasoupWorkers.length - 1;
listenInfo.port = listenInfo.port + mediasoupWorkers.length;
}
const webRtcServer = await worker.createWebRtcServer(webRtcServerOptions);
worker.appData.webRtcServer = webRtcServer;

View File

@@ -9,15 +9,23 @@ const protocol = {
// 当前索引
index: 0,
// 最大索引
maxIndex: 1000,
maxIndex: 999,
// 终端索引
clientIndex: 99999,
/**
* @returns 索引
*/
buildId() {
if (++this.index >= this.maxIndex) {
if (++this.index > this.maxIndex) {
this.index = 0;
}
return Date.now() * 1000 + this.index;
const date = new Date();
return 100000000000000 * date.getDate() +
1000000000000 * date.getHours() +
10000000000 * date.getMinutes() +
100000000 * date.getSeconds() +
1000 * this.clientIndex +
this.index;
},
/**
* 生成信令消息
@@ -188,15 +196,15 @@ const signalChannel = {
);
},
/**
* 推送消息
* 异步请求
*
* @param {*} message 消息
*/
push(message) {
push(message) {
try {
this.channel.send(JSON.stringify(message));
} catch (error) {
console.error("推送消息异常:", message, error);
console.error("异步请求异常:", message, error);
}
},
/**
@@ -375,6 +383,9 @@ class Signal {
case "client::shutdown":
this.clientShutdown(message, body);
break;
case "client::register":
protocol.clientIndex = body.index;
break;
case "media::ice::restart":
this.mediaIceRestart(message, body);
break;
@@ -400,15 +411,19 @@ class Signal {
}
/**
* 通知信令
* 异步请求
*
* @param {*} message 消息
*/
push(message) {
signalChannel.push(message);
try {
signalChannel.channel.send(JSON.stringify(message));
} catch (error) {
console.error("异步请求异常:", message, error);
}
}
/**
/**
* 同步请求
*
* @param {*} message 消息
@@ -416,24 +431,24 @@ class Signal {
* @returns Promise
*/
async request(message) {
const self = this;
const me = this;
return new Promise((resolve, reject) => {
let done = false;
// 注册回调
self.callbackMapping.set(message.header.id, (response) => {
me.callbackMapping.set(message.header.id, (response) => {
resolve(response);
done = true;
});
// 发送消息
try {
self.channel.send(JSON.stringify(message));
signalChannel.channel.send(JSON.stringify(message));
} catch (error) {
console.error("请求消息异常:", message, error);
reject("同步请求异常", error);
}
// 设置超时
setTimeout(() => {
if (!done) {
self.callbackMapping.delete(message.header.id);
me.callbackMapping.delete(message.header.id);
reject("请求超时", message);
}
}, 5000);