Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
44a1248a
提交
44a1248a
authored
8月 29, 2017
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Step by step
上级
3e9be3da
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
160 行增加
和
243 行删除
+160
-243
Consumer.js
lib/Consumer.js
+3
-3
Peer.js
lib/Peer.js
+72
-154
Producer.js
lib/Producer.js
+3
-3
Room.js
lib/Room.js
+26
-46
Transport.js
lib/Transport.js
+4
-4
Worker.js
lib/Worker.js
+5
-4
Notifier.hpp
worker/include/Channel/Notifier.hpp
+1
-4
Consumer.hpp
worker/include/RTC/Consumer.hpp
+6
-1
Producer.hpp
worker/include/RTC/Producer.hpp
+7
-2
Router.hpp
worker/include/RTC/Router.hpp
+4
-3
Notifier.cpp
worker/src/Channel/Notifier.cpp
+1
-4
Consumer.cpp
worker/src/RTC/Consumer.cpp
+7
-2
Producer.cpp
worker/src/RTC/Producer.cpp
+11
-4
Router.cpp
worker/src/RTC/Router.cpp
+3
-3
Transport.cpp
worker/src/RTC/Transport.cpp
+6
-5
main.cpp
worker/src/main.cpp
+1
-1
没有找到文件。
lib/Consumer.js
浏览文件 @
44a1248a
...
...
@@ -18,7 +18,7 @@ class Consumer extends EnhancedEventEmitter
this
.
_closed
=
false
;
// Internal data.
// - .ro
om
Id
// - .ro
uter
Id
// - .peerId
// - .consumerId
// - .transportId
...
...
@@ -47,7 +47,7 @@ class Consumer extends EnhancedEventEmitter
// @type {Boolean}
this
.
_sourcePaused
=
false
;
this
.
_handleNotifications
();
this
.
_handle
Worker
Notifications
();
}
get
id
()
...
...
@@ -380,7 +380,7 @@ class Consumer extends EnhancedEventEmitter
this
.
safeEmit
(
'resume'
,
'remote'
,
appData
);
}
_handleNotifications
()
_handle
Worker
Notifications
()
{
// Subscribe to notifications.
this
.
_channel
.
on
(
this
.
_internal
.
consumerId
,
(
event
)
=>
...
...
lib/Peer.js
浏览文件 @
44a1248a
...
...
@@ -6,7 +6,7 @@ const utils = require('./utils');
const
errors
=
require
(
'./errors'
);
const
Transport
=
require
(
'./Transport'
);
const
Producer
=
require
(
'./Producer'
);
const
Consumer
=
require
(
'./Consumer'
);
//
const Consumer = require('./Consumer');
const
KINDS
=
new
Set
([
'audio'
,
'video'
,
'depth'
]);
...
...
@@ -24,8 +24,7 @@ class Peer extends EnhancedEventEmitter
this
.
_closed
=
false
;
// Internal data.
// - .roomId
// - .peerId
// - .routerId
// - .peerName
this
.
_internal
=
internal
;
...
...
@@ -36,6 +35,7 @@ class Peer extends EnhancedEventEmitter
// Channel instance.
this
.
_channel
=
channel
;
// TODO: Let's see.
// Store internal sandbox stuff.
// - .getProducerById()
this
.
_sandbox
=
sandbox
;
...
...
@@ -43,9 +43,6 @@ class Peer extends EnhancedEventEmitter
// App data.
this
.
_appData
=
undefined
;
// Whether we are joined so can emit '@notify' events.
this
.
_joined
=
false
;
// Map of Transports indexed by id.
this
.
_transports
=
new
Map
();
...
...
@@ -54,13 +51,6 @@ class Peer extends EnhancedEventEmitter
// Map of Consumers indexed by id.
this
.
_consumers
=
new
Map
();
this
.
_handleNotifications
();
}
get
id
()
{
return
this
.
_internal
.
peerId
;
}
get
closed
()
...
...
@@ -83,11 +73,6 @@ class Peer extends EnhancedEventEmitter
this
.
_appData
=
appData
;
}
set
joined
(
flag
)
{
this
.
_joined
=
Boolean
(
joined
);
}
get
rtpCapabilities
()
{
return
this
.
_data
.
rtpCapabilities
;
...
...
@@ -147,26 +132,24 @@ class Peer extends EnhancedEventEmitter
// Close all the Producers.
for
(
const
producer
of
this
.
_producers
.
values
())
{
producer
.
close
(
undefined
,
false
);
producer
.
close
(
undefined
,
notifyChannel
);
}
// Close all the Consumers.
for
(
const
consumer
of
this
.
_consumers
.
values
())
{
consumer
.
close
();
consumer
.
close
(
undefined
,
notifyChannel
);
}
// Close all the Transports.
for
(
const
transport
of
this
.
_transports
.
values
())
{
transport
.
close
(
undefined
,
false
);
transport
.
close
(
undefined
,
notifyChannel
);
}
this
.
_destroy
(
notifyChannel
);
}
/**
* The remote Peer
was closed
.
* The remote Peer
left the Room
.
* Invoked via remote notification.
*
* @private
...
...
@@ -188,7 +171,7 @@ class Peer extends EnhancedEventEmitter
// Close all the Producers.
for
(
const
producer
of
this
.
_producers
.
values
())
{
producer
.
remoteClose
(
undefined
,
false
);
producer
.
remoteClose
();
}
// Close all the Consumers.
...
...
@@ -200,32 +183,7 @@ class Peer extends EnhancedEventEmitter
// Close all the Transports.
for
(
const
transport
of
this
.
_transports
.
values
())
{
transport
.
remoteClose
(
undefined
,
false
);
}
this
.
_destroy
();
}
/**
* Destroy the Peer.
*/
_destroy
(
notifyChannel
=
true
)
{
// Remove notification subscriptions.
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
peerId
);
if
(
notifyChannel
)
{
// Send Channel request.
this
.
_channel
.
request
(
'peer.close'
,
this
.
_internal
)
.
then
(()
=>
{
logger
.
debug
(
'"peer.close" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"peer.close" request failed: %s'
,
String
(
error
));
});
transport
.
remoteClose
();
}
}
...
...
@@ -277,16 +235,58 @@ class Peer extends EnhancedEventEmitter
if
(
this
.
_closed
)
return
Promise
.
reject
(
new
errors
.
InvalidStateError
(
'Peer closed'
));
return
this
.
_channel
.
request
(
'peer.dump'
,
this
.
_internal
)
.
then
((
data
)
=>
const
peerData
=
{
peerName
:
this
.
name
,
transports
:
[],
producers
:
[],
consumers
:
[]
};
const
promises
=
[];
for
(
const
transport
of
this
.
_transports
.
values
())
{
const
promise
=
transport
.
dump
()
.
then
((
data
)
=>
{
peerData
.
transports
.
push
(
data
);
});
promises
.
push
(
promise
);
}
for
(
const
producer
of
this
.
_producers
.
values
())
{
const
promise
=
producer
.
dump
()
.
then
((
data
)
=>
{
peerData
.
producers
.
push
(
data
);
});
promises
.
push
(
promise
);
}
for
(
const
consumer
of
this
.
_consumers
.
values
())
{
const
promise
=
consumer
.
dump
()
.
then
((
data
)
=>
{
peerData
.
consumers
.
push
(
data
);
});
promises
.
push
(
promise
);
}
return
Promise
.
all
(
promises
)
.
then
(()
=>
{
logger
.
debug
(
'
"peer.dump" request
succeeded'
);
logger
.
debug
(
'
dump() |
succeeded'
);
return
d
ata
;
return
peerD
ata
;
})
.
catch
((
error
)
=>
{
logger
.
error
(
'
"peer.dump" request
failed: %s'
,
String
(
error
));
logger
.
error
(
'
dump() |
failed: %s'
,
String
(
error
));
throw
error
;
});
...
...
@@ -316,11 +316,9 @@ class Peer extends EnhancedEventEmitter
{
const
{
id
,
options
,
dtlsParameters
,
appData
}
=
request
;
return
this
.
_createTransport
(
id
,
options
)
return
this
.
_createTransport
(
id
,
options
,
appData
)
.
then
((
transport
)
=>
{
transport
.
appData
=
appData
;
// If no client's DTLS parameters are given, we are done.
if
(
!
dtlsParameters
)
return
transport
;
...
...
@@ -383,11 +381,9 @@ class Peer extends EnhancedEventEmitter
const
rtpMapping
=
this
.
_sandbox
.
getProducerRtpParametersMapping
(
rtpParameters
);
return
this
.
_createProducer
(
id
,
kind
,
transportId
)
return
this
.
_createProducer
(
id
,
kind
,
transportId
,
appData
)
.
then
((
producer
)
=>
{
producer
.
appData
=
appData
;
if
(
paused
)
producer
.
remotePause
();
...
...
@@ -547,25 +543,26 @@ class Peer extends EnhancedEventEmitter
this
.
safeEmit
(
'notify'
,
notification
);
}
_createTransport
(
id
,
options
)
_createTransport
(
id
,
options
,
appData
)
{
logger
.
debug
(
'_createTransport() [id:%s]'
,
id
);
const
internal
=
{
roomId
:
this
.
_internal
.
roomId
,
peerId
:
this
.
_internal
.
peerId
,
routerId
:
this
.
_internal
.
routerId
,
transportId
:
id
||
utils
.
randomNumber
()
};
return
this
.
_channel
.
request
(
'
pe
er.createTransport'
,
internal
,
options
)
return
this
.
_channel
.
request
(
'
rout
er.createTransport'
,
internal
,
options
)
.
then
((
data
)
=>
{
logger
.
debug
(
'"
pe
er.createTransport" request succeeded'
);
logger
.
debug
(
'"
rout
er.createTransport" request succeeded'
);
// Create a Transport.
const
transport
=
new
Transport
(
internal
,
data
,
this
.
_channel
);
transport
.
appData
=
appData
;
// Store the Transport and remove it when closed.
this
.
_transports
.
set
(
transport
.
id
,
transport
);
transport
.
on
(
'@close'
,
()
=>
this
.
_transports
.
delete
(
transport
.
id
));
...
...
@@ -581,13 +578,13 @@ class Peer extends EnhancedEventEmitter
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"
pe
er.createTransport" request failed: %s'
,
String
(
error
));
logger
.
error
(
'"
rout
er.createTransport" request failed: %s'
,
String
(
error
));
throw
error
;
});
}
_createProducer
(
id
,
kind
,
transportId
)
_createProducer
(
id
,
kind
,
transportId
,
appData
)
{
logger
.
debug
(
'_createProducer() [id:%s, kind:%s]'
,
id
,
kind
);
...
...
@@ -603,8 +600,7 @@ class Peer extends EnhancedEventEmitter
const
internal
=
{
roomId
:
this
.
_internal
.
roomId
,
peerId
:
this
.
_internal
.
peerId
,
routerId
:
this
.
_internal
.
routerId
,
producerId
:
id
||
utils
.
randomNumber
(),
transportId
:
transport
.
id
};
...
...
@@ -621,14 +617,16 @@ class Peer extends EnhancedEventEmitter
kind
};
return
this
.
_channel
.
request
(
'
pe
er.createProducer'
,
internal
,
options
)
return
this
.
_channel
.
request
(
'
rout
er.createProducer'
,
internal
,
options
)
.
then
(()
=>
{
logger
.
debug
(
'"
pe
er.createProducer" request succeeded'
);
logger
.
debug
(
'"
rout
er.createProducer" request succeeded'
);
// Create a Producer instance.
const
producer
=
new
Producer
(
internal
,
data
,
this
.
_channel
);
producer
.
appData
=
appData
;
// Store the Producer and remove it when closed.
this
.
_producers
.
set
(
producer
.
id
,
producer
);
producer
.
on
(
'@close'
,
()
=>
this
.
_producers
.
delete
(
producer
.
id
));
...
...
@@ -652,91 +650,11 @@ class Peer extends EnhancedEventEmitter
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"
pe
er.createProducer" request failed: %s'
,
String
(
error
));
logger
.
error
(
'"
rout
er.createProducer" request failed: %s'
,
String
(
error
));
throw
error
;
});
}
_handleNotifications
()
{
// Subscribe to notifications.
this
.
_channel
.
on
(
this
.
_internal
.
peerId
,
(
event
,
data
)
=>
{
switch
(
event
)
{
case
'close'
:
{
this
.
close
(
undefined
,
false
);
break
;
}
// TODO: yes? or get it from data.peerName in 'newconsumer' and retreive
// peers via JS? Then what about `peerClosed`?
case
'newpeer'
:
{
// TODO
break
;
}
case
'newconsumer'
:
{
// TODO
console
.
warn
(
'----------------- newconsumer | peer.consumers:%s'
,
this
.
_consumers
.
size
+
1
);
// TODO
const
source
=
this
.
_sandbox
.
getProducerById
(
data
.
sourceId
);
const
consumerInternal
=
{
roomId
:
this
.
_internal
.
roomId
,
peerId
:
this
.
_internal
.
peerId
,
consumerId
:
data
.
consumerId
,
transportId
:
undefined
};
// TODO
const
consumerData
=
{
kind
:
data
.
kind
,
peer
:
this
,
rtpParameters
:
data
.
rtpParameters
,
source
:
source
};
// Create a Consumer instance.
const
consumer
=
new
Consumer
(
consumerInternal
,
consumerData
,
this
.
_channel
);
// Store the Consumer instance and remove it when closed.
this
.
_consumers
.
set
(
consumer
.
id
,
consumer
);
consumer
.
on
(
'@close'
,
()
=>
this
.
_consumers
.
delete
(
consumer
.
id
));
// TODO: Get the Consumer Peer?
if
(
this
.
_joined
)
{
// TODO: Let's see.
// TODO: appData? of the associated Producer/source?
// const foo = consumer.toJson();
const
foo
=
{
id
:
consumer
.
id
,
kind
:
consumer
.
kind
};
// Send a notification.
this
.
_sendNotification
(
'newConsumer'
,
foo
);
}
this
.
safeEmit
(
'newconsumer'
,
consumer
);
break
;
}
default
:
logger
.
error
(
'ignoring unknown event "%s"'
,
event
);
}
});
}
}
module
.
exports
=
Peer
;
lib/Producer.js
浏览文件 @
44a1248a
...
...
@@ -18,7 +18,7 @@ class Producer extends EnhancedEventEmitter
this
.
_closed
=
false
;
// Internal data.
// - .ro
om
Id
// - .ro
uter
Id
// - .peerId
// - .producerId
// - .transportId
...
...
@@ -42,7 +42,7 @@ class Producer extends EnhancedEventEmitter
// @type {Boolean}
this
.
_remotelyPaused
=
false
;
this
.
_handleNotifications
();
this
.
_handle
Worker
Notifications
();
}
get
id
()
...
...
@@ -392,7 +392,7 @@ class Producer extends EnhancedEventEmitter
this
.
safeEmit
(
'resume'
,
'remote'
,
appData
);
}
_handleNotifications
()
_handle
Worker
Notifications
()
{
// Subscribe to notifications.
this
.
_channel
.
on
(
this
.
_internal
.
producerId
,
(
event
,
data
,
buffer
)
=>
...
...
lib/Room.js
浏览文件 @
44a1248a
...
...
@@ -3,7 +3,6 @@
const
Logger
=
require
(
'./Logger'
);
const
EnhancedEventEmitter
=
require
(
'./EnhancedEventEmitter'
);
const
errors
=
require
(
'./errors'
);
const
utils
=
require
(
'./utils'
);
const
ortc
=
require
(
'./ortc'
);
const
Peer
=
require
(
'./Peer'
);
...
...
@@ -21,7 +20,7 @@ class Room extends EnhancedEventEmitter
this
.
_closed
=
false
;
// Internal data.
// - .ro
om
Id
// - .ro
uter
Id
this
.
_internal
=
internal
;
// Room data.
...
...
@@ -38,12 +37,12 @@ class Room extends EnhancedEventEmitter
// Map of Producer instances indexed by `producerId`.
this
.
_producers
=
new
Map
();
this
.
_handleNotifications
();
this
.
_handle
Worker
Notifications
();
}
get
id
()
{
return
this
.
_internal
.
ro
om
Id
;
return
this
.
_internal
.
ro
uter
Id
;
}
get
closed
()
...
...
@@ -85,7 +84,7 @@ class Room extends EnhancedEventEmitter
this
.
safeEmit
(
'close'
,
appData
);
// Remove notification subscriptions.
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
ro
om
Id
);
this
.
_channel
.
removeAllListeners
(
this
.
_internal
.
ro
uter
Id
);
// Close every Peer.
for
(
const
peer
of
this
.
_peers
.
values
())
...
...
@@ -96,14 +95,14 @@ class Room extends EnhancedEventEmitter
if
(
notifyChannel
)
{
// Send Channel request.
this
.
_channel
.
request
(
'ro
om
.close'
,
this
.
_internal
)
this
.
_channel
.
request
(
'ro
uter
.close'
,
this
.
_internal
)
.
then
(()
=>
{
logger
.
debug
(
'"ro
om
.close" request succeeded'
);
logger
.
debug
(
'"ro
uter
.close" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"ro
om
.close" request failed: %s'
,
String
(
error
));
logger
.
error
(
'"ro
uter
.close" request failed: %s'
,
String
(
error
));
});
}
}
...
...
@@ -120,16 +119,16 @@ class Room extends EnhancedEventEmitter
if
(
this
.
_closed
)
return
Promise
.
reject
(
new
errors
.
InvalidStateError
(
'Room closed'
));
return
this
.
_channel
.
request
(
'ro
om
.dump'
,
this
.
_internal
)
return
this
.
_channel
.
request
(
'ro
uter
.dump'
,
this
.
_internal
)
.
then
((
data
)
=>
{
logger
.
debug
(
'"ro
om
.dump" request succeeded'
);
logger
.
debug
(
'"ro
uter
.dump" request succeeded'
);
return
data
;
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"ro
om
.dump" request failed: %s'
,
String
(
error
));
logger
.
error
(
'"ro
uter
.dump" request failed: %s'
,
String
(
error
));
throw
error
;
});
...
...
@@ -188,6 +187,7 @@ class Room extends EnhancedEventEmitter
ortc
.
assertCapabilitiesSubset
(
rtpCapabilities
,
this
.
rtpCapabilities
);
// eslint-disable-next-line no-unused-vars
const
peer
=
this
.
_createPeer
(
peerName
,
rtpCapabilities
,
appData
);
const
response
=
...
...
@@ -215,14 +215,13 @@ class Room extends EnhancedEventEmitter
logger
.
debug
(
'_createPeer() [peerName:"%s]'
,
peerName
);
if
(
!
peerName
||
typeof
peerName
!==
'string'
)
return
Promise
.
reject
(
new
TypeError
(
'peerName must be a string'
)
);
throw
new
TypeError
(
'peerName must be a string'
);
else
if
(
this
.
_peers
.
has
(
peerName
))
return
Promise
.
reject
(
new
Error
(
`duplicated Peer [peerName:"
${
peerName
}
"]`
)
);
throw
new
Error
(
`duplicated Peer [peerName:"
${
peerName
}
"]`
);
const
internal
=
{
roomId
:
this
.
_internal
.
roomId
,
peerId
:
utils
.
randomNumber
(),
routerId
:
this
.
_internal
.
routerId
,
peerName
:
peerName
};
...
...
@@ -233,6 +232,7 @@ class Room extends EnhancedEventEmitter
const
sandbox
=
{
// TODO: Let's see.
getProducerById
:
(
producerId
)
=>
{
return
this
.
_producers
.
get
(
producerId
);
...
...
@@ -255,6 +255,7 @@ class Room extends EnhancedEventEmitter
this
.
_peers
.
set
(
peer
.
name
,
peer
);
peer
.
on
(
'@close'
,
()
=>
this
.
_peers
.
delete
(
peer
.
name
));
// TODO: Let's see.
// Listen for new Producers so we can associate new Consumers.
peer
.
on
(
'@newproducer'
,
(
producer
)
=>
{
...
...
@@ -263,42 +264,21 @@ class Room extends EnhancedEventEmitter
producer
.
on
(
'@close'
,
()
=>
this
.
_producers
.
delete
(
producer
.
id
));
});
this
.
_channel
.
request
(
'room.createPeer'
,
internal
)
.
then
(()
=>
{
logger
.
debug
(
'"room.createPeer" request succeeded'
);
peer
.
joined
=
true
;
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"room.createPeer" request failed: %s'
,
String
(
error
));
peer
.
close
();
});
this
.
safeEmit
(
'newpeer'
,
peer
);
return
peer
;
}
_handleNotifications
()
_handle
Worker
Notifications
()
{
// Subscribe to notifications.
this
.
_channel
.
on
(
this
.
_internal
.
ro
om
Id
,
(
event
,
data
)
=>
this
.
_channel
.
on
(
this
.
_internal
.
ro
uter
Id
,
(
event
,
data
)
=>
{
switch
(
event
)
{
case
'close'
:
{
this
.
close
(
undefined
,
false
);
break
;
}
case
'audiolevels'
:
{
const
entries
=
data
.
entries
;
const
{
entries
}
=
data
;
const
entries2
=
[];
for
(
const
entry
of
entries
)
...
...
@@ -310,7 +290,7 @@ class Room extends EnhancedEventEmitter
if
(
!
producer
)
continue
;
const
peer
=
producer
.
pe
er
;
const
{
peer
}
=
produc
er
;
entries2
.
push
({
peer
,
producer
,
audioLevel
});
}
...
...
@@ -348,15 +328,15 @@ class Room extends EnhancedEventEmitter
// Send Channel request.
this
.
_channel
.
request
(
'ro
om
.setAudioLevelsEvent'
,
this
.
_internal
,
{
enabled
:
true
})
'ro
uter
.setAudioLevelsEvent'
,
this
.
_internal
,
{
enabled
:
true
})
.
then
(()
=>
{
logger
.
debug
(
'"ro
om
.setAudioLevelsEvent" request succeeded'
);
logger
.
debug
(
'"ro
uter
.setAudioLevelsEvent" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"ro
om
.setAudioLevelsEvent" request failed: %s'
,
String
(
error
));
'"ro
uter
.setAudioLevelsEvent" request failed: %s'
,
String
(
error
));
});
break
;
...
...
@@ -377,15 +357,15 @@ class Room extends EnhancedEventEmitter
// Send Channel request.
this
.
_channel
.
request
(
'ro
om
.setAudioLevelsEvent'
,
this
.
_internal
,
{
enabled
:
false
})
'ro
uter
.setAudioLevelsEvent'
,
this
.
_internal
,
{
enabled
:
false
})
.
then
(()
=>
{
logger
.
debug
(
'"ro
om
.setAudioLevelsEvent" request succeeded'
);
logger
.
debug
(
'"ro
uter
.setAudioLevelsEvent" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"ro
om
.setAudioLevelsEvent" request failed: %s'
,
String
(
error
));
'"ro
uter
.setAudioLevelsEvent" request failed: %s'
,
String
(
error
));
});
break
;
...
...
lib/Transport.js
浏览文件 @
44a1248a
...
...
@@ -18,8 +18,7 @@ class Transport extends EnhancedEventEmitter
this
.
_closed
=
false
;
// Internal data.
// - .roomId
// - .peerId
// - .routerId
// - .transportId
this
.
_internal
=
internal
;
...
...
@@ -65,7 +64,7 @@ class Transport extends EnhancedEventEmitter
// App data.
this
.
_appData
=
undefined
;
this
.
_handleNotifications
();
this
.
_handle
Worker
Notifications
();
}
get
id
()
...
...
@@ -330,13 +329,14 @@ class Transport extends EnhancedEventEmitter
});
}
_handleNotifications
()
_handle
Worker
Notifications
()
{
// Subscribe to notifications.
this
.
_channel
.
on
(
this
.
_internal
.
transportId
,
(
event
,
data
)
=>
{
switch
(
event
)
{
// TODO: may be
case
'close'
:
{
this
.
close
(
undefined
,
false
);
...
...
lib/Worker.js
浏览文件 @
44a1248a
...
...
@@ -187,22 +187,23 @@ class Worker extends EventEmitter
const
internal
=
{
ro
om
Id
:
utils
.
randomNumber
()
ro
uter
Id
:
utils
.
randomNumber
()
};
const
room
=
new
Room
(
internal
,
data
,
this
.
_channel
);
// Store the Room instance and remove it when closed.
this
.
_rooms
.
add
(
room
);
room
.
on
(
'@close'
,
()
=>
this
.
_rooms
.
delete
(
room
));
this
.
_channel
.
request
(
'worker.createRo
om
'
,
internal
)
this
.
_channel
.
request
(
'worker.createRo
uter
'
,
internal
)
.
then
(()
=>
{
logger
.
debug
(
'"worker.createRo
om
" request succeeded'
);
logger
.
debug
(
'"worker.createRo
uter
" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"worker.createRo
om
" request failed: %s'
,
String
(
error
));
logger
.
error
(
'"worker.createRo
uter
" request failed: %s'
,
String
(
error
));
room
.
close
(
undefined
,
false
);
});
...
...
worker/include/Channel/Notifier.hpp
浏览文件 @
44a1248a
...
...
@@ -16,10 +16,7 @@ namespace Channel
void
Emit
(
uint32_t
targetId
,
const
std
::
string
&
event
);
void
Emit
(
uint32_t
targetId
,
const
std
::
string
&
event
,
Json
::
Value
&
data
);
void
EmitWithBinary
(
uint32_t
targetId
,
const
std
::
string
&
event
,
const
uint8_t
*
binaryData
,
size_t
binaryLen
);
uint32_t
targetId
,
const
std
::
string
&
event
,
const
uint8_t
*
binaryData
,
size_t
binaryLen
);
void
EmitWithBinary
(
uint32_t
targetId
,
const
std
::
string
&
event
,
...
...
worker/include/RTC/Consumer.hpp
浏览文件 @
44a1248a
...
...
@@ -32,7 +32,12 @@ namespace RTC
};
public
:
Consumer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
consumerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
);
Consumer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
consumerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
);
private
:
virtual
~
Consumer
();
...
...
worker/include/RTC/Producer.hpp
浏览文件 @
44a1248a
...
...
@@ -26,7 +26,7 @@ namespace RTC
class
Listener
{
public
:
virtual
void
OnProducerClosed
(
RTC
::
Producer
*
producer
)
=
0
;
virtual
void
OnProducerClosed
(
RTC
::
Producer
*
producer
)
=
0
;
virtual
void
OnProducerRtpPacket
(
RTC
::
Producer
*
producer
,
RTC
::
RtpPacket
*
packet
)
=
0
;
};
...
...
@@ -45,7 +45,12 @@ namespace RTC
};
public
:
Producer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
producerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
);
Producer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
producerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
);
public
:
// Must be public because Router needs to call it.
...
...
worker/include/RTC/Router.hpp
浏览文件 @
44a1248a
...
...
@@ -4,10 +4,10 @@
#include "common.hpp"
#include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/Transport.hpp"
#include "RTC/Producer.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/Producer.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/Transport.hpp"
// TODO: Let's see.
// #include "RTC/RTCP/Feedback.hpp"
// #include "RTC/RTCP/ReceiverReport.hpp"
...
...
@@ -51,7 +51,8 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
);
private
:
RTC
::
Transport
*
GetTransportFromRequest
(
Channel
::
Request
*
request
,
uint32_t
*
transportId
=
nullptr
)
const
;
RTC
::
Transport
*
GetTransportFromRequest
(
Channel
::
Request
*
request
,
uint32_t
*
transportId
=
nullptr
)
const
;
RTC
::
Producer
*
GetProducerFromRequest
(
Channel
::
Request
*
request
,
uint32_t
*
producerId
=
nullptr
)
const
;
RTC
::
Consumer
*
GetConsumerFromRequest
(
Channel
::
Request
*
request
,
uint32_t
*
consumerId
=
nullptr
)
const
;
...
...
worker/src/Channel/Notifier.cpp
浏览文件 @
44a1248a
...
...
@@ -46,10 +46,7 @@ namespace Channel
}
void
Notifier
::
EmitWithBinary
(
uint32_t
targetId
,
const
std
::
string
&
event
,
const
uint8_t
*
binaryData
,
size_t
binaryLen
)
uint32_t
targetId
,
const
std
::
string
&
event
,
const
uint8_t
*
binaryData
,
size_t
binaryLen
)
{
MS_TRACE
();
...
...
worker/src/RTC/Consumer.cpp
浏览文件 @
44a1248a
...
...
@@ -18,8 +18,13 @@ namespace RTC
/* Instance methods. */
Consumer
::
Consumer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
consumerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
)
:
consumerId
(
consumerId
),
kind
(
kind
),
listener
(
listener
),
notifier
(
notifier
),
transport
(
transport
)
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
consumerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
)
:
consumerId
(
consumerId
),
kind
(
kind
),
listener
(
listener
),
notifier
(
notifier
),
transport
(
transport
)
{
MS_TRACE
();
...
...
worker/src/RTC/Producer.cpp
浏览文件 @
44a1248a
...
...
@@ -13,8 +13,13 @@ namespace RTC
/* Instance methods. */
Producer
::
Producer
(
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
producerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
)
:
producerId
(
producerId
),
kind
(
kind
),
listener
(
listener
),
notifier
(
notifier
),
transport
(
transport
)
Listener
*
listener
,
Channel
::
Notifier
*
notifier
,
uint32_t
producerId
,
RTC
::
Media
::
Kind
kind
,
RTC
::
Transport
*
transport
)
:
producerId
(
producerId
),
kind
(
kind
),
listener
(
listener
),
notifier
(
notifier
),
transport
(
transport
)
{
MS_TRACE
();
...
...
@@ -151,6 +156,9 @@ namespace RTC
// NOTE: This may throw.
CreateRtpMapping
(
request
->
data
[
JsonStringRtpMapping
]);
// NOTE: This may throw.
this
->
transport
->
HandleProducer
(
this
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -298,8 +306,7 @@ namespace RTC
// Emit "rtpraw" if enabled.
if
(
this
->
rtpRawEventEnabled
)
{
this
->
notifier
->
EmitWithBinary
(
this
->
producerId
,
"rtpraw"
,
packet
->
GetData
(),
packet
->
GetSize
());
this
->
notifier
->
EmitWithBinary
(
this
->
producerId
,
"rtpraw"
,
packet
->
GetData
(),
packet
->
GetSize
());
}
// Emit "rtpobject" is enabled.
...
...
worker/src/RTC/Router.cpp
浏览文件 @
44a1248a
...
...
@@ -535,7 +535,7 @@ namespace RTC
if
(
transportId
!=
nullptr
)
*
transportId
=
jsonTransportId
.
asUInt
();
auto
it
=
this
->
transports
.
find
(
*
transportId
);
auto
it
=
this
->
transports
.
find
(
jsonTransportId
.
asUInt
()
);
if
(
it
!=
this
->
transports
.
end
())
{
auto
*
transport
=
it
->
second
;
...
...
@@ -560,7 +560,7 @@ namespace RTC
if
(
producerId
!=
nullptr
)
*
producerId
=
jsonProducerId
.
asUInt
();
auto
it
=
this
->
producers
.
find
(
*
producerId
);
auto
it
=
this
->
producers
.
find
(
jsonProducerId
.
asUInt
()
);
if
(
it
!=
this
->
producers
.
end
())
{
auto
*
producer
=
it
->
second
;
...
...
@@ -585,7 +585,7 @@ namespace RTC
if
(
consumerId
!=
nullptr
)
*
consumerId
=
jsonConsumerId
.
asUInt
();
auto
it
=
this
->
consumers
.
find
(
*
consumerId
);
auto
it
=
this
->
consumers
.
find
(
jsonConsumerId
.
asUInt
()
);
if
(
it
!=
this
->
consumers
.
end
())
{
auto
*
consumer
=
it
->
second
;
...
...
worker/src/RTC/Transport.cpp
浏览文件 @
44a1248a
...
...
@@ -7,8 +7,8 @@
#include "MediaSoupError.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include "RTC/Producer.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/Producer.hpp"
#include "RTC/RTCP/FeedbackPsRemb.hpp"
#include <cmath> // std::pow()
#include <iterator> // std::ostream_iterator
...
...
@@ -599,17 +599,18 @@ namespace RTC
{
MS_TRACE
();
// NOTE: This may throw.
this
->
rtpListener
.
AddProducer
(
producer
);
// TODO: add to the set.
// TODO: add to the map
// If it has RTP parameters pass it to the RTP listener.
if
(
producer
->
GetParameters
())
this
->
rtpListener
.
AddProducer
(
producer
);
}
void
Transport
::
HandleConsumer
(
RTC
::
Consumer
*
consumer
)
{
MS_TRACE
();
// TODO
// TODO
: add to the set.
}
void
Transport
::
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
)
...
...
worker/src/main.cpp
浏览文件 @
44a1248a
...
...
@@ -6,10 +6,10 @@
#include "DepLibUV.hpp"
#include "DepOpenSSL.hpp"
#include "Logger.hpp"
#include "Worker.hpp"
#include "MediaSoupError.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include "Worker.hpp"
#include "Channel/UnixStreamSocket.hpp"
#include "RTC/DtlsTransport.hpp"
#include "RTC/SrtpSession.hpp"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论