Skip to content

Commit

Permalink
fix RTCPeerConnection.addTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
hthetiot committed Oct 13, 2019
1 parent 6e17853 commit ba3900f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/PluginRTCPeerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {
if (IsUnifiedPlan()) {

var streamAdded : Bool = false;
for (_, pluginMediaStream) in pluginMediaStream.audioTracks {
streamAdded = self.addTrack(pluginMediaStream) && streamAdded;
for (_, pluginMediaTrack) in pluginMediaStream.audioTracks {
streamAdded = self.addTrack(pluginMediaTrack, pluginMediaStream) && streamAdded;
}

for (_, pluginMediaStream) in pluginMediaStream.videoTracks {
streamAdded = self.addTrack(pluginMediaStream) && streamAdded;
for (_, pluginMediaTrack) in pluginMediaStream.videoTracks {
streamAdded = self.addTrack(pluginMediaTrack, pluginMediaStream) && streamAdded;
}

return streamAdded;
Expand Down Expand Up @@ -332,7 +332,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {
return rtcPeerConnection.configuration.sdpSemantics == RTCSdpSemantics.unifiedPlan;
}

func addTrack(_ pluginMediaTrack: PluginMediaStreamTrack) -> Bool {
func addTrack(_ pluginMediaTrack: PluginMediaStreamTrack, _ pluginMediaStream: PluginMediaStream) -> Bool {
NSLog("PluginRTCPeerConnection#addTrack()")

if self.rtcPeerConnection.signalingState == RTCSignalingState.closed {
Expand All @@ -342,7 +342,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {
let rtcMediaStreamTrack = pluginMediaTrack.rtcMediaStreamTrack;
var rtcSender = trackIdsToSenders[rtcMediaStreamTrack.trackId];
if (rtcSender == nil) {
rtcSender = self.rtcPeerConnection.add(rtcMediaStreamTrack, streamIds: [pluginMediaTrack.streamId])
rtcSender = self.rtcPeerConnection.add(rtcMediaStreamTrack, streamIds: [pluginMediaStream.id])
trackIdsToSenders[rtcMediaStreamTrack.trackId] = rtcSender;
return true;
}
Expand Down Expand Up @@ -739,13 +739,21 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {

/** New track as been added. */
func peerConnection(_ peerConnection: RTCPeerConnection, didAdd rtpReceiver: RTCRtpReceiver, streams:[RTCMediaStream]) {

NSLog("PluginRTCPeerConnection | onaddtrack")

let track = PluginMediaStreamTrack(rtcMediaStreamTrack: rtpReceiver.track!, streamId: streams[0].streamId)
// TODO why streams.count is 0 and should it trigger addtrack
let streamId : String = streams.count > 0 ? streams[0].streamId : "";
NSLog("PluginRTCPeerConnection | onaddtrack [streamId:%s]", streamId)

self.eventListener([
"type": "addtrack",
"track": track.getJSON()
])
let track = PluginMediaStreamTrack(
rtcMediaStreamTrack: rtpReceiver.track!,
streamId: streamId
)

self.eventListener([
"type": "addtrack",
"track": track.getJSON()
])
}
}
3 changes: 2 additions & 1 deletion src/iosrtcPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ class iosrtcPlugin : CDVPlugin {
}

self.queue.async { [weak pluginRTCPeerConnection, weak pluginMediaStreamTrack] in
if pluginRTCPeerConnection?.addTrack(pluginMediaStreamTrack!) == true {
if pluginRTCPeerConnection?.addTrack(pluginMediaStreamTrack!, pluginMediaStream!) == true {
self.saveMediaStream(pluginMediaStream!)
self.saveMediaStreamTrack(pluginMediaStreamTrack!)
}
}
Expand Down

0 comments on commit ba3900f

Please sign in to comment.