Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
b075c53f
提交
b075c53f
authored
7月 19, 2019
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disable test-node-sctp.js until node-sctp is fixed
上级
2a793efc
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
204 行增加
和
205 行删除
+204
-205
test-node-sctp.js
test/test-node-sctp.js
+204
-205
没有找到文件。
test/test-node-sctp.js
浏览文件 @
b075c53f
const
{
toBeType
}
=
require
(
'jest-tobetype'
);
//
const { toBeType } = require('jest-tobetype');
const
dgram
=
require
(
'dgram'
);
//
const dgram = require('dgram');
const
sctp
=
require
(
'sctp'
);
//
const sctp = require('sctp');
const
mediasoup
=
require
(
'../'
);
//
const mediasoup = require('../');
const
{
createWorker
}
=
mediasoup
;
//
const { createWorker } = mediasoup;
expect
.
extend
({
toBeType
});
//
expect.extend({ toBeType });
// Set node-sctp default PMTU to 1200.
// Set node-sctp default PMTU to 1200.
sctp
.
defaults
({
PMTU
:
1200
});
// sctp.defaults({ PMTU: 1200 });
let
worker
;
// TODO: Remove when https://github.com/latysheff/node-sctp/issues/11 is fixed.
let
router
;
test
.
todo
(
'ordered DataProducer delivers all SCTP messages to the DataConsumer'
);
let
transport
;
let
dataProducer
;
// let worker;
let
dataConsumer
;
// let router;
let
udpSocket
;
// let transport;
let
sctpSocket
;
// let dataProducer;
let
sctpSendStreamId
;
// let dataConsumer;
let
sctpSendStream
;
// let udpSocket;
// let sctpSocket;
beforeAll
(
async
()
=>
// let sctpSendStreamId;
{
// let sctpSendStream;
worker
=
await
createWorker
();
router
=
await
worker
.
createRouter
();
// beforeAll(async () =>
transport
=
await
router
.
createPlainRtpTransport
(
// {
{
// worker = await createWorker();
listenIp
:
'127.0.0.1'
,
// router = await worker.createRouter();
enableSctp
:
true
,
// transport = await router.createPlainRtpTransport(
numSctpStreams
:
{
OS
:
256
,
MIS
:
256
}
// {
});
// listenIp : '127.0.0.1',
// comedia : true, // So we don't need to call transport.connect().
// Node UDP socket for SCTP.
// enableSctp : true,
udpSocket
=
dgram
.
createSocket
({
type
:
'udp4'
});
// numSctpStreams : { OS: 256, MIS: 256 }
// });
await
new
Promise
((
resolve
)
=>
udpSocket
.
bind
(
0
,
'127.0.0.1'
,
resolve
));
// // Node UDP socket for SCTP.
const
localUdpPort
=
udpSocket
.
address
().
port
;
// udpSocket = dgram.createSocket({ type: 'udp4' });
// Connect the mediasoup PlainRtpTransport to the UDP socket port.
// await new Promise((resolve) => udpSocket.bind(0, '127.0.0.1', resolve));
await
transport
.
connect
({
ip
:
'127.0.0.1'
,
port
:
localUdpPort
});
// const remoteUdpIp = transport.tuple.localIp;
const
remoteUdpIp
=
transport
.
tuple
.
localIp
;
// const remoteUdpPort = transport.tuple.localPort;
const
remoteUdpPort
=
transport
.
tuple
.
localPort
;
// const { OS, MIS } = transport.sctpParameters;
const
{
OS
,
MIS
}
=
transport
.
sctpParameters
;
// // Use UDP connected socket if Node >= 12.
// Use UDP connected socket if Node >= 12.
// if (typeof udpSocket.connect === 'function')
if
(
typeof
udpSocket
.
connect
===
'function'
)
// {
{
// await new Promise((resolve, reject) =>
await
new
Promise
((
resolve
,
reject
)
=>
// {
{
// udpSocket.connect(remoteUdpPort, remoteUdpIp, (error) =>
udpSocket
.
connect
(
remoteUdpPort
,
remoteUdpIp
,
(
error
)
=>
// {
{
// if (error)
if
(
error
)
// {
{
// reject(error);
reject
(
error
);
// return;
return
;
// }
}
// sctpSocket = sctp.connect(
sctpSocket
=
sctp
.
connect
(
// {
{
// localPort : 5000, // Required for SCTP over UDP in mediasoup.
localPort
:
5000
,
// Required for SCTP over UDP in mediasoup.
// port : 5000, // Required for SCTP over UDP in mediasoup.
port
:
5000
,
// Required for SCTP over UDP in mediasoup.
// OS : OS,
OS
:
OS
,
// MIS : MIS,
MIS
:
MIS
,
// udpTransport : udpSocket
udpTransport
:
udpSocket
// });
});
// resolve();
resolve
();
// });
});
// });
});
// }
}
// // Use UDP disconnected socket if Node < 12.
// Use UDP disconnected socket if Node < 12.
// else
else
// {
{
// sctpSocket = sctp.connect(
sctpSocket
=
sctp
.
connect
(
// {
{
// localPort : 5000, // Required for SCTP over UDP in mediasoup.
localPort
:
5000
,
// Required for SCTP over UDP in mediasoup.
// port : 5000, // Required for SCTP over UDP in mediasoup.
port
:
5000
,
// Required for SCTP over UDP in mediasoup.
// OS : OS,
OS
:
OS
,
// MIS : MIS,
MIS
:
MIS
,
// udpTransport : udpSocket,
udpTransport
:
udpSocket
,
// udpPeer :
udpPeer
:
// {
{
// address : remoteUdpIp,
address
:
remoteUdpIp
,
// port : remoteUdpPort
port
:
remoteUdpPort
// }
}
// });
});
// }
}
// // Create an explicit SCTP outgoing stream with id 123 (id 0 is already used
// Create an explicit SCTP outgoing stream with id 123 (id 0 is already used
// // by the implicit SCTP outgoing stream built-in the SCTP socket).
// by the implicit SCTP outgoing stream built-in the SCTP socket).
// sctpSendStreamId = 123;
sctpSendStreamId
=
123
;
// sctpSendStream = sctpSocket.createStream(sctpSendStreamId);
sctpSendStream
=
sctpSocket
.
createStream
(
sctpSendStreamId
);
// // Create a DataProducer with the corresponding SCTP stream id.
// Create a DataProducer with the corresponding SCTP stream id.
// dataProducer = await transport.produceData(
dataProducer
=
await
transport
.
produceData
(
// {
{
// sctpStreamParameters :
sctpStreamParameters
:
// {
{
// streamId : sctpSendStreamId,
streamId
:
sctpSendStreamId
,
// ordered : true
ordered
:
true
// },
},
// label : 'node-sctp',
label
:
'node-sctp'
,
// protocol : 'foo & bar 😀😀😀'
protocol
:
'foo & bar 😀😀😀'
// });
});
// // Create a DataConsumer to receive messages from the DataProducer over the
// Create a DataConsumer to receive messages from the DataProducer over the
// // same transport.
// same transport.
// dataConsumer = await transport.consumeData({ dataProducerId: dataProducer.id });
dataConsumer
=
await
transport
.
consumeData
({
dataProducerId
:
dataProducer
.
id
});
// });
});
// afterAll(() =>
afterAll
(()
=>
// {
{
// udpSocket.close();
udpSocket
.
close
();
// sctpSocket.end();
sctpSocket
.
end
();
// worker.close();
worker
.
close
();
// });
});
// test('ordered DataProducer delivers all SCTP messages to the DataConsumer', async () =>
test
(
'ordered DataProducer delivers all SCTP messages to the DataConsumer'
,
async
()
=>
// {
{
// const onStream = jest.fn();
const
onStream
=
jest
.
fn
();
// const numMessages = 200;
const
numMessages
=
200
;
// let sentMessageBytes = 0;
let
sentMessageBytes
=
0
;
// let recvMessageBytes = 0;
let
recvMessageBytes
=
0
;
// let lastSentMessageId = 0;
let
lastSentMessageId
=
0
;
// let lastRecvMessageId = 0;
let
lastRecvMessageId
=
0
;
// // It must be zero because it's the first DataConsumer on the transport.
// It must be zero because it's the first DataConsumer on the transport.
// expect(dataConsumer.sctpStreamParameters.streamId).toBe(0);
expect
(
dataConsumer
.
sctpStreamParameters
.
streamId
).
toBe
(
0
);
// await new Promise((resolve) =>
await
new
Promise
((
resolve
)
=>
// {
{
// // Send SCTP messages over the sctpSendStream created above.
// Send SCTP messages over the sctpSendStream created above.
// const interval = setInterval(() =>
const
interval
=
setInterval
(()
=>
// {
{
// const id = ++lastSentMessageId;
const
id
=
++
lastSentMessageId
;
// const data = Buffer.from(String(id));
const
data
=
Buffer
.
from
(
String
(
id
));
// // Set ppid of type WebRTC DataChannel string.
// Set ppid of type WebRTC DataChannel string.
// data.ppid = sctp.PPID.WEBRTC_STRING;
data
.
ppid
=
sctp
.
PPID
.
WEBRTC_STRING
;
// sctpSendStream.write(data);
sctpSendStream
.
write
(
data
);
// sentMessageBytes += data.byteLength;
sentMessageBytes
+=
data
.
byteLength
;
// if (id === numMessages)
if
(
id
===
numMessages
)
// clearInterval(interval);
clearInterval
(
interval
);
// }, 10);
},
10
);
// sctpSocket.on('stream', onStream);
sctpSocket
.
on
(
'stream'
,
onStream
);
// // Handle the generated SCTP incoming stream and SCTP messages receives on it.
// Handle the generated SCTP incoming stream and SCTP messages receives on it.
// sctpSocket.on('stream', (stream, streamId) =>
sctpSocket
.
on
(
'stream'
,
(
stream
,
streamId
)
=>
// {
{
// // It must be zero because it's the first SCTP incoming stream (so first
// It must be zero because it's the first SCTP incoming stream (so first
// // DataConsumer).
// DataConsumer).
// expect(streamId).toBe(0);
expect
(
streamId
).
toBe
(
0
);
// stream.on('data', (data) =>
stream
.
on
(
'data'
,
(
data
)
=>
// {
{
// recvMessageBytes += data.byteLength;
recvMessageBytes
+=
data
.
byteLength
;
// const id = Number(data.toString('utf8'));
const
id
=
Number
(
data
.
toString
(
'utf8'
));
// if (id === numMessages)
if
(
id
===
numMessages
)
// {
{
// clearInterval(interval);
clearInterval
(
interval
);
// resolve();
resolve
();
// }
}
// expect(data.ppid).toBe(sctp.PPID.WEBRTC_STRING);
expect
(
data
.
ppid
).
toBe
(
sctp
.
PPID
.
WEBRTC_STRING
);
// expect(id).toBe(++lastRecvMessageId);
expect
(
id
).
toBe
(
++
lastRecvMessageId
);
// });
});
// });
});
// });
});
// expect(onStream).toHaveBeenCalledTimes(1);
expect
(
onStream
).
toHaveBeenCalledTimes
(
1
);
// expect(lastSentMessageId).toBe(numMessages);
expect
(
lastSentMessageId
).
toBe
(
numMessages
);
// expect(lastRecvMessageId).toBe(numMessages);
expect
(
lastRecvMessageId
).
toBe
(
numMessages
);
// expect(recvMessageBytes).toBe(sentMessageBytes);
expect
(
recvMessageBytes
).
toBe
(
sentMessageBytes
);
// await expect(dataProducer.getStats())
await
expect
(
dataProducer
.
getStats
())
// .resolves
.
resolves
// .toStrictEqual(
.
toStrictEqual
(
// [
[
// {
{
// type : 'data-producer',
type
:
'data-producer'
,
// label : dataProducer.label,
label
:
dataProducer
.
label
,
// protocol : dataProducer.protocol,
protocol
:
dataProducer
.
protocol
,
// messagesReceived : numMessages,
messagesReceived
:
numMessages
,
// bytesReceived : sentMessageBytes
bytesReceived
:
sentMessageBytes
// }
}
// ]);
]);
// await expect(dataConsumer.getStats())
await
expect
(
dataConsumer
.
getStats
())
// .resolves
.
resolves
// .toStrictEqual(
.
toStrictEqual
(
// [
[
// {
{
// type : 'data-consumer',
type
:
'data-consumer'
,
// label : dataConsumer.label,
label
:
dataConsumer
.
label
,
// protocol : dataConsumer.protocol,
protocol
:
dataConsumer
.
protocol
,
// messagesSent : numMessages,
messagesSent
:
numMessages
,
// bytesSent : recvMessageBytes
bytesSent
:
recvMessageBytes
// }
}
// ]);
]);
// }, 8000);
},
8000
);
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论