Skip to content

Commit

Permalink
Update sender parameters state and parse sendEncodings.
Browse files Browse the repository at this point in the history
* Update sender parameters along with transceivers.
* Parse and pass along sendEncodings when doing addTransceiver.
  • Loading branch information
axel-calmid committed Jan 22, 2021
1 parent 4c286a8 commit e6a837d
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 74 deletions.
66 changes: 34 additions & 32 deletions js/RTCDataChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,40 @@ RTCDataChannel.prototype.send = function (data) {
return;
}

if (typeof data === 'string' || data instanceof String) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendString', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (window.ArrayBuffer && data instanceof window.ArrayBuffer) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (
(window.Int8Array && data instanceof window.Int8Array) ||
(window.Uint8Array && data instanceof window.Uint8Array) ||
(window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) ||
(window.Int16Array && data instanceof window.Int16Array) ||
(window.Uint16Array && data instanceof window.Uint16Array) ||
(window.Int32Array && data instanceof window.Int32Array) ||
(window.Uint32Array && data instanceof window.Uint32Array) ||
(window.Float32Array && data instanceof window.Float32Array) ||
(window.Float64Array && data instanceof window.Float64Array) ||
(window.DataView && data instanceof window.DataView)
) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data.buffer
]);
} else {
throw new Error('invalid data type');
}
setImmediate(() => {
if (typeof data === 'string' || data instanceof String) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendString', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (window.ArrayBuffer && data instanceof window.ArrayBuffer) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (
(window.Int8Array && data instanceof window.Int8Array) ||
(window.Uint8Array && data instanceof window.Uint8Array) ||
(window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) ||
(window.Int16Array && data instanceof window.Int16Array) ||
(window.Uint16Array && data instanceof window.Uint16Array) ||
(window.Int32Array && data instanceof window.Int32Array) ||
(window.Uint32Array && data instanceof window.Uint32Array) ||
(window.Float32Array && data instanceof window.Float32Array) ||
(window.Float64Array && data instanceof window.Float64Array) ||
(window.DataView && data instanceof window.DataView)
) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data.buffer
]);
} else {
throw new Error('invalid data type');
}
});
};

RTCDataChannel.prototype.close = function () {
Expand Down
4 changes: 3 additions & 1 deletion js/RTCRtpSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ RTCRtpSender.prototype.replaceTrack = function (withTrack) {
});
};

RTCRtpSender.prototype.update = function ({ track }) {
RTCRtpSender.prototype.update = function ({ track, params }) {
if (track) {
this.track = this._pc.getOrCreateTrack(track);
} else {
this.track = null;
}

this.params = params;
};
39 changes: 38 additions & 1 deletion src/PluginRTCPeerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {
}

func getTransceiversJSON() -> [NSDictionary] {
if (!IsUnifiedPlan()) {
NSLog("PluginRTCPeerConnection#getTransceiversJSON() | transceiers is not available when using plan-b")
return [];
}

return self.rtcPeerConnection.transceivers.map({ (transceiver: RTCRtpTransceiver) -> NSDictionary in
let receiverTrack = self.getPluginMediaStreamTrack(transceiver.receiver.track, trackId: nil);
let senderTrack = self.getPluginMediaStreamTrack(transceiver.sender.track, trackId: nil);
Expand All @@ -722,6 +727,38 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {

var currentDirection = RTCRtpTransceiverDirection.inactive
transceiver.currentDirection(&currentDirection)


let senderParameters = transceiver.sender.parameters;
let senderParamsJSON = [
"rtcp": [
"cname": senderParameters.rtcp.cname,
"reducedSize": senderParameters.rtcp.isReducedSize
],
"headerExtensions": senderParameters.headerExtensions.map({ (headerExtension: RTCRtpHeaderExtension) -> Int32 in
return headerExtension.id
}),
"codecs": senderParameters.codecs.map({ (codec: RTCRtpCodecParameters) -> NSDictionary in
return [
"payloadType": codec.payloadType,
"mimeType": NSString(format: "%@/%@", codec.name, codec.kind),
"clockRate": (codec.clockRate ?? nil) as Any,
"channels": (codec.numChannels ?? nil) as Any,
"sdpFmtpLine": codec.parameters
]
}),
"encodings": senderParameters.encodings.map({ (encoding: RTCRtpEncodingParameters) -> NSDictionary in
return [
"rid": encoding.rid as Any,
"active": encoding.isActive,
"maxBitrate": encoding.maxBitrateBps as Any,
"maxFramerate": encoding.maxFramerate as Any,
"scaleResolutionDownBy": encoding.scaleResolutionDownBy as Any

]
})

] as NSDictionary

return [
"id": transceiverHolder.id,
Expand All @@ -730,7 +767,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate {
"direction": PluginRTCRtpTransceiver.directionToString(transceiver.direction),
"stopped": transceiver.isStopped,
"receiver": [ "track": receiverTrack!.getJSON() ],
"sender": [ "track": senderTrack?.getJSON() ]
"sender": [ "track": senderTrack?.getJSON(), "params": senderParamsJSON ]
]
})
}
Expand Down
12 changes: 10 additions & 2 deletions src/PluginRTCRtpTransceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ class PluginRTCRtpTransceiver : NSObject {
rtcRtpTransceiverInit.streamIds = streamIds
}

// TODO: Implement sendEncodings configuration
if options?.object(forKey: "sendEncodings") != nil {
NSLog("iosrtcPlugin#RTCPeerConnection_addTransceiver() | ERROR: init.sendEncodings not supported yet")
let encodings = options!.object(forKey: "sendEncodings") as! [NSDictionary]
rtcRtpTransceiverInit.sendEncodings = encodings.map({ (encoding: NSDictionary) -> RTCRtpEncodingParameters in
let encodingParameters = RTCRtpEncodingParameters()
encodingParameters.isActive = encoding["active"] as? Bool ?? true
encodingParameters.maxBitrateBps = encoding["maxBitrate"] as? NSNumber
encodingParameters.maxFramerate = encoding["maxFramerate"] as? NSNumber
encodingParameters.rid = encoding["rid"] as? String
encodingParameters.scaleResolutionDownBy = encoding["scaleResolutionDownBy"] as? NSNumber
return encodingParameters
})
}

return rtcRtpTransceiverInit
Expand Down
161 changes: 123 additions & 38 deletions www/cordova-plugin-iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ EventTarget.prototype.dispatchEvent = function (event) {
*/
module.exports = EventTarget;

},{"yaeti":30}],3:[function(_dereq_,module,exports){
},{"yaeti":31}],3:[function(_dereq_,module,exports){
/**
* Expose the MediaDeviceInfo class.
*/
Expand Down Expand Up @@ -1445,6 +1445,7 @@ function onEvent(data) {
}

},{"./EventTarget":2,"cordova/exec":undefined,"debug":24,"random-number":29}],11:[function(_dereq_,module,exports){
(function (setImmediate){
/**
* Expose the RTCDataChannel class.
*/
Expand Down Expand Up @@ -1588,38 +1589,40 @@ RTCDataChannel.prototype.send = function (data) {
return;
}

if (typeof data === 'string' || data instanceof String) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendString', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (window.ArrayBuffer && data instanceof window.ArrayBuffer) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (
(window.Int8Array && data instanceof window.Int8Array) ||
(window.Uint8Array && data instanceof window.Uint8Array) ||
(window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) ||
(window.Int16Array && data instanceof window.Int16Array) ||
(window.Uint16Array && data instanceof window.Uint16Array) ||
(window.Int32Array && data instanceof window.Int32Array) ||
(window.Uint32Array && data instanceof window.Uint32Array) ||
(window.Float32Array && data instanceof window.Float32Array) ||
(window.Float64Array && data instanceof window.Float64Array) ||
(window.DataView && data instanceof window.DataView)
) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data.buffer
]);
} else {
throw new Error('invalid data type');
}
setImmediate(() => {
if (typeof data === 'string' || data instanceof String) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendString', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (window.ArrayBuffer && data instanceof window.ArrayBuffer) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data
]);
} else if (
(window.Int8Array && data instanceof window.Int8Array) ||
(window.Uint8Array && data instanceof window.Uint8Array) ||
(window.Uint8ClampedArray && data instanceof window.Uint8ClampedArray) ||
(window.Int16Array && data instanceof window.Int16Array) ||
(window.Uint16Array && data instanceof window.Uint16Array) ||
(window.Int32Array && data instanceof window.Int32Array) ||
(window.Uint32Array && data instanceof window.Uint32Array) ||
(window.Float32Array && data instanceof window.Float32Array) ||
(window.Float64Array && data instanceof window.Float64Array) ||
(window.DataView && data instanceof window.DataView)
) {
exec(null, null, 'iosrtcPlugin', 'RTCPeerConnection_RTCDataChannel_sendBinary', [
this.peerConnection.pcId,
this.dcId,
data.buffer
]);
} else {
throw new Error('invalid data type');
}
});
};

RTCDataChannel.prototype.close = function () {
Expand Down Expand Up @@ -1707,7 +1710,8 @@ function onEvent(data) {
}
}

},{"./EventTarget":2,"cordova/exec":undefined,"debug":24,"random-number":29}],12:[function(_dereq_,module,exports){
}).call(this,_dereq_("timers").setImmediate)
},{"./EventTarget":2,"cordova/exec":undefined,"debug":24,"random-number":29,"timers":30}],12:[function(_dereq_,module,exports){
/**
* Expose the RTCIceCandidate class.
*/
Expand Down Expand Up @@ -2508,7 +2512,7 @@ RTCPeerConnection.prototype.addTransceiver = function (trackOrKind, init) {
track
});

var data = init;
var data = init || {};
data.sender = sender;
data.receiver = receiver;

Expand Down Expand Up @@ -2922,12 +2926,14 @@ RTCRtpSender.prototype.replaceTrack = function (withTrack) {
});
};

RTCRtpSender.prototype.update = function ({ track }) {
RTCRtpSender.prototype.update = function ({ track, params }) {
if (track) {
this.track = this._pc.getOrCreateTrack(track);
} else {
this.track = null;
}

this.params = params;
};

},{}],16:[function(_dereq_,module,exports){
Expand Down Expand Up @@ -5226,13 +5232,92 @@ void function(root){
}(this)

},{}],30:[function(_dereq_,module,exports){
(function (setImmediate,clearImmediate){
var nextTick = _dereq_('process/browser.js').nextTick;
var apply = Function.prototype.apply;
var slice = Array.prototype.slice;
var immediateIds = {};
var nextImmediateId = 0;

// DOM APIs, for completeness

exports.setTimeout = function() {
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
};
exports.setInterval = function() {
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
};
exports.clearTimeout =
exports.clearInterval = function(timeout) { timeout.close(); };

function Timeout(id, clearFn) {
this._id = id;
this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
Timeout.prototype.close = function() {
this._clearFn.call(window, this._id);
};

// Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = msecs;
};

exports.unenroll = function(item) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = -1;
};

exports._unrefActive = exports.active = function(item) {
clearTimeout(item._idleTimeoutId);

var msecs = item._idleTimeout;
if (msecs >= 0) {
item._idleTimeoutId = setTimeout(function onTimeout() {
if (item._onTimeout)
item._onTimeout();
}, msecs);
}
};

// That's not how node.js implements it but the exposed api is the same.
exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
var id = nextImmediateId++;
var args = arguments.length < 2 ? false : slice.call(arguments, 1);

immediateIds[id] = true;

nextTick(function onNextTick() {
if (immediateIds[id]) {
// fn.call() is faster so we optimize for the common use-case
// @see http://jsperf.com/call-apply-segu
if (args) {
fn.apply(null, args);
} else {
fn.call(null);
}
// Prevent ids from leaking
exports.clearImmediate(id);
}
});

return id;
};

exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
delete immediateIds[id];
};
}).call(this,_dereq_("timers").setImmediate,_dereq_("timers").clearImmediate)
},{"process/browser.js":28,"timers":30}],31:[function(_dereq_,module,exports){
module.exports =
{
EventTarget : _dereq_('./lib/EventTarget'),
Event : _dereq_('./lib/Event')
};

},{"./lib/Event":31,"./lib/EventTarget":32}],31:[function(_dereq_,module,exports){
},{"./lib/Event":32,"./lib/EventTarget":33}],32:[function(_dereq_,module,exports){
(function (global){
/**
* In browsers export the native Event interface.
Expand All @@ -5241,7 +5326,7 @@ module.exports =
module.exports = global.Event;

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],32:[function(_dereq_,module,exports){
},{}],33:[function(_dereq_,module,exports){
function yaetiEventTarget()
{
this._listeners = {};
Expand Down

0 comments on commit e6a837d

Please sign in to comment.