Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
d09586fe
提交
d09586fe
authored
2月 20, 2020
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TypeScript: generate es2020 instead of es6
上级
40ae625a
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
740 行增加
和
974 行删除
+740
-974
CHANGELOG.md
CHANGELOG.md
+1
-0
Channel.js
lib/Channel.js
+41
-52
Consumer.js
lib/Consumer.js
+44
-71
DataConsumer.js
lib/DataConsumer.js
+6
-19
DataProducer.js
lib/DataProducer.js
+6
-19
EnhancedEventEmitter.js
lib/EnhancedEventEmitter.js
+2
-13
PipeTransport.js
lib/PipeTransport.js
+42
-57
PlainRtpTransport.js
lib/PlainRtpTransport.js
+14
-32
Producer.js
lib/Producer.js
+26
-45
Router.js
lib/Router.js
+287
-308
RtpObserver.js
lib/RtpObserver.js
+30
-47
Transport.js
lib/Transport.js
+176
-203
WebRtcTransport.js
lib/WebRtcTransport.js
+15
-30
Worker.js
lib/Worker.js
+29
-46
index.js
lib/index.js
+19
-30
ortc.js
lib/ortc.js
+1
-1
tsconfig.json
tsconfig.json
+1
-1
没有找到文件。
CHANGELOG.md
浏览文件 @
d09586fe
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
### 3.4.12 (WIP)
### 3.4.12 (WIP)
*
TypeScript: generate
`es2020`
instead of
`es6`
.
*
Update
`usrsctp`
library.
*
Update
`usrsctp`
library.
-
Fixes #362 (thanks @chvarlam for reporting it).
-
Fixes #362 (thanks @chvarlam for reporting it).
...
...
lib/Channel.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
var
result
=
{};
...
@@ -150,49 +141,47 @@ class Channel extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -150,49 +141,47 @@ class Channel extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* @private
* @private
*/
*/
request
(
method
,
internal
,
data
)
{
async
request
(
method
,
internal
,
data
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
this
.
_nextId
<
4294967295
?
++
this
.
_nextId
:
(
this
.
_nextId
=
1
);
this
.
_nextId
<
4294967295
?
++
this
.
_nextId
:
(
this
.
_nextId
=
1
);
const
id
=
this
.
_nextId
;
const
id
=
this
.
_nextId
;
logger
.
debug
(
'request() [method:%s, id:%s]'
,
method
,
id
);
logger
.
debug
(
'request() [method:%s, id:%s]'
,
method
,
id
);
if
(
this
.
_closed
)
if
(
this
.
_closed
)
throw
new
errors_1
.
InvalidStateError
(
'Channel closed'
);
throw
new
errors_1
.
InvalidStateError
(
'Channel closed'
);
const
request
=
{
id
,
method
,
internal
,
data
};
const
request
=
{
id
,
method
,
internal
,
data
};
const
ns
=
netstring
.
nsWrite
(
JSON
.
stringify
(
request
));
const
ns
=
netstring
.
nsWrite
(
JSON
.
stringify
(
request
));
if
(
Buffer
.
byteLength
(
ns
)
>
NS_MESSAGE_MAX_LEN
)
if
(
Buffer
.
byteLength
(
ns
)
>
NS_MESSAGE_MAX_LEN
)
throw
new
Error
(
'Channel request too big'
);
throw
new
Error
(
'Channel request too big'
);
// This may throw if closed or remote side ended.
// This may throw if closed or remote side ended.
this
.
_producerSocket
.
write
(
ns
);
this
.
_producerSocket
.
write
(
ns
);
return
new
Promise
((
pResolve
,
pReject
)
=>
{
return
new
Promise
((
pResolve
,
pReject
)
=>
{
const
timeout
=
1000
*
(
15
+
(
0.1
*
this
.
_sents
.
size
));
const
timeout
=
1000
*
(
15
+
(
0.1
*
this
.
_sents
.
size
));
const
sent
=
{
const
sent
=
{
id
:
id
,
id
:
id
,
method
:
method
,
method
:
method
,
resolve
:
(
data2
)
=>
{
resolve
:
(
data2
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
return
;
clearTimeout
(
sent
.
timer
);
clearTimeout
(
sent
.
timer
);
pResolve
(
data2
);
pResolve
(
data2
);
},
},
reject
:
(
error
)
=>
{
reject
:
(
error
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
return
;
clearTimeout
(
sent
.
timer
);
clearTimeout
(
sent
.
timer
);
pReject
(
error
);
pReject
(
error
);
},
},
timer
:
setTimeout
(()
=>
{
timer
:
setTimeout
(()
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
return
;
pReject
(
new
Error
(
'Channel request timeout'
));
pReject
(
new
Error
(
'Channel request timeout'
));
},
timeout
),
},
timeout
),
close
:
()
=>
{
close
:
()
=>
{
clearTimeout
(
sent
.
timer
);
clearTimeout
(
sent
.
timer
);
pReject
(
new
errors_1
.
InvalidStateError
(
'Channel closed'
));
pReject
(
new
errors_1
.
InvalidStateError
(
'Channel closed'
));
}
}
};
};
// Add sent stuff to the map.
// Add sent stuff to the map.
this
.
_sents
.
set
(
id
,
sent
);
this
.
_sents
.
set
(
id
,
sent
);
});
});
});
}
}
_processMessage
(
msg
)
{
_processMessage
(
msg
)
{
...
...
lib/Consumer.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
@@ -184,100 +175,82 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -184,100 +175,82 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump Consumer.
* Dump Consumer.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'consumer.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'consumer.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Get Consumer stats.
* Get Consumer stats.
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'consumer.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'consumer.getStats'
,
this
.
_internal
);
});
}
}
/**
/**
* Pause the Consumer.
* Pause the Consumer.
*/
*/
pause
()
{
async
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
await
this
.
_channel
.
request
(
'consumer.pause'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'consumer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
this
.
_paused
=
true
;
// Emit observer event.
// Emit observer event.
if
(
!
wasPaused
)
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
this
.
_observer
.
safeEmit
(
'pause'
);
});
}
}
/**
/**
* Resume the Consumer.
* Resume the Consumer.
*/
*/
resume
()
{
async
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
await
this
.
_channel
.
request
(
'consumer.resume'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'consumer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
this
.
_paused
=
false
;
// Emit observer event.
// Emit observer event.
if
(
wasPaused
&&
!
this
.
_producerPaused
)
if
(
wasPaused
&&
!
this
.
_producerPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
this
.
_observer
.
safeEmit
(
'resume'
);
});
}
}
/**
/**
* Set preferred video layers.
* Set preferred video layers.
*/
*/
setPreferredLayers
({
spatialLayer
,
temporalLayer
})
{
async
setPreferredLayers
({
spatialLayer
,
temporalLayer
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setPreferredLayers()'
);
logger
.
debug
(
'setPreferredLayers()'
);
const
reqData
=
{
spatialLayer
,
temporalLayer
};
const
reqData
=
{
spatialLayer
,
temporalLayer
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPreferredLayers'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPreferredLayers'
,
this
.
_internal
,
reqData
);
this
.
_preferredLayers
=
data
||
null
;
this
.
_preferredLayers
=
data
||
null
;
});
}
}
/**
/**
* Set priority.
* Set priority.
*/
*/
setPriority
(
priority
)
{
async
setPriority
(
priority
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setPriority()'
);
logger
.
debug
(
'setPriority()'
);
const
reqData
=
{
priority
};
const
reqData
=
{
priority
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
this
.
_priority
=
data
.
priority
;
});
}
}
/**
/**
* Unset priority.
* Unset priority.
*/
*/
unsetPriority
()
{
async
unsetPriority
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'unsetPriority()'
);
logger
.
debug
(
'unsetPriority()'
);
const
reqData
=
{
priority
:
1
};
const
reqData
=
{
priority
:
1
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
this
.
_priority
=
data
.
priority
;
});
}
}
/**
/**
* Request a key frame to the Producer.
* Request a key frame to the Producer.
*/
*/
requestKeyFrame
()
{
async
requestKeyFrame
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'requestKeyFrame()'
);
logger
.
debug
(
'requestKeyFrame()'
);
await
this
.
_channel
.
request
(
'consumer.requestKeyFrame'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'consumer.requestKeyFrame'
,
this
.
_internal
);
});
}
}
/**
/**
* Enable 'trace' event.
* Enable 'trace' event.
*/
*/
enableTraceEvent
(
types
=
[])
{
async
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'enableTraceEvent()'
);
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'consumer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
yield
this
.
_channel
.
request
(
'consumer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
consumerId
,
(
event
,
data
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
consumerId
,
(
event
,
data
)
=>
{
...
...
lib/DataConsumer.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
@@ -124,20 +115,16 @@ class DataConsumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -124,20 +115,16 @@ class DataConsumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump DataConsumer.
* Dump DataConsumer.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataConsumer.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'dataConsumer.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Get DataConsumer stats.
* Get DataConsumer stats.
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataConsumer.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'dataConsumer.getStats'
,
this
.
_internal
);
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
dataConsumerId
,
(
event
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
dataConsumerId
,
(
event
)
=>
{
...
...
lib/DataProducer.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
@@ -114,20 +105,16 @@ class DataProducer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -114,20 +105,16 @@ class DataProducer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump DataProducer.
* Dump DataProducer.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataProducer.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'dataProducer.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Get DataProducer stats.
* Get DataProducer stats.
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataProducer.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'dataProducer.getStats'
,
this
.
_internal
);
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
// No need to subscribe to any event.
// No need to subscribe to any event.
...
...
lib/EnhancedEventEmitter.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
events_1
=
require
(
"events"
);
const
events_1
=
require
(
"events"
);
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
...
@@ -27,10 +18,8 @@ class EnhancedEventEmitter extends events_1.EventEmitter {
...
@@ -27,10 +18,8 @@ class EnhancedEventEmitter extends events_1.EventEmitter {
return
Boolean
(
numListeners
);
return
Boolean
(
numListeners
);
}
}
}
}
safeEmitAsPromise
(
event
,
...
args
)
{
async
safeEmitAsPromise
(
event
,
...
args
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
return
new
Promise
((
resolve
,
reject
)
=>
(
this
.
safeEmit
(
event
,
...
args
,
resolve
,
reject
)));
return
new
Promise
((
resolve
,
reject
)
=>
(
this
.
safeEmit
(
event
,
...
args
,
resolve
,
reject
)));
});
}
}
}
}
exports
.
EnhancedEventEmitter
=
EnhancedEventEmitter
;
exports
.
EnhancedEventEmitter
=
EnhancedEventEmitter
;
lib/PipeTransport.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
};
...
@@ -119,67 +110,61 @@ class PipeTransport extends Transport_1.Transport {
...
@@ -119,67 +110,61 @@ class PipeTransport extends Transport_1.Transport {
*
*
* @override
* @override
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
}
}
/**
/**
* Provide the PipeTransport remote parameters.
* Provide the PipeTransport remote parameters.
*
*
* @override
* @override
*/
*/
connect
({
ip
,
port
})
{
async
connect
({
ip
,
port
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
};
const
reqData
=
{
ip
,
port
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
tuple
=
data
.
tuple
;
});
}
}
/**
/**
* Create a pipe Consumer.
* Create a pipe Consumer.
*
*
* @override
* @override
*/
*/
consume
({
producerId
,
appData
=
{}
})
{
async
consume
({
producerId
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consume()'
);
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
// This may throw.
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
producer
.
consumableRtpParameters
);
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
producer
.
consumableRtpParameters
);
const
internal
=
{
...
this
.
_internal
,
consumerId
:
v4_1
.
default
(),
producerId
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
consumerId
:
v4_1
.
default
(),
producerId
});
const
reqData
=
{
const
reqData
=
{
kind
:
producer
.
kind
,
kind
:
producer
.
kind
,
rtpParameters
,
rtpParameters
,
type
:
'pipe'
,
type
:
'pipe'
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
};
};
const
status
=
await
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
status
=
yield
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
};
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
};
const
consumer
=
new
Consumer_1
.
Consumer
({
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
,
appData
,
paused
:
status
.
paused
,
paused
:
status
.
paused
,
producerPaused
:
status
.
producerPaused
producerPaused
:
status
.
producerPaused
});
this
.
_consumers
.
set
(
consumer
.
id
,
consumer
);
consumer
.
on
(
'@close'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
consumer
.
on
(
'@producerclose'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newconsumer'
,
consumer
);
return
consumer
;
});
});
this
.
_consumers
.
set
(
consumer
.
id
,
consumer
);
consumer
.
on
(
'@close'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
consumer
.
on
(
'@producerclose'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newconsumer'
,
consumer
);
return
consumer
;
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/PlainRtpTransport.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
Transport_1
=
require
(
"./Transport"
);
const
Transport_1
=
require
(
"./Transport"
);
...
@@ -122,41 +113,32 @@ class PlainRtpTransport extends Transport_1.Transport {
...
@@ -122,41 +113,32 @@ class PlainRtpTransport extends Transport_1.Transport {
*
*
* @override
* @override
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
}
}
/**
/**
* Provide the PlainRtpTransport remote parameters.
* Provide the PlainRtpTransport remote parameters.
*
*
* @override
* @override
*/
*/
connect
({
ip
,
port
,
rtcpPort
})
{
async
connect
({
ip
,
port
,
rtcpPort
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
});
}
}
/**
/**
* Override Transport.consume() method to reject it if multiSource is set.
* Override Transport.consume() method to reject it if multiSource is set.
*
*
* @override
* @override
*/
*/
consume
(
params
)
{
async
consume
(
params
)
{
const
_super
=
Object
.
create
(
null
,
{
if
(
this
.
_data
.
multiSource
)
consume
:
{
get
:
()
=>
super
.
consume
}
throw
new
Error
(
'cannot call consume() with multiSource set'
);
});
return
super
.
consume
(
params
);
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
if
(
this
.
_data
.
multiSource
)
throw
new
Error
(
'cannot call consume() with multiSource set'
);
return
_super
.
consume
.
call
(
this
,
params
);
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/Producer.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
@@ -149,58 +140,48 @@ class Producer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -149,58 +140,48 @@ class Producer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump Producer.
* Dump Producer.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'producer.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'producer.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Get Producer stats.
* Get Producer stats.
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'producer.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'producer.getStats'
,
this
.
_internal
);
});
}
}
/**
/**
* Pause the Producer.
* Pause the Producer.
*/
*/
pause
()
{
async
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'producer.pause'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'producer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
this
.
_paused
=
true
;
// Emit observer event.
// Emit observer event.
if
(
!
wasPaused
)
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
this
.
_observer
.
safeEmit
(
'pause'
);
});
}
}
/**
/**
* Resume the Producer.
* Resume the Producer.
*/
*/
resume
()
{
async
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'producer.resume'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'producer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
this
.
_paused
=
false
;
// Emit observer event.
// Emit observer event.
if
(
wasPaused
)
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
this
.
_observer
.
safeEmit
(
'resume'
);
});
}
}
/**
/**
* Enable 'trace' event.
* Enable 'trace' event.
*/
*/
enableTraceEvent
(
types
=
[])
{
async
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'enableTraceEvent()'
);
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'producer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
yield
this
.
_channel
.
request
(
'producer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
producerId
,
(
event
,
data
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
producerId
,
(
event
,
data
)
=>
{
...
...
lib/Router.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
};
...
@@ -165,342 +156,330 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -165,342 +156,330 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump Router.
* Dump Router.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'router.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'router.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Create a WebRtcTransport.
* Create a WebRtcTransport.
*/
*/
createWebRtcTransport
({
listenIps
,
enableUdp
=
true
,
enableTcp
=
false
,
preferUdp
=
false
,
preferTcp
=
false
,
initialAvailableOutgoingBitrate
=
600000
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
async
createWebRtcTransport
({
listenIps
,
enableUdp
=
true
,
enableTcp
=
false
,
preferUdp
=
false
,
preferTcp
=
false
,
initialAvailableOutgoingBitrate
=
600000
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createWebRtcTransport()'
);
logger
.
debug
(
'createWebRtcTransport()'
);
if
(
!
Array
.
isArray
(
listenIps
))
if
(
!
Array
.
isArray
(
listenIps
))
throw
new
TypeError
(
'missing listenIps'
);
throw
new
TypeError
(
'missing listenIps'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
listenIps
=
listenIps
.
map
((
listenIp
)
=>
{
listenIps
=
listenIps
.
map
((
listenIp
)
=>
{
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
return
{
ip
:
listenIp
};
}
else
if
(
typeof
listenIp
===
'object'
)
{
return
{
ip
:
listenIp
.
ip
,
announcedIp
:
listenIp
.
announcedIp
||
undefined
};
}
else
{
throw
new
TypeError
(
'wrong listenIp'
);
}
});
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
transportId
:
v4_1
.
default
()
});
const
reqData
=
{
listenIps
,
enableUdp
,
enableTcp
,
preferUdp
,
preferTcp
,
initialAvailableOutgoingBitrate
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
true
};
const
data
=
yield
this
.
_channel
.
request
(
'router.createWebRtcTransport'
,
internal
,
reqData
);
const
transport
=
new
WebRtcTransport_1
.
WebRtcTransport
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
});
}
/**
* Create a PlainRtpTransport.
*/
createPlainRtpTransport
({
listenIp
,
rtcpMux
=
true
,
comedia
=
false
,
multiSource
=
false
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createPlainRtpTransport()'
);
if
(
!
listenIp
)
throw
new
TypeError
(
'missing listenIp'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
listenIp
=
{
ip
:
listenIp
};
return
{
ip
:
listenIp
};
}
}
else
if
(
typeof
listenIp
===
'object'
)
{
else
if
(
typeof
listenIp
===
'object'
)
{
listenIp
=
return
{
{
ip
:
listenIp
.
ip
,
ip
:
listenIp
.
ip
,
announcedIp
:
listenIp
.
announcedIp
||
undefined
announcedIp
:
listenIp
.
announcedIp
||
undefined
};
};
}
}
else
{
else
{
throw
new
TypeError
(
'wrong listenIp'
);
throw
new
TypeError
(
'wrong listenIp'
);
}
}
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
transportId
:
v4_1
.
default
()
});
const
reqData
=
{
listenIp
,
rtcpMux
,
comedia
,
multiSource
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
};
const
data
=
yield
this
.
_channel
.
request
(
'router.createPlainRtpTransport'
,
internal
,
reqData
);
const
transport
=
new
PlainRtpTransport_1
.
PlainRtpTransport
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
});
});
const
internal
=
{
...
this
.
_internal
,
transportId
:
v4_1
.
default
()
};
const
reqData
=
{
listenIps
,
enableUdp
,
enableTcp
,
preferUdp
,
preferTcp
,
initialAvailableOutgoingBitrate
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
true
};
const
data
=
await
this
.
_channel
.
request
(
'router.createWebRtcTransport'
,
internal
,
reqData
);
const
transport
=
new
WebRtcTransport_1
.
WebRtcTransport
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
}
/**
* Create a PlainRtpTransport.
*/
async
createPlainRtpTransport
({
listenIp
,
rtcpMux
=
true
,
comedia
=
false
,
multiSource
=
false
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
logger
.
debug
(
'createPlainRtpTransport()'
);
if
(
!
listenIp
)
throw
new
TypeError
(
'missing listenIp'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
listenIp
=
{
ip
:
listenIp
};
}
else
if
(
typeof
listenIp
===
'object'
)
{
listenIp
=
{
ip
:
listenIp
.
ip
,
announcedIp
:
listenIp
.
announcedIp
||
undefined
};
}
else
{
throw
new
TypeError
(
'wrong listenIp'
);
}
const
internal
=
{
...
this
.
_internal
,
transportId
:
v4_1
.
default
()
};
const
reqData
=
{
listenIp
,
rtcpMux
,
comedia
,
multiSource
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
};
const
data
=
await
this
.
_channel
.
request
(
'router.createPlainRtpTransport'
,
internal
,
reqData
);
const
transport
=
new
PlainRtpTransport_1
.
PlainRtpTransport
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
}
}
/**
/**
* Create a PipeTransport.
* Create a PipeTransport.
*/
*/
createPipeTransport
({
listenIp
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
1073741823
,
appData
=
{}
})
{
async
createPipeTransport
({
listenIp
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
1073741823
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createPipeTransport()'
);
logger
.
debug
(
'createPipeTransport()'
);
if
(
!
listenIp
)
if
(
!
listenIp
)
throw
new
TypeError
(
'missing listenIp'
);
throw
new
TypeError
(
'missing listenIp'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
listenIp
=
{
ip
:
listenIp
};
listenIp
=
{
ip
:
listenIp
};
}
}
else
if
(
typeof
listenIp
===
'object'
)
{
else
if
(
typeof
listenIp
===
'object'
)
{
listenIp
=
listenIp
=
{
{
ip
:
listenIp
.
ip
,
ip
:
listenIp
.
ip
,
announcedIp
:
listenIp
.
announcedIp
||
undefined
announcedIp
:
listenIp
.
announcedIp
||
undefined
};
};
}
}
else
{
else
{
throw
new
TypeError
(
'wrong listenIp'
);
throw
new
TypeError
(
'wrong listenIp'
);
}
}
const
internal
=
{
...
this
.
_internal
,
transportId
:
v4_1
.
default
()
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
transportId
:
v4_1
.
default
()
});
const
reqData
=
{
const
reqData
=
{
listenIp
,
listenIp
,
enableSctp
,
enableSctp
,
numSctpStreams
,
numSctpStreams
,
maxSctpMessageSize
,
maxSctpMessageSize
,
isDataChannel
:
false
isDataChannel
:
false
};
};
const
data
=
await
this
.
_channel
.
request
(
'router.createPipeTransport'
,
internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'router.createPipeTransport'
,
internal
,
reqData
);
const
transport
=
new
PipeTransport_1
.
PipeTransport
({
const
transport
=
new
PipeTransport_1
.
PipeTransport
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
,
appData
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getRouterRtpCapabilities
:
()
=>
this
.
_data
.
rtpCapabilities
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
)),
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
getDataProducerById
:
(
dataProducerId
)
=>
(
this
.
_dataProducers
.
get
(
dataProducerId
))
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
});
});
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
transport
.
on
(
'@newproducer'
,
(
producer
)
=>
this
.
_producers
.
set
(
producer
.
id
,
producer
));
transport
.
on
(
'@producerclose'
,
(
producer
)
=>
this
.
_producers
.
delete
(
producer
.
id
));
transport
.
on
(
'@newdataproducer'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
)));
transport
.
on
(
'@dataproducerclose'
,
(
dataProducer
)
=>
(
this
.
_dataProducers
.
delete
(
dataProducer
.
id
)));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newtransport'
,
transport
);
return
transport
;
}
}
/**
/**
* Pipes the given Producer or DataProducer into another Router in same host.
* Pipes the given Producer or DataProducer into another Router in same host.
*/
*/
pipeToRouter
({
producerId
,
dataProducerId
,
router
,
listenIp
=
'127.0.0.1'
,
enableSctp
=
true
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
}
})
{
async
pipeToRouter
({
producerId
,
dataProducerId
,
router
,
listenIp
=
'127.0.0.1'
,
enableSctp
=
true
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
if
(
!
producerId
&&
!
dataProducerId
)
if
(
!
producerId
&&
!
dataProducerId
)
throw
new
TypeError
(
'missing producerId or dataProducerId'
);
throw
new
TypeError
(
'missing producerId or dataProducerId'
);
else
if
(
producerId
&&
dataProducerId
)
else
if
(
producerId
&&
dataProducerId
)
throw
new
TypeError
(
'just producerId or dataProducerId can be given'
);
throw
new
TypeError
(
'just producerId or dataProducerId can be given'
);
else
if
(
!
router
)
else
if
(
!
router
)
throw
new
TypeError
(
'Router not found'
);
throw
new
TypeError
(
'Router not found'
);
else
if
(
router
===
this
)
else
if
(
router
===
this
)
throw
new
TypeError
(
'cannot use this Router as destination'
);
throw
new
TypeError
(
'cannot use this Router as destination'
);
let
producer
;
let
producer
;
let
dataProducer
;
let
dataProducer
;
if
(
producerId
)
{
if
(
producerId
)
{
producer
=
this
.
_producers
.
get
(
producerId
);
producer
=
this
.
_producers
.
get
(
producerId
);
if
(
!
producer
)
if
(
!
producer
)
throw
new
TypeError
(
'Producer not found'
);
throw
new
TypeError
(
'Producer not found'
);
}
}
else
if
(
dataProducerId
)
{
else
if
(
dataProducerId
)
{
dataProducer
=
this
.
_dataProducers
.
get
(
dataProducerId
);
dataProducer
=
this
.
_dataProducers
.
get
(
dataProducerId
);
if
(
!
dataProducer
)
if
(
!
dataProducer
)
throw
new
TypeError
(
'DataProducer not found'
);
throw
new
TypeError
(
'DataProducer not found'
);
}
// Here we may have to create a new PipeTransport pair to connect source and
// destination Routers. We just want to keep a PipeTransport pair for each
// pair of Routers. Since this operation is async, it may happen that two
// simultaneous calls to router1.pipeToRouter({ producerId: xxx, router: router2 })
// would end up generating two pairs of PipeTranports. To prevent that, let's
// use an async queue.
let
localPipeTransport
;
let
remotePipeTransport
;
await
this
.
_pipeToRouterQueue
.
push
(
async
()
=>
{
let
pipeTransportPair
=
this
.
_mapRouterPipeTransports
.
get
(
router
);
if
(
pipeTransportPair
)
{
localPipeTransport
=
pipeTransportPair
[
0
];
remotePipeTransport
=
pipeTransportPair
[
1
];
}
}
// Here we may have to create a new PipeTransport pair to connect source and
else
{
// destination Routers. We just want to keep a PipeTransport pair for each
try
{
// pair of Routers. Since this operation is async, it may happen that two
pipeTransportPair
=
await
Promise
.
all
([
// simultaneous calls to router1.pipeToRouter({ producerId: xxx, router: router2 })
this
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
}),
// would end up generating two pairs of PipeTranports. To prevent that, let's
router
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
})
// use an async queue.
]);
let
localPipeTransport
;
let
remotePipeTransport
;
yield
this
.
_pipeToRouterQueue
.
push
(()
=>
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
let
pipeTransportPair
=
this
.
_mapRouterPipeTransports
.
get
(
router
);
if
(
pipeTransportPair
)
{
localPipeTransport
=
pipeTransportPair
[
0
];
localPipeTransport
=
pipeTransportPair
[
0
];
remotePipeTransport
=
pipeTransportPair
[
1
];
remotePipeTransport
=
pipeTransportPair
[
1
];
}
await
Promise
.
all
([
else
{
localPipeTransport
.
connect
({
try
{
ip
:
remotePipeTransport
.
tuple
.
localIp
,
pipeTransportPair
=
yield
Promise
.
all
([
port
:
remotePipeTransport
.
tuple
.
localPort
this
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
}),
}),
router
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
})
remotePipeTransport
.
connect
({
]);
ip
:
localPipeTransport
.
tuple
.
localIp
,
localPipeTransport
=
pipeTransportPair
[
0
];
port
:
localPipeTransport
.
tuple
.
localPort
remotePipeTransport
=
pipeTransportPair
[
1
];
})
yield
Promise
.
all
([
]);
localPipeTransport
.
connect
({
localPipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
ip
:
remotePipeTransport
.
tuple
.
localIp
,
remotePipeTransport
.
close
();
port
:
remotePipeTransport
.
tuple
.
localPort
this
.
_mapRouterPipeTransports
.
delete
(
router
);
}),
remotePipeTransport
.
connect
({
ip
:
localPipeTransport
.
tuple
.
localIp
,
port
:
localPipeTransport
.
tuple
.
localPort
})
]);
localPipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
remotePipeTransport
.
close
();
this
.
_mapRouterPipeTransports
.
delete
(
router
);
});
remotePipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
localPipeTransport
.
close
();
this
.
_mapRouterPipeTransports
.
delete
(
router
);
});
this
.
_mapRouterPipeTransports
.
set
(
router
,
[
localPipeTransport
,
remotePipeTransport
]);
}
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating PipeTransport pair:%o'
,
error
);
if
(
localPipeTransport
)
localPipeTransport
.
close
();
if
(
remotePipeTransport
)
remotePipeTransport
.
close
();
throw
error
;
}
}
}));
if
(
producer
)
{
let
pipeConsumer
;
let
pipeProducer
;
try
{
pipeConsumer
=
yield
localPipeTransport
.
consume
({
producerId
});
pipeProducer
=
yield
remotePipeTransport
.
produce
({
id
:
producer
.
id
,
kind
:
pipeConsumer
.
kind
,
rtpParameters
:
pipeConsumer
.
rtpParameters
,
paused
:
pipeConsumer
.
producerPaused
,
appData
:
producer
.
appData
});
});
// Pipe events from the pipe Consumer to the pipe Producer.
remotePipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
pipeConsumer
.
observer
.
on
(
'close'
,
()
=>
pipeProducer
.
close
());
localPipeTransport
.
close
();
pipeConsumer
.
observer
.
on
(
'pause'
,
()
=>
pipeProducer
.
pause
());
this
.
_mapRouterPipeTransports
.
delete
(
router
);
pipeConsumer
.
observer
.
on
(
'resume'
,
()
=>
pipeProducer
.
resume
());
// Pipe events from the pipe Producer to the pipe Consumer.
pipeProducer
.
observer
.
on
(
'close'
,
()
=>
pipeConsumer
.
close
());
return
{
pipeConsumer
,
pipeProducer
};
}
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating pipe Consumer/Producer pair:%o'
,
error
);
if
(
pipeConsumer
)
pipeConsumer
.
close
();
if
(
pipeProducer
)
pipeProducer
.
close
();
throw
error
;
}
}
else
if
(
dataProducer
)
{
let
pipeDataConsumer
;
let
pipeDataProducer
;
try
{
pipeDataConsumer
=
yield
localPipeTransport
.
consumeData
({
dataProducerId
});
});
pipeDataProducer
=
yield
remotePipeTransport
.
produceData
({
this
.
_mapRouterPipeTransports
.
set
(
router
,
[
localPipeTransport
,
remotePipeTransport
]);
id
:
dataProducer
.
id
,
sctpStreamParameters
:
pipeDataConsumer
.
sctpStreamParameters
,
label
:
pipeDataConsumer
.
label
,
protocol
:
pipeDataConsumer
.
protocol
,
appData
:
dataProducer
.
appData
});
// Pipe events from the pipe DataConsumer to the pipe DataProducer.
pipeDataConsumer
.
observer
.
on
(
'close'
,
()
=>
pipeDataProducer
.
close
());
// Pipe events from the pipe DataProducer to the pipe DataConsumer.
pipeDataProducer
.
observer
.
on
(
'close'
,
()
=>
pipeDataConsumer
.
close
());
return
{
pipeDataConsumer
,
pipeDataProducer
};
}
}
catch
(
error
)
{
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating
pipe DataConsumer/DataProducer
pair:%o'
,
error
);
logger
.
error
(
'pipeToRouter() | error creating
PipeTransport
pair:%o'
,
error
);
if
(
pipeDataConsumer
)
if
(
localPipeTransport
)
pipeDataConsumer
.
close
();
localPipeTransport
.
close
();
if
(
pipeDataProducer
)
if
(
remotePipeTransport
)
pipeDataProducer
.
close
();
remotePipeTransport
.
close
();
throw
error
;
throw
error
;
}
}
}
}
else
{
throw
new
Error
(
'internal error'
);
}
});
});
if
(
producer
)
{
let
pipeConsumer
;
let
pipeProducer
;
try
{
pipeConsumer
=
await
localPipeTransport
.
consume
({
producerId
});
pipeProducer
=
await
remotePipeTransport
.
produce
({
id
:
producer
.
id
,
kind
:
pipeConsumer
.
kind
,
rtpParameters
:
pipeConsumer
.
rtpParameters
,
paused
:
pipeConsumer
.
producerPaused
,
appData
:
producer
.
appData
});
// Pipe events from the pipe Consumer to the pipe Producer.
pipeConsumer
.
observer
.
on
(
'close'
,
()
=>
pipeProducer
.
close
());
pipeConsumer
.
observer
.
on
(
'pause'
,
()
=>
pipeProducer
.
pause
());
pipeConsumer
.
observer
.
on
(
'resume'
,
()
=>
pipeProducer
.
resume
());
// Pipe events from the pipe Producer to the pipe Consumer.
pipeProducer
.
observer
.
on
(
'close'
,
()
=>
pipeConsumer
.
close
());
return
{
pipeConsumer
,
pipeProducer
};
}
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating pipe Consumer/Producer pair:%o'
,
error
);
if
(
pipeConsumer
)
pipeConsumer
.
close
();
if
(
pipeProducer
)
pipeProducer
.
close
();
throw
error
;
}
}
else
if
(
dataProducer
)
{
let
pipeDataConsumer
;
let
pipeDataProducer
;
try
{
pipeDataConsumer
=
await
localPipeTransport
.
consumeData
({
dataProducerId
});
pipeDataProducer
=
await
remotePipeTransport
.
produceData
({
id
:
dataProducer
.
id
,
sctpStreamParameters
:
pipeDataConsumer
.
sctpStreamParameters
,
label
:
pipeDataConsumer
.
label
,
protocol
:
pipeDataConsumer
.
protocol
,
appData
:
dataProducer
.
appData
});
// Pipe events from the pipe DataConsumer to the pipe DataProducer.
pipeDataConsumer
.
observer
.
on
(
'close'
,
()
=>
pipeDataProducer
.
close
());
// Pipe events from the pipe DataProducer to the pipe DataConsumer.
pipeDataProducer
.
observer
.
on
(
'close'
,
()
=>
pipeDataConsumer
.
close
());
return
{
pipeDataConsumer
,
pipeDataProducer
};
}
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating pipe DataConsumer/DataProducer pair:%o'
,
error
);
if
(
pipeDataConsumer
)
pipeDataConsumer
.
close
();
if
(
pipeDataProducer
)
pipeDataProducer
.
close
();
throw
error
;
}
}
else
{
throw
new
Error
(
'internal error'
);
}
}
}
/**
/**
* Create an AudioLevelObserver.
* Create an AudioLevelObserver.
*/
*/
createAudioLevelObserver
({
maxEntries
=
1
,
threshold
=
-
80
,
interval
=
1000
,
appData
=
{}
}
=
{})
{
async
createAudioLevelObserver
({
maxEntries
=
1
,
threshold
=
-
80
,
interval
=
1000
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createAudioLevelObserver()'
);
logger
.
debug
(
'createAudioLevelObserver()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
const
internal
=
{
...
this
.
_internal
,
rtpObserverId
:
v4_1
.
default
()
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
rtpObserverId
:
v4_1
.
default
()
});
const
reqData
=
{
maxEntries
,
threshold
,
interval
};
const
reqData
=
{
maxEntries
,
threshold
,
interval
};
await
this
.
_channel
.
request
(
'router.createAudioLevelObserver'
,
internal
,
reqData
);
yield
this
.
_channel
.
request
(
'router.createAudioLevelObserver'
,
internal
,
reqData
);
const
audioLevelObserver
=
new
AudioLevelObserver_1
.
AudioLevelObserver
({
const
audioLevelObserver
=
new
AudioLevelObserver_1
.
AudioLevelObserver
({
internal
,
internal
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
,
appData
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
))
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
))
});
});
this
.
_rtpObservers
.
set
(
audioLevelObserver
.
id
,
audioLevelObserver
);
this
.
_rtpObservers
.
set
(
audioLevelObserver
.
id
,
audioLevelObserver
);
audioLevelObserver
.
on
(
'@close'
,
()
=>
{
audioLevelObserver
.
on
(
'@close'
,
()
=>
{
this
.
_rtpObservers
.
delete
(
audioLevelObserver
.
id
);
this
.
_rtpObservers
.
delete
(
audioLevelObserver
.
id
);
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrtpobserver'
,
audioLevelObserver
);
return
audioLevelObserver
;
});
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrtpobserver'
,
audioLevelObserver
);
return
audioLevelObserver
;
}
}
/**
/**
* Check whether the given RTP capabilities can consume the given Producer.
* Check whether the given RTP capabilities can consume the given Producer.
...
...
lib/RtpObserver.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
@@ -110,56 +101,48 @@ class RtpObserver extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -110,56 +101,48 @@ class RtpObserver extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Pause the RtpObserver.
* Pause the RtpObserver.
*/
*/
pause
()
{
async
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'rtpObserver.pause'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'rtpObserver.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
this
.
_paused
=
true
;
// Emit observer event.
// Emit observer event.
if
(
!
wasPaused
)
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
this
.
_observer
.
safeEmit
(
'pause'
);
});
}
}
/**
/**
* Resume the RtpObserver.
* Resume the RtpObserver.
*/
*/
resume
()
{
async
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'rtpObserver.resume'
,
this
.
_internal
);
yield
this
.
_channel
.
request
(
'rtpObserver.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
this
.
_paused
=
false
;
// Emit observer event.
// Emit observer event.
if
(
wasPaused
)
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
this
.
_observer
.
safeEmit
(
'resume'
);
});
}
}
/**
/**
* Add a Producer to the RtpObserver.
* Add a Producer to the RtpObserver.
*/
*/
addProducer
({
producerId
})
{
async
addProducer
({
producerId
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'addProducer()'
);
logger
.
debug
(
'addProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
{
...
this
.
_internal
,
producerId
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
});
await
this
.
_channel
.
request
(
'rtpObserver.addProducer'
,
internal
);
yield
this
.
_channel
.
request
(
'rtpObserver.addProducer'
,
internal
);
// Emit observer event.
// Emit observer event.
this
.
_observer
.
safeEmit
(
'addproducer'
,
producer
);
this
.
_observer
.
safeEmit
(
'addproducer'
,
producer
);
});
}
}
/**
/**
* Remove a Producer from the RtpObserver.
* Remove a Producer from the RtpObserver.
*/
*/
removeProducer
({
producerId
})
{
async
removeProducer
({
producerId
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'removeProducer()'
);
logger
.
debug
(
'removeProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
{
...
this
.
_internal
,
producerId
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
});
await
this
.
_channel
.
request
(
'rtpObserver.removeProducer'
,
internal
);
yield
this
.
_channel
.
request
(
'rtpObserver.removeProducer'
,
internal
);
// Emit observer event.
// Emit observer event.
this
.
_observer
.
safeEmit
(
'removeproducer'
,
producer
);
this
.
_observer
.
safeEmit
(
'removeproducer'
,
producer
);
});
}
}
}
}
exports
.
RtpObserver
=
RtpObserver
;
exports
.
RtpObserver
=
RtpObserver
;
lib/Transport.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
};
...
@@ -185,22 +176,18 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -185,22 +176,18 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump Transport.
* Dump Transport.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'transport.dump'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'transport.dump'
,
this
.
_internal
);
});
}
}
/**
/**
* Get Transport stats.
* Get Transport stats.
*
*
* @abstract
* @abstract
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
// Should not happen.
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
throw
new
Error
(
'method not implemented in the subclass'
);
});
}
}
/**
/**
* Provide the Transport remote parameters.
* Provide the Transport remote parameters.
...
@@ -208,222 +195,208 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -208,222 +195,208 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
* @abstract
* @abstract
*/
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
connect
(
params
)
{
async
connect
(
params
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
// Should not happen.
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
throw
new
Error
(
'method not implemented in the subclass'
);
});
}
}
/**
/**
* Set maximum incoming bitrate for receiving media.
* Set maximum incoming bitrate for receiving media.
*/
*/
setMaxIncomingBitrate
(
bitrate
)
{
async
setMaxIncomingBitrate
(
bitrate
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setMaxIncomingBitrate() [bitrate:%s]'
,
bitrate
);
logger
.
debug
(
'setMaxIncomingBitrate() [bitrate:%s]'
,
bitrate
);
const
reqData
=
{
bitrate
};
const
reqData
=
{
bitrate
};
await
this
.
_channel
.
request
(
'transport.setMaxIncomingBitrate'
,
this
.
_internal
,
reqData
);
yield
this
.
_channel
.
request
(
'transport.setMaxIncomingBitrate'
,
this
.
_internal
,
reqData
);
});
}
}
/**
/**
* Create a Producer.
* Create a Producer.
*/
*/
produce
({
id
=
undefined
,
kind
,
rtpParameters
,
paused
=
false
,
keyFrameRequestDelay
,
appData
=
{}
})
{
async
produce
({
id
=
undefined
,
kind
,
rtpParameters
,
paused
=
false
,
keyFrameRequestDelay
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'produce()'
);
logger
.
debug
(
'produce()'
);
if
(
id
&&
this
.
_producers
.
has
(
id
))
if
(
id
&&
this
.
_producers
.
has
(
id
))
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
// This may throw.
ortc
.
validateRtpParameters
(
rtpParameters
);
ortc
.
validateRtpParameters
(
rtpParameters
);
// If missing or empty encodings, add one.
// If missing or empty encodings, add one.
if
(
!
rtpParameters
.
encodings
||
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
rtpParameters
.
encodings
.
length
===
0
)
{
rtpParameters
.
encodings
.
length
===
0
)
{
rtpParameters
.
encodings
=
[{}];
rtpParameters
.
encodings
=
[{}];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
if
(
this
.
constructor
.
name
!==
'PipeTransport'
)
{
// If CNAME is given and we don't have yet a CNAME for Producers in this
// Transport, take it.
if
(
!
this
.
_cnameForProducers
&&
rtpParameters
.
rtcp
&&
rtpParameters
.
rtcp
.
cname
)
{
this
.
_cnameForProducers
=
rtpParameters
.
rtcp
.
cname
;
}
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// Otherwise if we don't have yet a CNAME for Producers and the RTP parameters
// each Producer.
// do not include CNAME, create a random one.
if
(
this
.
constructor
.
name
!==
'PipeTransport'
)
{
else
if
(
!
this
.
_cnameForProducers
)
{
// If CNAME is given and we don't have yet a CNAME for Producers in this
this
.
_cnameForProducers
=
v4_1
.
default
().
substr
(
0
,
8
);
// Transport, take it.
if
(
!
this
.
_cnameForProducers
&&
rtpParameters
.
rtcp
&&
rtpParameters
.
rtcp
.
cname
)
{
this
.
_cnameForProducers
=
rtpParameters
.
rtcp
.
cname
;
}
// Otherwise if we don't have yet a CNAME for Producers and the RTP parameters
// do not include CNAME, create a random one.
else
if
(
!
this
.
_cnameForProducers
)
{
this
.
_cnameForProducers
=
v4_1
.
default
().
substr
(
0
,
8
);
}
// Override Producer's CNAME.
rtpParameters
.
rtcp
=
rtpParameters
.
rtcp
||
{};
rtpParameters
.
rtcp
.
cname
=
this
.
_cnameForProducers
;
}
}
const
routerRtpCapabilities
=
this
.
_getRouterRtpCapabilities
();
// Override Producer's CNAME.
// This may throw.
rtpParameters
.
rtcp
=
rtpParameters
.
rtcp
||
{};
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
rtpParameters
,
routerRtpCapabilities
);
rtpParameters
.
rtcp
.
cname
=
this
.
_cnameForProducers
;
// This may throw.
}
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
kind
,
rtpParameters
,
routerRtpCapabilities
,
rtpMapping
);
const
routerRtpCapabilities
=
this
.
_getRouterRtpCapabilities
();
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
:
id
||
v4_1
.
default
()
});
// This may throw.
const
reqData
=
{
kind
,
rtpParameters
,
rtpMapping
,
keyFrameRequestDelay
,
paused
};
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
rtpParameters
,
routerRtpCapabilities
);
const
status
=
yield
this
.
_channel
.
request
(
'transport.produce'
,
internal
,
reqData
);
// This may throw.
const
data
=
{
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
kind
,
rtpParameters
,
routerRtpCapabilities
,
rtpMapping
);
kind
,
const
internal
=
{
...
this
.
_internal
,
producerId
:
id
||
v4_1
.
default
()
};
rtpParameters
,
const
reqData
=
{
kind
,
rtpParameters
,
rtpMapping
,
keyFrameRequestDelay
,
paused
};
type
:
status
.
type
,
const
status
=
await
this
.
_channel
.
request
(
'transport.produce'
,
internal
,
reqData
);
consumableRtpParameters
const
data
=
{
};
kind
,
const
producer
=
new
Producer_1
.
Producer
({
rtpParameters
,
internal
,
type
:
status
.
type
,
data
,
consumableRtpParameters
channel
:
this
.
_channel
,
};
appData
,
const
producer
=
new
Producer_1
.
Producer
({
paused
internal
,
});
data
,
this
.
_producers
.
set
(
producer
.
id
,
producer
);
channel
:
this
.
_channel
,
producer
.
on
(
'@close'
,
()
=>
{
appData
,
this
.
_producers
.
delete
(
producer
.
id
);
paused
this
.
emit
(
'@producerclose'
,
producer
);
});
});
this
.
_producers
.
set
(
producer
.
id
,
producer
);
this
.
emit
(
'@newproducer'
,
producer
);
producer
.
on
(
'@close'
,
()
=>
{
// Emit observer event.
this
.
_producers
.
delete
(
producer
.
id
);
this
.
_observer
.
safeEmit
(
'newproducer'
,
producer
);
this
.
emit
(
'@producerclose'
,
producer
);
return
producer
;
});
});
this
.
emit
(
'@newproducer'
,
producer
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newproducer'
,
producer
);
return
producer
;
}
}
/**
/**
* Create a Consumer.
* Create a Consumer.
*
*
* @virtual
* @virtual
*/
*/
consume
({
producerId
,
rtpCapabilities
,
paused
=
false
,
preferredLayers
,
appData
=
{}
})
{
async
consume
({
producerId
,
rtpCapabilities
,
paused
=
false
,
preferredLayers
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consume()'
);
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
// This may throw.
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
rtpCapabilities
);
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
rtpCapabilities
);
const
internal
=
{
...
this
.
_internal
,
consumerId
:
v4_1
.
default
(),
producerId
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
consumerId
:
v4_1
.
default
(),
producerId
});
const
reqData
=
{
const
reqData
=
{
kind
:
producer
.
kind
,
kind
:
producer
.
kind
,
rtpParameters
,
rtpParameters
,
type
:
producer
.
type
,
type
:
producer
.
type
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
,
paused
,
paused
,
preferredLayers
preferredLayers
};
};
const
status
=
await
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
status
=
yield
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
};
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
};
const
consumer
=
new
Consumer_1
.
Consumer
({
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
,
appData
,
paused
:
status
.
paused
,
paused
:
status
.
paused
,
producerPaused
:
status
.
producerPaused
,
producerPaused
:
status
.
producerPaused
,
score
:
status
.
score
,
score
:
status
.
score
,
preferredLayers
:
status
.
preferredLayers
preferredLayers
:
status
.
preferredLayers
});
this
.
_consumers
.
set
(
consumer
.
id
,
consumer
);
consumer
.
on
(
'@close'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
consumer
.
on
(
'@producerclose'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newconsumer'
,
consumer
);
return
consumer
;
});
});
this
.
_consumers
.
set
(
consumer
.
id
,
consumer
);
consumer
.
on
(
'@close'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
consumer
.
on
(
'@producerclose'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newconsumer'
,
consumer
);
return
consumer
;
}
}
/**
/**
* Create a DataProducer.
* Create a DataProducer.
*/
*/
produceData
({
id
=
undefined
,
sctpStreamParameters
,
label
=
''
,
protocol
=
''
,
appData
=
{}
})
{
async
produceData
({
id
=
undefined
,
sctpStreamParameters
,
label
=
''
,
protocol
=
''
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'produceData()'
);
logger
.
debug
(
'produceData()'
);
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
// This may throw.
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
const
internal
=
{
...
this
.
_internal
,
dataProducerId
:
id
||
v4_1
.
default
()
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataProducerId
:
id
||
v4_1
.
default
()
});
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
await
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
const
dataProducer
=
new
DataProducer_1
.
DataProducer
({
const
dataProducer
=
new
DataProducer_1
.
DataProducer
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
appData
});
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
);
dataProducer
.
on
(
'@close'
,
()
=>
{
this
.
_dataProducers
.
delete
(
dataProducer
.
id
);
this
.
emit
(
'@dataproducerclose'
,
dataProducer
);
});
this
.
emit
(
'@newdataproducer'
,
dataProducer
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newdataproducer'
,
dataProducer
);
return
dataProducer
;
});
});
this
.
_dataProducers
.
set
(
dataProducer
.
id
,
dataProducer
);
dataProducer
.
on
(
'@close'
,
()
=>
{
this
.
_dataProducers
.
delete
(
dataProducer
.
id
);
this
.
emit
(
'@dataproducerclose'
,
dataProducer
);
});
this
.
emit
(
'@newdataproducer'
,
dataProducer
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newdataproducer'
,
dataProducer
);
return
dataProducer
;
}
}
/**
/**
* Create a DataConsumer.
* Create a DataConsumer.
*/
*/
consumeData
({
dataProducerId
,
appData
=
{}
})
{
async
consumeData
({
dataProducerId
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consumeData()'
);
logger
.
debug
(
'consumeData()'
);
if
(
!
dataProducerId
||
typeof
dataProducerId
!==
'string'
)
if
(
!
dataProducerId
||
typeof
dataProducerId
!==
'string'
)
throw
new
TypeError
(
'missing dataProducerId'
);
throw
new
TypeError
(
'missing dataProducerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
const
dataProducer
=
this
.
_getDataProducerById
(
dataProducerId
);
const
dataProducer
=
this
.
_getDataProducerById
(
dataProducerId
);
if
(
!
dataProducer
)
if
(
!
dataProducer
)
throw
Error
(
`DataProducer with id "
${
dataProducerId
}
" not found`
);
throw
Error
(
`DataProducer with id "
${
dataProducerId
}
" not found`
);
const
sctpStreamParameters
=
utils
.
clone
(
dataProducer
.
sctpStreamParameters
);
const
sctpStreamParameters
=
utils
.
clone
(
dataProducer
.
sctpStreamParameters
);
const
{
label
,
protocol
}
=
dataProducer
;
const
{
label
,
protocol
}
=
dataProducer
;
// This may throw.
// This may throw.
const
sctpStreamId
=
this
.
_getNextSctpStreamId
();
const
sctpStreamId
=
this
.
_getNextSctpStreamId
();
this
.
_sctpStreamIds
[
sctpStreamId
]
=
1
;
this
.
_sctpStreamIds
[
sctpStreamId
]
=
1
;
sctpStreamParameters
.
streamId
=
sctpStreamId
;
sctpStreamParameters
.
streamId
=
sctpStreamId
;
const
internal
=
{
...
this
.
_internal
,
dataConsumerId
:
v4_1
.
default
(),
dataProducerId
};
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataConsumerId
:
v4_1
.
default
(),
dataProducerId
});
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
await
this
.
_channel
.
request
(
'transport.consumeData'
,
internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.consumeData'
,
internal
,
reqData
);
const
dataConsumer
=
new
DataConsumer_1
.
DataConsumer
({
const
dataConsumer
=
new
DataConsumer_1
.
DataConsumer
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
appData
});
this
.
_dataConsumers
.
set
(
dataConsumer
.
id
,
dataConsumer
);
dataConsumer
.
on
(
'@close'
,
()
=>
{
this
.
_dataConsumers
.
delete
(
dataConsumer
.
id
);
this
.
_sctpStreamIds
[
sctpStreamId
]
=
0
;
});
dataConsumer
.
on
(
'@dataproducerclose'
,
()
=>
{
this
.
_dataConsumers
.
delete
(
dataConsumer
.
id
);
this
.
_sctpStreamIds
[
sctpStreamId
]
=
0
;
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newdataconsumer'
,
dataConsumer
);
return
dataConsumer
;
});
});
this
.
_dataConsumers
.
set
(
dataConsumer
.
id
,
dataConsumer
);
dataConsumer
.
on
(
'@close'
,
()
=>
{
this
.
_dataConsumers
.
delete
(
dataConsumer
.
id
);
this
.
_sctpStreamIds
[
sctpStreamId
]
=
0
;
});
dataConsumer
.
on
(
'@dataproducerclose'
,
()
=>
{
this
.
_dataConsumers
.
delete
(
dataConsumer
.
id
);
this
.
_sctpStreamIds
[
sctpStreamId
]
=
0
;
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newdataconsumer'
,
dataConsumer
);
return
dataConsumer
;
}
}
/**
/**
* Enable 'trace' event.
* Enable 'trace' event.
*/
*/
enableTraceEvent
(
types
=
[])
{
async
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
logger
.
debug
(
'pause()'
);
const
reqData
=
{
types
};
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'transport.enableTraceEvent'
,
this
.
_internal
,
reqData
);
yield
this
.
_channel
.
request
(
'transport.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
}
}
_getNextSctpStreamId
()
{
_getNextSctpStreamId
()
{
if
(
!
this
.
_data
.
sctpParameters
||
if
(
!
this
.
_data
.
sctpParameters
||
...
...
lib/WebRtcTransport.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Logger_1
=
require
(
"./Logger"
);
const
Logger_1
=
require
(
"./Logger"
);
const
Transport_1
=
require
(
"./Transport"
);
const
Transport_1
=
require
(
"./Transport"
);
...
@@ -186,37 +177,31 @@ class WebRtcTransport extends Transport_1.Transport {
...
@@ -186,37 +177,31 @@ class WebRtcTransport extends Transport_1.Transport {
*
*
* @override
* @override
*/
*/
getStats
()
{
async
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
}
}
/**
/**
* Provide the WebRtcTransport remote parameters.
* Provide the WebRtcTransport remote parameters.
*
*
* @override
* @override
*/
*/
connect
({
dtlsParameters
})
{
async
connect
({
dtlsParameters
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
logger
.
debug
(
'connect()'
);
const
reqData
=
{
dtlsParameters
};
const
reqData
=
{
dtlsParameters
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
// Update data.
this
.
_data
.
dtlsParameters
.
role
=
data
.
dtlsLocalRole
;
this
.
_data
.
dtlsParameters
.
role
=
data
.
dtlsLocalRole
;
});
}
}
/**
/**
* Restart ICE.
* Restart ICE.
*/
*/
restartIce
()
{
async
restartIce
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'restartIce()'
);
logger
.
debug
(
'restartIce()'
);
const
data
=
await
this
.
_channel
.
request
(
'transport.restartIce'
,
this
.
_internal
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.restartIce'
,
this
.
_internal
);
const
{
iceParameters
}
=
data
;
const
{
iceParameters
}
=
data
;
this
.
_data
.
iceParameters
=
iceParameters
;
this
.
_data
.
iceParameters
=
iceParameters
;
return
iceParameters
;
return
iceParameters
;
});
}
}
_handleWorkerNotifications
()
{
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/Worker.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
var
result
=
{};
...
@@ -222,56 +213,48 @@ class Worker extends EnhancedEventEmitter_1.EnhancedEventEmitter {
...
@@ -222,56 +213,48 @@ class Worker extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
/**
* Dump Worker.
* Dump Worker.
*/
*/
dump
()
{
async
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'worker.dump'
);
return
this
.
_channel
.
request
(
'worker.dump'
);
});
}
}
/**
/**
* Get mediasoup-worker process resource usage.
* Get mediasoup-worker process resource usage.
*/
*/
getResourceUsage
()
{
async
getResourceUsage
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getResourceUsage()'
);
logger
.
debug
(
'getResourceUsage()'
);
return
this
.
_channel
.
request
(
'worker.getResourceUsage'
);
return
this
.
_channel
.
request
(
'worker.getResourceUsage'
);
});
}
}
/**
/**
* Update settings.
* Update settings.
*/
*/
updateSettings
({
logLevel
,
logTags
}
=
{})
{
async
updateSettings
({
logLevel
,
logTags
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'updateSettings()'
);
logger
.
debug
(
'updateSettings()'
);
const
reqData
=
{
logLevel
,
logTags
};
const
reqData
=
{
logLevel
,
logTags
};
await
this
.
_channel
.
request
(
'worker.updateSettings'
,
undefined
,
reqData
);
yield
this
.
_channel
.
request
(
'worker.updateSettings'
,
undefined
,
reqData
);
});
}
}
/**
/**
* Create a Router.
* Create a Router.
*/
*/
createRouter
({
mediaCodecs
,
appData
=
{}
}
=
{})
{
async
createRouter
({
mediaCodecs
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createRouter()'
);
logger
.
debug
(
'createRouter()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
// This may throw.
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
mediaCodecs
);
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
mediaCodecs
);
const
internal
=
{
routerId
:
v4_1
.
default
()
};
const
internal
=
{
routerId
:
v4_1
.
default
()
};
await
this
.
_channel
.
request
(
'worker.createRouter'
,
internal
);
yield
this
.
_channel
.
request
(
'worker.createRouter'
,
internal
);
const
data
=
{
rtpCapabilities
};
const
data
=
{
rtpCapabilities
};
const
router
=
new
Router_1
.
Router
({
const
router
=
new
Router_1
.
Router
({
internal
,
internal
,
data
,
data
,
channel
:
this
.
_channel
,
channel
:
this
.
_channel
,
appData
appData
});
this
.
_routers
.
add
(
router
);
router
.
on
(
'@close'
,
()
=>
this
.
_routers
.
delete
(
router
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrouter'
,
router
);
return
router
;
});
});
this
.
_routers
.
add
(
router
);
router
.
on
(
'@close'
,
()
=>
this
.
_routers
.
delete
(
router
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrouter'
,
router
);
return
router
;
}
}
}
}
exports
.
Worker
=
Worker
;
exports
.
Worker
=
Worker
;
lib/index.js
浏览文件 @
d09586fe
"use strict"
;
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
var
__importStar
=
(
this
&&
this
.
__importStar
)
||
function
(
mod
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
var
result
=
{};
...
@@ -38,28 +29,26 @@ exports.observer = observer;
...
@@ -38,28 +29,26 @@ exports.observer = observer;
/**
/**
* Create a Worker.
* Create a Worker.
*/
*/
function
createWorker
({
logLevel
=
'error'
,
logTags
,
rtcMinPort
=
10000
,
rtcMaxPort
=
59999
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
=
{}
}
=
{})
{
async
function
createWorker
({
logLevel
=
'error'
,
logTags
,
rtcMinPort
=
10000
,
rtcMaxPort
=
59999
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createWorker()'
);
logger
.
debug
(
'createWorker()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
throw
new
TypeError
(
'if given, appData must be an object'
);
const
worker
=
new
Worker_1
.
Worker
({
const
worker
=
new
Worker_1
.
Worker
({
logLevel
,
logLevel
,
logTags
,
logTags
,
rtcMinPort
,
rtcMinPort
,
rtcMaxPort
,
rtcMaxPort
,
dtlsCertificateFile
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
dtlsPrivateKeyFile
,
appData
appData
});
});
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
worker
.
on
(
'@success'
,
()
=>
{
worker
.
on
(
'@success'
,
()
=>
{
// Emit observer event.
// Emit observer event.
observer
.
safeEmit
(
'newworker'
,
worker
);
observer
.
safeEmit
(
'newworker'
,
worker
);
resolve
(
worker
);
resolve
(
worker
);
});
worker
.
on
(
'@failure'
,
reject
);
});
});
worker
.
on
(
'@failure'
,
reject
);
});
});
}
}
exports
.
createWorker
=
createWorker
;
exports
.
createWorker
=
createWorker
;
...
...
lib/ortc.js
浏览文件 @
d09586fe
...
@@ -449,7 +449,7 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
...
@@ -449,7 +449,7 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
// Merge the media codec parameters.
// Merge the media codec parameters.
codec
.
parameters
=
Object
.
assign
(
Object
.
assign
({},
codec
.
parameters
),
mediaCodec
.
parameters
)
;
codec
.
parameters
=
{
...
codec
.
parameters
,
...
mediaCodec
.
parameters
}
;
// Append to the codec list.
// Append to the codec list.
caps
.
codecs
.
push
(
codec
);
caps
.
codecs
.
push
(
codec
);
// Add a RTX video codec if video.
// Add a RTX video codec if video.
...
...
tsconfig.json
浏览文件 @
d09586fe
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
"compilerOptions"
:
"compilerOptions"
:
{
{
"lib"
:
[
"es6"
,
"dom"
],
"lib"
:
[
"es6"
,
"dom"
],
"target"
:
"es
6
"
,
"target"
:
"es
2020
"
,
"module"
:
"commonjs"
,
"module"
:
"commonjs"
,
"moduleResolution"
:
"node"
,
"moduleResolution"
:
"node"
,
"esModuleInterop"
:
true
,
"esModuleInterop"
:
true
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论