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.4.12 (WIP)
*
TypeScript: generate
`es2020`
instead of
`es6`
.
*
Update
`usrsctp`
library.
-
Fixes #362 (thanks @chvarlam for reporting it).
...
...
lib/Channel.js
浏览文件 @
d09586fe
"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
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
...
...
@@ -150,49 +141,47 @@ class Channel extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* @private
*/
request
(
method
,
internal
,
data
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
this
.
_nextId
<
4294967295
?
++
this
.
_nextId
:
(
this
.
_nextId
=
1
);
const
id
=
this
.
_nextId
;
logger
.
debug
(
'request() [method:%s, id:%s]'
,
method
,
id
);
if
(
this
.
_closed
)
throw
new
errors_1
.
InvalidStateError
(
'Channel closed'
);
const
request
=
{
id
,
method
,
internal
,
data
};
const
ns
=
netstring
.
nsWrite
(
JSON
.
stringify
(
request
));
if
(
Buffer
.
byteLength
(
ns
)
>
NS_MESSAGE_MAX_LEN
)
throw
new
Error
(
'Channel request too big'
);
// This may throw if closed or remote side ended.
this
.
_producerSocket
.
write
(
ns
);
return
new
Promise
((
pResolve
,
pReject
)
=>
{
const
timeout
=
1000
*
(
15
+
(
0.1
*
this
.
_sents
.
size
));
const
sent
=
{
id
:
id
,
method
:
method
,
resolve
:
(
data2
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
clearTimeout
(
sent
.
timer
);
pResolve
(
data2
);
},
reject
:
(
error
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
clearTimeout
(
sent
.
timer
);
pReject
(
error
);
},
timer
:
setTimeout
(()
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
pReject
(
new
Error
(
'Channel request timeout'
));
},
timeout
),
close
:
()
=>
{
clearTimeout
(
sent
.
timer
);
pReject
(
new
errors_1
.
InvalidStateError
(
'Channel closed'
));
}
};
// Add sent stuff to the map.
this
.
_sents
.
set
(
id
,
sent
);
});
async
request
(
method
,
internal
,
data
)
{
this
.
_nextId
<
4294967295
?
++
this
.
_nextId
:
(
this
.
_nextId
=
1
);
const
id
=
this
.
_nextId
;
logger
.
debug
(
'request() [method:%s, id:%s]'
,
method
,
id
);
if
(
this
.
_closed
)
throw
new
errors_1
.
InvalidStateError
(
'Channel closed'
);
const
request
=
{
id
,
method
,
internal
,
data
};
const
ns
=
netstring
.
nsWrite
(
JSON
.
stringify
(
request
));
if
(
Buffer
.
byteLength
(
ns
)
>
NS_MESSAGE_MAX_LEN
)
throw
new
Error
(
'Channel request too big'
);
// This may throw if closed or remote side ended.
this
.
_producerSocket
.
write
(
ns
);
return
new
Promise
((
pResolve
,
pReject
)
=>
{
const
timeout
=
1000
*
(
15
+
(
0.1
*
this
.
_sents
.
size
));
const
sent
=
{
id
:
id
,
method
:
method
,
resolve
:
(
data2
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
clearTimeout
(
sent
.
timer
);
pResolve
(
data2
);
},
reject
:
(
error
)
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
clearTimeout
(
sent
.
timer
);
pReject
(
error
);
},
timer
:
setTimeout
(()
=>
{
if
(
!
this
.
_sents
.
delete
(
id
))
return
;
pReject
(
new
Error
(
'Channel request timeout'
));
},
timeout
),
close
:
()
=>
{
clearTimeout
(
sent
.
timer
);
pReject
(
new
errors_1
.
InvalidStateError
(
'Channel closed'
));
}
};
// Add sent stuff to the map.
this
.
_sents
.
set
(
id
,
sent
);
});
}
_processMessage
(
msg
)
{
...
...
lib/Consumer.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
...
@@ -184,100 +175,82 @@ class Consumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump Consumer.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'consumer.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'consumer.dump'
,
this
.
_internal
);
}
/**
* Get Consumer stats.
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'consumer.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'consumer.getStats'
,
this
.
_internal
);
}
/**
* Pause the Consumer.
*/
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
yield
this
.
_channel
.
request
(
'consumer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
});
async
pause
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
await
this
.
_channel
.
request
(
'consumer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
}
/**
* Resume the Consumer.
*/
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
yield
this
.
_channel
.
request
(
'consumer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
&&
!
this
.
_producerPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
});
async
resume
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
||
this
.
_producerPaused
;
await
this
.
_channel
.
request
(
'consumer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
&&
!
this
.
_producerPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
}
/**
* Set preferred video layers.
*/
setPreferredLayers
({
spatialLayer
,
temporalLayer
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setPreferredLayers()'
);
const
reqData
=
{
spatialLayer
,
temporalLayer
};
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPreferredLayers'
,
this
.
_internal
,
reqData
);
this
.
_preferredLayers
=
data
||
null
;
});
async
setPreferredLayers
({
spatialLayer
,
temporalLayer
})
{
logger
.
debug
(
'setPreferredLayers()'
);
const
reqData
=
{
spatialLayer
,
temporalLayer
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPreferredLayers'
,
this
.
_internal
,
reqData
);
this
.
_preferredLayers
=
data
||
null
;
}
/**
* Set priority.
*/
setPriority
(
priority
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setPriority()'
);
const
reqData
=
{
priority
};
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
});
async
setPriority
(
priority
)
{
logger
.
debug
(
'setPriority()'
);
const
reqData
=
{
priority
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
}
/**
* Unset priority.
*/
unsetPriority
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'unsetPriority()'
);
const
reqData
=
{
priority
:
1
};
const
data
=
yield
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
});
async
unsetPriority
()
{
logger
.
debug
(
'unsetPriority()'
);
const
reqData
=
{
priority
:
1
};
const
data
=
await
this
.
_channel
.
request
(
'consumer.setPriority'
,
this
.
_internal
,
reqData
);
this
.
_priority
=
data
.
priority
;
}
/**
* Request a key frame to the Producer.
*/
requestKeyFrame
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'requestKeyFrame()'
);
yield
this
.
_channel
.
request
(
'consumer.requestKeyFrame'
,
this
.
_internal
);
});
async
requestKeyFrame
()
{
logger
.
debug
(
'requestKeyFrame()'
);
await
this
.
_channel
.
request
(
'consumer.requestKeyFrame'
,
this
.
_internal
);
}
/**
* Enable 'trace' event.
*/
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
yield
this
.
_channel
.
request
(
'consumer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
async
enableTraceEvent
(
types
=
[])
{
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'consumer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
consumerId
,
(
event
,
data
)
=>
{
...
...
lib/DataConsumer.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
...
@@ -124,20 +115,16 @@ class DataConsumer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump DataConsumer.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataConsumer.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataConsumer.dump'
,
this
.
_internal
);
}
/**
* Get DataConsumer stats.
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataConsumer.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataConsumer.getStats'
,
this
.
_internal
);
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
dataConsumerId
,
(
event
)
=>
{
...
...
lib/DataProducer.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
...
@@ -114,20 +105,16 @@ class DataProducer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump DataProducer.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataProducer.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'dataProducer.dump'
,
this
.
_internal
);
}
/**
* Get DataProducer stats.
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataProducer.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'dataProducer.getStats'
,
this
.
_internal
);
}
_handleWorkerNotifications
()
{
// No need to subscribe to any event.
...
...
lib/EnhancedEventEmitter.js
浏览文件 @
d09586fe
"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
});
const
events_1
=
require
(
"events"
);
const
Logger_1
=
require
(
"./Logger"
);
...
...
@@ -27,10 +18,8 @@ class EnhancedEventEmitter extends events_1.EventEmitter {
return
Boolean
(
numListeners
);
}
}
safeEmitAsPromise
(
event
,
...
args
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
return
new
Promise
((
resolve
,
reject
)
=>
(
this
.
safeEmit
(
event
,
...
args
,
resolve
,
reject
)));
});
async
safeEmitAsPromise
(
event
,
...
args
)
{
return
new
Promise
((
resolve
,
reject
)
=>
(
this
.
safeEmit
(
event
,
...
args
,
resolve
,
reject
)));
}
}
exports
.
EnhancedEventEmitter
=
EnhancedEventEmitter
;
lib/PipeTransport.js
浏览文件 @
d09586fe
"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
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
...
...
@@ -119,67 +110,61 @@ class PipeTransport extends Transport_1.Transport {
*
* @override
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
}
/**
* Provide the PipeTransport remote parameters.
*
* @override
*/
connect
({
ip
,
port
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
});
async
connect
({
ip
,
port
})
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
}
/**
* Create a pipe Consumer.
*
* @override
*/
consume
({
producerId
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
producer
.
consumableRtpParameters
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
consumerId
:
v4_1
.
default
(),
producerId
});
const
reqData
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
};
const
status
=
yield
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
};
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
:
status
.
paused
,
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
;
async
consume
({
producerId
,
appData
=
{}
})
{
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
const
rtpParameters
=
ortc
.
getPipeConsumerRtpParameters
(
producer
.
consumableRtpParameters
);
const
internal
=
{
...
this
.
_internal
,
consumerId
:
v4_1
.
default
(),
producerId
};
const
reqData
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
};
const
status
=
await
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
'pipe'
};
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
:
status
.
paused
,
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
;
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/PlainRtpTransport.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
Transport_1
=
require
(
"./Transport"
);
...
...
@@ -122,41 +113,32 @@ class PlainRtpTransport extends Transport_1.Transport {
*
* @override
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
}
/**
* Provide the PlainRtpTransport remote parameters.
*
* @override
*/
connect
({
ip
,
port
,
rtcpPort
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
});
async
connect
({
ip
,
port
,
rtcpPort
})
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
}
/**
* Override Transport.consume() method to reject it if multiSource is set.
*
* @override
*/
consume
(
params
)
{
const
_super
=
Object
.
create
(
null
,
{
consume
:
{
get
:
()
=>
super
.
consume
}
});
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
);
});
async
consume
(
params
)
{
if
(
this
.
_data
.
multiSource
)
throw
new
Error
(
'cannot call consume() with multiSource set'
);
return
super
.
consume
(
params
);
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/Producer.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
...
@@ -149,58 +140,48 @@ class Producer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump Producer.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'producer.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'producer.dump'
,
this
.
_internal
);
}
/**
* Get Producer stats.
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'producer.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'producer.getStats'
,
this
.
_internal
);
}
/**
* Pause the Producer.
*/
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
yield
this
.
_channel
.
request
(
'producer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
});
async
pause
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'producer.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
}
/**
* Resume the Producer.
*/
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
yield
this
.
_channel
.
request
(
'producer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
});
async
resume
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'producer.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
}
/**
* Enable 'trace' event.
*/
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
yield
this
.
_channel
.
request
(
'producer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
async
enableTraceEvent
(
types
=
[])
{
logger
.
debug
(
'enableTraceEvent()'
);
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'producer.enableTraceEvent'
,
this
.
_internal
,
reqData
);
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
producerId
,
(
event
,
data
)
=>
{
...
...
lib/Router.js
浏览文件 @
d09586fe
"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
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
...
...
@@ -165,342 +156,330 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump Router.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'router.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'router.dump'
,
this
.
_internal
);
}
/**
* 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
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createWebRtcTransport()'
);
if
(
!
Array
.
isArray
(
listenIps
))
throw
new
TypeError
(
'missing listenIps'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
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'
);
async
createWebRtcTransport
({
listenIps
,
enableUdp
=
true
,
enableTcp
=
false
,
preferUdp
=
false
,
preferTcp
=
false
,
initialAvailableOutgoingBitrate
=
600000
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
logger
.
debug
(
'createWebRtcTransport()'
);
if
(
!
Array
.
isArray
(
listenIps
))
throw
new
TypeError
(
'missing listenIps'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
listenIps
=
listenIps
.
map
((
listenIp
)
=>
{
if
(
typeof
listenIp
===
'string'
&&
listenIp
)
{
listenIp
=
{
ip
:
listenIp
};
return
{
ip
:
listenIp
};
}
else
if
(
typeof
listenIp
===
'object'
)
{
listenIp
=
{
ip
:
listenIp
.
ip
,
announcedIp
:
listenIp
.
announcedIp
||
undefined
};
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
=
{
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.
*/
createPipeTransport
({
listenIp
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
1073741823
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createPipeTransport()'
);
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
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
transportId
:
v4_1
.
default
()
});
const
reqData
=
{
listenIp
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
};
const
data
=
yield
this
.
_channel
.
request
(
'router.createPipeTransport'
,
internal
,
reqData
);
const
transport
=
new
PipeTransport_1
.
PipeTransport
({
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
;
async
createPipeTransport
({
listenIp
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
1073741823
,
appData
=
{}
})
{
logger
.
debug
(
'createPipeTransport()'
);
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
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
};
const
data
=
await
this
.
_channel
.
request
(
'router.createPipeTransport'
,
internal
,
reqData
);
const
transport
=
new
PipeTransport_1
.
PipeTransport
({
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
;
}
/**
* 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
}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
if
(
!
producerId
&&
!
dataProducerId
)
throw
new
TypeError
(
'missing producerId or dataProducerId'
);
else
if
(
producerId
&&
dataProducerId
)
throw
new
TypeError
(
'just producerId or dataProducerId can be given'
);
else
if
(
!
router
)
throw
new
TypeError
(
'Router not found'
);
else
if
(
router
===
this
)
throw
new
TypeError
(
'cannot use this Router as destination'
);
let
producer
;
let
dataProducer
;
if
(
producerId
)
{
producer
=
this
.
_producers
.
get
(
producerId
);
if
(
!
producer
)
throw
new
TypeError
(
'Producer not found'
);
}
else
if
(
dataProducerId
)
{
dataProducer
=
this
.
_dataProducers
.
get
(
dataProducerId
);
if
(
!
dataProducer
)
throw
new
TypeError
(
'DataProducer not found'
);
async
pipeToRouter
({
producerId
,
dataProducerId
,
router
,
listenIp
=
'127.0.0.1'
,
enableSctp
=
true
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
}
})
{
if
(
!
producerId
&&
!
dataProducerId
)
throw
new
TypeError
(
'missing producerId or dataProducerId'
);
else
if
(
producerId
&&
dataProducerId
)
throw
new
TypeError
(
'just producerId or dataProducerId can be given'
);
else
if
(
!
router
)
throw
new
TypeError
(
'Router not found'
);
else
if
(
router
===
this
)
throw
new
TypeError
(
'cannot use this Router as destination'
);
let
producer
;
let
dataProducer
;
if
(
producerId
)
{
producer
=
this
.
_producers
.
get
(
producerId
);
if
(
!
producer
)
throw
new
TypeError
(
'Producer not found'
);
}
else
if
(
dataProducerId
)
{
dataProducer
=
this
.
_dataProducers
.
get
(
dataProducerId
);
if
(
!
dataProducer
)
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
// 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
;
yield
this
.
_pipeToRouterQueue
.
push
(()
=>
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
let
pipeTransportPair
=
this
.
_mapRouterPipeTransports
.
get
(
router
);
if
(
pipeTransportPair
)
{
else
{
try
{
pipeTransportPair
=
await
Promise
.
all
([
this
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
}),
router
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
})
]);
localPipeTransport
=
pipeTransportPair
[
0
];
remotePipeTransport
=
pipeTransportPair
[
1
];
}
else
{
try
{
pipeTransportPair
=
yield
Promise
.
all
([
this
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
}),
router
.
createPipeTransport
({
listenIp
,
enableSctp
,
numSctpStreams
})
]);
localPipeTransport
=
pipeTransportPair
[
0
];
remotePipeTransport
=
pipeTransportPair
[
1
];
yield
Promise
.
all
([
localPipeTransport
.
connect
({
ip
:
remotePipeTransport
.
tuple
.
localIp
,
port
:
remotePipeTransport
.
tuple
.
localPort
}),
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
await
Promise
.
all
([
localPipeTransport
.
connect
({
ip
:
remotePipeTransport
.
tuple
.
localIp
,
port
:
remotePipeTransport
.
tuple
.
localPort
}),
remotePipeTransport
.
connect
({
ip
:
localPipeTransport
.
tuple
.
localIp
,
port
:
localPipeTransport
.
tuple
.
localPort
})
]);
localPipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
remotePipeTransport
.
close
();
this
.
_mapRouterPipeTransports
.
delete
(
router
);
});
// 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
=
yield
localPipeTransport
.
consumeData
({
dataProducerId
remotePipeTransport
.
observer
.
on
(
'close'
,
()
=>
{
localPipeTransport
.
close
();
this
.
_mapRouterPipeTransports
.
delete
(
router
);
});
pipeDataProducer
=
yield
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
};
this
.
_mapRouterPipeTransports
.
set
(
router
,
[
localPipeTransport
,
remotePipeTransport
]);
}
catch
(
error
)
{
logger
.
error
(
'pipeToRouter() | error creating
pipe DataConsumer/DataProducer
pair:%o'
,
error
);
if
(
pipeDataConsumer
)
pipeDataConsumer
.
close
();
if
(
pipeDataProducer
)
pipeDataProducer
.
close
();
logger
.
error
(
'pipeToRouter() | error creating
PipeTransport
pair:%o'
,
error
);
if
(
localPipeTransport
)
localPipeTransport
.
close
();
if
(
remotePipeTransport
)
remotePipeTransport
.
close
();
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.
*/
createAudioLevelObserver
({
maxEntries
=
1
,
threshold
=
-
80
,
interval
=
1000
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createAudioLevelObserver()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
rtpObserverId
:
v4_1
.
default
()
});
const
reqData
=
{
maxEntries
,
threshold
,
interval
};
yield
this
.
_channel
.
request
(
'router.createAudioLevelObserver'
,
internal
,
reqData
);
const
audioLevelObserver
=
new
AudioLevelObserver_1
.
AudioLevelObserver
({
internal
,
channel
:
this
.
_channel
,
appData
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
))
});
this
.
_rtpObservers
.
set
(
audioLevelObserver
.
id
,
audioLevelObserver
);
audioLevelObserver
.
on
(
'@close'
,
()
=>
{
this
.
_rtpObservers
.
delete
(
audioLevelObserver
.
id
);
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrtpobserver'
,
audioLevelObserver
);
return
audioLevelObserver
;
async
createAudioLevelObserver
({
maxEntries
=
1
,
threshold
=
-
80
,
interval
=
1000
,
appData
=
{}
}
=
{})
{
logger
.
debug
(
'createAudioLevelObserver()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
internal
=
{
...
this
.
_internal
,
rtpObserverId
:
v4_1
.
default
()
};
const
reqData
=
{
maxEntries
,
threshold
,
interval
};
await
this
.
_channel
.
request
(
'router.createAudioLevelObserver'
,
internal
,
reqData
);
const
audioLevelObserver
=
new
AudioLevelObserver_1
.
AudioLevelObserver
({
internal
,
channel
:
this
.
_channel
,
appData
,
getProducerById
:
(
producerId
)
=>
(
this
.
_producers
.
get
(
producerId
))
});
this
.
_rtpObservers
.
set
(
audioLevelObserver
.
id
,
audioLevelObserver
);
audioLevelObserver
.
on
(
'@close'
,
()
=>
{
this
.
_rtpObservers
.
delete
(
audioLevelObserver
.
id
);
});
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrtpobserver'
,
audioLevelObserver
);
return
audioLevelObserver
;
}
/**
* Check whether the given RTP capabilities can consume the given Producer.
...
...
lib/RtpObserver.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
EnhancedEventEmitter_1
=
require
(
"./EnhancedEventEmitter"
);
...
...
@@ -110,56 +101,48 @@ class RtpObserver extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Pause the RtpObserver.
*/
pause
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
yield
this
.
_channel
.
request
(
'rtpObserver.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
});
async
pause
()
{
logger
.
debug
(
'pause()'
);
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'rtpObserver.pause'
,
this
.
_internal
);
this
.
_paused
=
true
;
// Emit observer event.
if
(
!
wasPaused
)
this
.
_observer
.
safeEmit
(
'pause'
);
}
/**
* Resume the RtpObserver.
*/
resume
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
yield
this
.
_channel
.
request
(
'rtpObserver.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
});
async
resume
()
{
logger
.
debug
(
'resume()'
);
const
wasPaused
=
this
.
_paused
;
await
this
.
_channel
.
request
(
'rtpObserver.resume'
,
this
.
_internal
);
this
.
_paused
=
false
;
// Emit observer event.
if
(
wasPaused
)
this
.
_observer
.
safeEmit
(
'resume'
);
}
/**
* Add a Producer to the RtpObserver.
*/
addProducer
({
producerId
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'addProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
});
yield
this
.
_channel
.
request
(
'rtpObserver.addProducer'
,
internal
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'addproducer'
,
producer
);
});
async
addProducer
({
producerId
})
{
logger
.
debug
(
'addProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
{
...
this
.
_internal
,
producerId
};
await
this
.
_channel
.
request
(
'rtpObserver.addProducer'
,
internal
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'addproducer'
,
producer
);
}
/**
* Remove a Producer from the RtpObserver.
*/
removeProducer
({
producerId
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'removeProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
});
yield
this
.
_channel
.
request
(
'rtpObserver.removeProducer'
,
internal
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'removeproducer'
,
producer
);
});
async
removeProducer
({
producerId
})
{
logger
.
debug
(
'removeProducer()'
);
const
producer
=
this
.
_getProducerById
(
producerId
);
const
internal
=
{
...
this
.
_internal
,
producerId
};
await
this
.
_channel
.
request
(
'rtpObserver.removeProducer'
,
internal
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'removeproducer'
,
producer
);
}
}
exports
.
RtpObserver
=
RtpObserver
;
lib/Transport.js
浏览文件 @
d09586fe
"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
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"default"
:
mod
};
};
...
...
@@ -185,22 +176,18 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump Transport.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'transport.dump'
,
this
.
_internal
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'transport.dump'
,
this
.
_internal
);
}
/**
* Get Transport stats.
*
* @abstract
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
});
async
getStats
()
{
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
}
/**
* Provide the Transport remote parameters.
...
...
@@ -208,222 +195,208 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
* @abstract
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
connect
(
params
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
});
async
connect
(
params
)
{
// Should not happen.
throw
new
Error
(
'method not implemented in the subclass'
);
}
/**
* Set maximum incoming bitrate for receiving media.
*/
setMaxIncomingBitrate
(
bitrate
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'setMaxIncomingBitrate() [bitrate:%s]'
,
bitrate
);
const
reqData
=
{
bitrate
};
yield
this
.
_channel
.
request
(
'transport.setMaxIncomingBitrate'
,
this
.
_internal
,
reqData
);
});
async
setMaxIncomingBitrate
(
bitrate
)
{
logger
.
debug
(
'setMaxIncomingBitrate() [bitrate:%s]'
,
bitrate
);
const
reqData
=
{
bitrate
};
await
this
.
_channel
.
request
(
'transport.setMaxIncomingBitrate'
,
this
.
_internal
,
reqData
);
}
/**
* Create a Producer.
*/
produce
({
id
=
undefined
,
kind
,
rtpParameters
,
paused
=
false
,
keyFrameRequestDelay
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'produce()'
);
if
(
id
&&
this
.
_producers
.
has
(
id
))
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpParameters
(
rtpParameters
);
// If missing or empty encodings, add one.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
rtpParameters
.
encodings
.
length
===
0
)
{
rtpParameters
.
encodings
=
[{}];
async
produce
({
id
=
undefined
,
kind
,
rtpParameters
,
paused
=
false
,
keyFrameRequestDelay
,
appData
=
{}
})
{
logger
.
debug
(
'produce()'
);
if
(
id
&&
this
.
_producers
.
has
(
id
))
throw
new
TypeError
(
`a Producer with same id "
${
id
}
" already exists`
);
else
if
(
!
[
'audio'
,
'video'
].
includes
(
kind
))
throw
new
TypeError
(
`invalid kind "
${
kind
}
"`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpParameters
(
rtpParameters
);
// If missing or empty encodings, add one.
if
(
!
rtpParameters
.
encodings
||
!
Array
.
isArray
(
rtpParameters
.
encodings
)
||
rtpParameters
.
encodings
.
length
===
0
)
{
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
// 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
;
}
// 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
;
// 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
);
}
const
routerRtpCapabilities
=
this
.
_getRouterRtpCapabilities
();
// This may throw.
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
rtpParameters
,
routerRtpCapabilities
);
// This may throw.
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
kind
,
rtpParameters
,
routerRtpCapabilities
,
rtpMapping
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
producerId
:
id
||
v4_1
.
default
()
});
const
reqData
=
{
kind
,
rtpParameters
,
rtpMapping
,
keyFrameRequestDelay
,
paused
};
const
status
=
yield
this
.
_channel
.
request
(
'transport.produce'
,
internal
,
reqData
);
const
data
=
{
kind
,
rtpParameters
,
type
:
status
.
type
,
consumableRtpParameters
};
const
producer
=
new
Producer_1
.
Producer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
});
this
.
_producers
.
set
(
producer
.
id
,
producer
);
producer
.
on
(
'@close'
,
()
=>
{
this
.
_producers
.
delete
(
producer
.
id
);
this
.
emit
(
'@producerclose'
,
producer
);
});
this
.
emit
(
'@newproducer'
,
producer
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newproducer'
,
producer
);
return
producer
;
// Override Producer's CNAME.
rtpParameters
.
rtcp
=
rtpParameters
.
rtcp
||
{};
rtpParameters
.
rtcp
.
cname
=
this
.
_cnameForProducers
;
}
const
routerRtpCapabilities
=
this
.
_getRouterRtpCapabilities
();
// This may throw.
const
rtpMapping
=
ortc
.
getProducerRtpParametersMapping
(
rtpParameters
,
routerRtpCapabilities
);
// This may throw.
const
consumableRtpParameters
=
ortc
.
getConsumableRtpParameters
(
kind
,
rtpParameters
,
routerRtpCapabilities
,
rtpMapping
);
const
internal
=
{
...
this
.
_internal
,
producerId
:
id
||
v4_1
.
default
()
};
const
reqData
=
{
kind
,
rtpParameters
,
rtpMapping
,
keyFrameRequestDelay
,
paused
};
const
status
=
await
this
.
_channel
.
request
(
'transport.produce'
,
internal
,
reqData
);
const
data
=
{
kind
,
rtpParameters
,
type
:
status
.
type
,
consumableRtpParameters
};
const
producer
=
new
Producer_1
.
Producer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
});
this
.
_producers
.
set
(
producer
.
id
,
producer
);
producer
.
on
(
'@close'
,
()
=>
{
this
.
_producers
.
delete
(
producer
.
id
);
this
.
emit
(
'@producerclose'
,
producer
);
});
this
.
emit
(
'@newproducer'
,
producer
);
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newproducer'
,
producer
);
return
producer
;
}
/**
* Create a Consumer.
*
* @virtual
*/
consume
({
producerId
,
rtpCapabilities
,
paused
=
false
,
preferredLayers
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
rtpCapabilities
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
consumerId
:
v4_1
.
default
(),
producerId
});
const
reqData
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
,
paused
,
preferredLayers
};
const
status
=
yield
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
};
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
:
status
.
paused
,
producerPaused
:
status
.
producerPaused
,
score
:
status
.
score
,
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
;
async
consume
({
producerId
,
rtpCapabilities
,
paused
=
false
,
preferredLayers
,
appData
=
{}
})
{
logger
.
debug
(
'consume()'
);
if
(
!
producerId
||
typeof
producerId
!==
'string'
)
throw
new
TypeError
(
'missing producerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateRtpCapabilities
(
rtpCapabilities
);
const
producer
=
this
.
_getProducerById
(
producerId
);
if
(
!
producer
)
throw
Error
(
`Producer with id "
${
producerId
}
" not found`
);
// This may throw.
const
rtpParameters
=
ortc
.
getConsumerRtpParameters
(
producer
.
consumableRtpParameters
,
rtpCapabilities
);
const
internal
=
{
...
this
.
_internal
,
consumerId
:
v4_1
.
default
(),
producerId
};
const
reqData
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
,
consumableRtpEncodings
:
producer
.
consumableRtpParameters
.
encodings
,
paused
,
preferredLayers
};
const
status
=
await
this
.
_channel
.
request
(
'transport.consume'
,
internal
,
reqData
);
const
data
=
{
kind
:
producer
.
kind
,
rtpParameters
,
type
:
producer
.
type
};
const
consumer
=
new
Consumer_1
.
Consumer
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
,
paused
:
status
.
paused
,
producerPaused
:
status
.
producerPaused
,
score
:
status
.
score
,
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
;
}
/**
* Create a DataProducer.
*/
produceData
({
id
=
undefined
,
sctpStreamParameters
,
label
=
''
,
protocol
=
''
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'produceData()'
);
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataProducerId
:
id
||
v4_1
.
default
()
});
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
const
dataProducer
=
new
DataProducer_1
.
DataProducer
({
internal
,
data
,
channel
:
this
.
_channel
,
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
;
async
produceData
({
id
=
undefined
,
sctpStreamParameters
,
label
=
''
,
protocol
=
''
,
appData
=
{}
})
{
logger
.
debug
(
'produceData()'
);
if
(
id
&&
this
.
_dataProducers
.
has
(
id
))
throw
new
TypeError
(
`a DataProducer with same id "
${
id
}
" already exists`
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
ortc
.
validateSctpStreamParameters
(
sctpStreamParameters
);
const
internal
=
{
...
this
.
_internal
,
dataProducerId
:
id
||
v4_1
.
default
()
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
await
this
.
_channel
.
request
(
'transport.produceData'
,
internal
,
reqData
);
const
dataProducer
=
new
DataProducer_1
.
DataProducer
({
internal
,
data
,
channel
:
this
.
_channel
,
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
;
}
/**
* Create a DataConsumer.
*/
consumeData
({
dataProducerId
,
appData
=
{}
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'consumeData()'
);
if
(
!
dataProducerId
||
typeof
dataProducerId
!==
'string'
)
throw
new
TypeError
(
'missing dataProducerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
dataProducer
=
this
.
_getDataProducerById
(
dataProducerId
);
if
(
!
dataProducer
)
throw
Error
(
`DataProducer with id "
${
dataProducerId
}
" not found`
);
const
sctpStreamParameters
=
utils
.
clone
(
dataProducer
.
sctpStreamParameters
);
const
{
label
,
protocol
}
=
dataProducer
;
// This may throw.
const
sctpStreamId
=
this
.
_getNextSctpStreamId
();
this
.
_sctpStreamIds
[
sctpStreamId
]
=
1
;
sctpStreamParameters
.
streamId
=
sctpStreamId
;
const
internal
=
Object
.
assign
(
Object
.
assign
({},
this
.
_internal
),
{
dataConsumerId
:
v4_1
.
default
(),
dataProducerId
});
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.consumeData'
,
internal
,
reqData
);
const
dataConsumer
=
new
DataConsumer_1
.
DataConsumer
({
internal
,
data
,
channel
:
this
.
_channel
,
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
;
async
consumeData
({
dataProducerId
,
appData
=
{}
})
{
logger
.
debug
(
'consumeData()'
);
if
(
!
dataProducerId
||
typeof
dataProducerId
!==
'string'
)
throw
new
TypeError
(
'missing dataProducerId'
);
else
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
dataProducer
=
this
.
_getDataProducerById
(
dataProducerId
);
if
(
!
dataProducer
)
throw
Error
(
`DataProducer with id "
${
dataProducerId
}
" not found`
);
const
sctpStreamParameters
=
utils
.
clone
(
dataProducer
.
sctpStreamParameters
);
const
{
label
,
protocol
}
=
dataProducer
;
// This may throw.
const
sctpStreamId
=
this
.
_getNextSctpStreamId
();
this
.
_sctpStreamIds
[
sctpStreamId
]
=
1
;
sctpStreamParameters
.
streamId
=
sctpStreamId
;
const
internal
=
{
...
this
.
_internal
,
dataConsumerId
:
v4_1
.
default
(),
dataProducerId
};
const
reqData
=
{
sctpStreamParameters
,
label
,
protocol
};
const
data
=
await
this
.
_channel
.
request
(
'transport.consumeData'
,
internal
,
reqData
);
const
dataConsumer
=
new
DataConsumer_1
.
DataConsumer
({
internal
,
data
,
channel
:
this
.
_channel
,
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
;
}
/**
* Enable 'trace' event.
*/
enableTraceEvent
(
types
=
[])
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'pause()'
);
const
reqData
=
{
types
};
yield
this
.
_channel
.
request
(
'transport.enableTraceEvent'
,
this
.
_internal
,
reqData
);
});
async
enableTraceEvent
(
types
=
[])
{
logger
.
debug
(
'pause()'
);
const
reqData
=
{
types
};
await
this
.
_channel
.
request
(
'transport.enableTraceEvent'
,
this
.
_internal
,
reqData
);
}
_getNextSctpStreamId
()
{
if
(
!
this
.
_data
.
sctpParameters
||
...
...
lib/WebRtcTransport.js
浏览文件 @
d09586fe
"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
});
const
Logger_1
=
require
(
"./Logger"
);
const
Transport_1
=
require
(
"./Transport"
);
...
...
@@ -186,37 +177,31 @@ class WebRtcTransport extends Transport_1.Transport {
*
* @override
*/
getStats
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
});
async
getStats
()
{
logger
.
debug
(
'getStats()'
);
return
this
.
_channel
.
request
(
'transport.getStats'
,
this
.
_internal
);
}
/**
* Provide the WebRtcTransport remote parameters.
*
* @override
*/
connect
({
dtlsParameters
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
dtlsParameters
};
const
data
=
yield
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
dtlsParameters
.
role
=
data
.
dtlsLocalRole
;
});
async
connect
({
dtlsParameters
})
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
dtlsParameters
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
dtlsParameters
.
role
=
data
.
dtlsLocalRole
;
}
/**
* Restart ICE.
*/
restartIce
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'restartIce()'
);
const
data
=
yield
this
.
_channel
.
request
(
'transport.restartIce'
,
this
.
_internal
);
const
{
iceParameters
}
=
data
;
this
.
_data
.
iceParameters
=
iceParameters
;
return
iceParameters
;
});
async
restartIce
()
{
logger
.
debug
(
'restartIce()'
);
const
data
=
await
this
.
_channel
.
request
(
'transport.restartIce'
,
this
.
_internal
);
const
{
iceParameters
}
=
data
;
this
.
_data
.
iceParameters
=
iceParameters
;
return
iceParameters
;
}
_handleWorkerNotifications
()
{
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
...
...
lib/Worker.js
浏览文件 @
d09586fe
"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
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
...
...
@@ -222,56 +213,48 @@ class Worker extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Dump Worker.
*/
dump
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'worker.dump'
);
});
async
dump
()
{
logger
.
debug
(
'dump()'
);
return
this
.
_channel
.
request
(
'worker.dump'
);
}
/**
* Get mediasoup-worker process resource usage.
*/
getResourceUsage
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'getResourceUsage()'
);
return
this
.
_channel
.
request
(
'worker.getResourceUsage'
);
});
async
getResourceUsage
()
{
logger
.
debug
(
'getResourceUsage()'
);
return
this
.
_channel
.
request
(
'worker.getResourceUsage'
);
}
/**
* Update settings.
*/
updateSettings
({
logLevel
,
logTags
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'updateSettings()'
);
const
reqData
=
{
logLevel
,
logTags
};
yield
this
.
_channel
.
request
(
'worker.updateSettings'
,
undefined
,
reqData
);
});
async
updateSettings
({
logLevel
,
logTags
}
=
{})
{
logger
.
debug
(
'updateSettings()'
);
const
reqData
=
{
logLevel
,
logTags
};
await
this
.
_channel
.
request
(
'worker.updateSettings'
,
undefined
,
reqData
);
}
/**
* Create a Router.
*/
createRouter
({
mediaCodecs
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createRouter()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
mediaCodecs
);
const
internal
=
{
routerId
:
v4_1
.
default
()
};
yield
this
.
_channel
.
request
(
'worker.createRouter'
,
internal
);
const
data
=
{
rtpCapabilities
};
const
router
=
new
Router_1
.
Router
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
});
this
.
_routers
.
add
(
router
);
router
.
on
(
'@close'
,
()
=>
this
.
_routers
.
delete
(
router
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrouter'
,
router
);
return
router
;
async
createRouter
({
mediaCodecs
,
appData
=
{}
}
=
{})
{
logger
.
debug
(
'createRouter()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
// This may throw.
const
rtpCapabilities
=
ortc
.
generateRouterRtpCapabilities
(
mediaCodecs
);
const
internal
=
{
routerId
:
v4_1
.
default
()
};
await
this
.
_channel
.
request
(
'worker.createRouter'
,
internal
);
const
data
=
{
rtpCapabilities
};
const
router
=
new
Router_1
.
Router
({
internal
,
data
,
channel
:
this
.
_channel
,
appData
});
this
.
_routers
.
add
(
router
);
router
.
on
(
'@close'
,
()
=>
this
.
_routers
.
delete
(
router
));
// Emit observer event.
this
.
_observer
.
safeEmit
(
'newrouter'
,
router
);
return
router
;
}
}
exports
.
Worker
=
Worker
;
lib/index.js
浏览文件 @
d09586fe
"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
)
{
if
(
mod
&&
mod
.
__esModule
)
return
mod
;
var
result
=
{};
...
...
@@ -38,28 +29,26 @@ exports.observer = observer;
/**
* Create a Worker.
*/
function
createWorker
({
logLevel
=
'error'
,
logTags
,
rtcMinPort
=
10000
,
rtcMaxPort
=
59999
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
=
{}
}
=
{})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
logger
.
debug
(
'createWorker()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
worker
=
new
Worker_1
.
Worker
({
logLevel
,
logTags
,
rtcMinPort
,
rtcMaxPort
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
});
return
new
Promise
((
resolve
,
reject
)
=>
{
worker
.
on
(
'@success'
,
()
=>
{
// Emit observer event.
observer
.
safeEmit
(
'newworker'
,
worker
);
resolve
(
worker
);
});
worker
.
on
(
'@failure'
,
reject
);
async
function
createWorker
({
logLevel
=
'error'
,
logTags
,
rtcMinPort
=
10000
,
rtcMaxPort
=
59999
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
=
{}
}
=
{})
{
logger
.
debug
(
'createWorker()'
);
if
(
appData
&&
typeof
appData
!==
'object'
)
throw
new
TypeError
(
'if given, appData must be an object'
);
const
worker
=
new
Worker_1
.
Worker
({
logLevel
,
logTags
,
rtcMinPort
,
rtcMaxPort
,
dtlsCertificateFile
,
dtlsPrivateKeyFile
,
appData
});
return
new
Promise
((
resolve
,
reject
)
=>
{
worker
.
on
(
'@success'
,
()
=>
{
// Emit observer event.
observer
.
safeEmit
(
'newworker'
,
worker
);
resolve
(
worker
);
});
worker
.
on
(
'@failure'
,
reject
);
});
}
exports
.
createWorker
=
createWorker
;
...
...
lib/ortc.js
浏览文件 @
d09586fe
...
...
@@ -449,7 +449,7 @@ function generateRouterRtpCapabilities(mediaCodecs = []) {
if
(
caps
.
codecs
.
some
((
c
)
=>
c
.
preferredPayloadType
===
codec
.
preferredPayloadType
))
throw
new
TypeError
(
'duplicated codec.preferredPayloadType'
);
// 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.
caps
.
codecs
.
push
(
codec
);
// Add a RTX video codec if video.
...
...
tsconfig.json
浏览文件 @
d09586fe
...
...
@@ -3,7 +3,7 @@
"compilerOptions"
:
{
"lib"
:
[
"es6"
,
"dom"
],
"target"
:
"es
6
"
,
"target"
:
"es
2020
"
,
"module"
:
"commonjs"
,
"moduleResolution"
:
"node"
,
"esModuleInterop"
:
true
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论