mirror of
https://github.com/strukturag/nextcloud-spreed-signaling.git
synced 2023-10-21 07:33:40 -05:00
Add specific ID for connections
A new ID is introduced for publishers and subscribers to be able to identify different connections in the same session. While it was possible to do that from the Janus handles this ID is meant to be shared with the clients and set by the peer sending the offer, so it is set by the client for publishers and by the signaling server for subscribers (in which case the Janus handle is used). This will make possible to know without any ambiguity if an offer/answer belongs to an already existing connection or not. This can be used, for example, to know if an offer represents an update or a new connection, or to discard unneeded messages that might be sent in some corner cases by the clients. The ID name is "sid" for consistency with the property name used by the internal signaling server of Talk. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
+12
-1
@@ -436,6 +436,7 @@ type mcuJanusClient struct {
|
||||
id uint64
|
||||
session uint64
|
||||
roomId uint64
|
||||
sid string
|
||||
streamType string
|
||||
|
||||
handle *JanusHandle
|
||||
@@ -455,6 +456,10 @@ func (c *mcuJanusClient) Id() string {
|
||||
return strconv.FormatUint(c.id, 10)
|
||||
}
|
||||
|
||||
func (c *mcuJanusClient) Sid() string {
|
||||
return c.sid
|
||||
}
|
||||
|
||||
func (c *mcuJanusClient) StreamType() string {
|
||||
return c.streamType
|
||||
}
|
||||
@@ -781,7 +786,7 @@ func (m *mcuJanus) getOrCreatePublisherHandle(ctx context.Context, id string, st
|
||||
return handle, response.Session, roomId, nil
|
||||
}
|
||||
|
||||
func (m *mcuJanus) NewPublisher(ctx context.Context, listener McuListener, id string, streamType string, bitrate int, mediaTypes MediaType, initiator McuInitiator) (McuPublisher, error) {
|
||||
func (m *mcuJanus) NewPublisher(ctx context.Context, listener McuListener, id string, sid string, streamType string, bitrate int, mediaTypes MediaType, initiator McuInitiator) (McuPublisher, error) {
|
||||
if _, found := streamTypeUserIds[streamType]; !found {
|
||||
return nil, fmt.Errorf("Unsupported stream type %s", streamType)
|
||||
}
|
||||
@@ -799,6 +804,7 @@ func (m *mcuJanus) NewPublisher(ctx context.Context, listener McuListener, id st
|
||||
id: atomic.AddUint64(&m.clientId, 1),
|
||||
session: session,
|
||||
roomId: roomId,
|
||||
sid: sid,
|
||||
streamType: streamType,
|
||||
|
||||
handle: handle,
|
||||
@@ -1032,6 +1038,7 @@ func (m *mcuJanus) NewSubscriber(ctx context.Context, listener McuListener, publ
|
||||
|
||||
id: atomic.AddUint64(&m.clientId, 1),
|
||||
roomId: pub.roomId,
|
||||
sid: strconv.FormatUint(handle.Id, 10),
|
||||
streamType: streamType,
|
||||
|
||||
handle: handle,
|
||||
@@ -1123,6 +1130,8 @@ func (p *mcuJanusSubscriber) NotifyReconnected() {
|
||||
p.handle = handle
|
||||
p.handleId = handle.Id
|
||||
p.roomId = pub.roomId
|
||||
p.sid = strconv.FormatUint(handle.Id, 10)
|
||||
p.listener.SubscriberSidUpdated(p)
|
||||
log.Printf("Subscriber %d for publisher %s reconnected on handle %d", p.id, p.publisher, p.handleId)
|
||||
}
|
||||
|
||||
@@ -1191,6 +1200,8 @@ retry:
|
||||
p.handle = handle
|
||||
p.handleId = handle.Id
|
||||
p.roomId = pub.roomId
|
||||
p.sid = strconv.FormatUint(handle.Id, 10)
|
||||
p.listener.SubscriberSidUpdated(p)
|
||||
p.closeChan = make(chan bool, 1)
|
||||
go p.run(p.handle, p.closeChan)
|
||||
log.Printf("Already connected subscriber %d for %s, leaving and re-joining on handle %d", p.id, p.streamType, p.handleId)
|
||||
|
||||
Reference in New Issue
Block a user