Skip to content

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed May 17, 2017
1 parent 27a5968 commit c4e0ea0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### Version 4.0.1

* Let `addIceCandidate()` be called with a `RTCIceCandidateInit` object as argument (as per the latest WebRTC spec) rather than mandating a `RTCIceCandidate` instance.


#### Version 4.0.0

* Moved the repository over to its new home with the Basque VoIP Mafia
Expand Down
116 changes: 70 additions & 46 deletions dist/cordova-plugin-iosrtc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* cordova-plugin-iosrtc v4.0.0
* cordova-plugin-iosrtc v4.0.1
* Cordova iOS plugin exposing the full WebRTC W3C JavaScript APIs
* Copyright 2015-2017 eFace2Face, Inc. (https://eface2face.com)
* Copyright 2017 BasqueVoIPMafia (https://github.com/BasqueVoIPMafia)
Expand Down Expand Up @@ -189,6 +189,10 @@ MediaStream.create = function (dataFromEvent) {
};


MediaStream.prototype.getBlobId = function () {
return this._blobId;
};

MediaStream.prototype.getAudioTracks = function () {
debug('getAudioTracks()');

Expand Down Expand Up @@ -1730,14 +1734,14 @@ RTCPeerConnection.prototype.addIceCandidate = function (candidate) {

debug('addIceCandidate() | [candidate:%o]', candidate);

if (!(candidate instanceof RTCIceCandidate)) {
if (typeof candidate !== 'object') {
if (isPromise) {
return new Promise(function (resolve, reject) {
reject(new global.DOMError('addIceCandidate() must be called with a RTCIceCandidate instance as first argument'));
reject(new global.DOMError('addIceCandidate() must be called with a RTCIceCandidate instance or RTCIceCandidateInit object as argument'));
});
} else {
if (typeof errback === 'function') {
errback(new global.DOMError('addIceCandidate() must be called with a RTCIceCandidate instance as first argument'));
errback(new global.DOMError('addIceCandidate() must be called with a RTCIceCandidate instance or RTCIceCandidateInit object as argument'));
}
return;
}
Expand Down Expand Up @@ -2555,7 +2559,8 @@ module.exports.observeVideo = observeVideo;
/**
* Dependencies.
*/
var debug = _dereq_('debug')('iosrtc:videoElementsHandler'),
var
debug = _dereq_('debug')('iosrtc:videoElementsHandler'),
MediaStreamRenderer = _dereq_('./MediaStreamRenderer'),


Expand All @@ -2581,17 +2586,16 @@ var debug = _dereq_('debug')('iosrtc:videoElementsHandler'),

// Video element mutation observer.
videoObserver = new MutationObserver(function (mutations) {
var i, numMutations, mutation,
video;
var i, numMutations, mutation, video;

for (i = 0, numMutations = mutations.length; i < numMutations; i++) {
mutation = mutations[i];

// HTML video element.
video = mutation.target;

// .src removed.
if (!video.src) {
// .src or .srcObject removed.
if (!video.src && !video.srcObject) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);
continue;
Expand All @@ -2603,7 +2607,8 @@ var debug = _dereq_('debug')('iosrtc:videoElementsHandler'),

// DOM mutation observer.
domObserver = new MutationObserver(function (mutations) {
var i, numMutations, mutation,
var
i, numMutations, mutation,
j, numNodes, node;

for (i = 0, numMutations = mutations.length; i < numMutations; i++) {
Expand Down Expand Up @@ -2673,9 +2678,9 @@ var debug = _dereq_('debug')('iosrtc:videoElementsHandler'),


function videoElementsHandler(_mediaStreams, _mediaStreamRenderers) {
var existingVideos = document.querySelectorAll('video'),
i, len,
video;
var
existingVideos = document.querySelectorAll('video'),
i, len, video;

mediaStreams = _mediaStreams;
mediaStreamRenderers = _mediaStreamRenderers;
Expand Down Expand Up @@ -2715,9 +2720,9 @@ function videoElementsHandler(_mediaStreams, _mediaStreamRenderers) {
function observeVideo(video) {
debug('observeVideo()');

// If the video already has a src property but is not yet handled by the plugin
// If the video already has a src/srcObject property but is not yet handled by the plugin
// then handle it now.
if (video.src && !video._iosrtcMediaStreamRendererId) {
if ((video.src || video.srcObject) && !video._iosrtcMediaStreamRendererId) {
handleVideo(video);
}

Expand All @@ -2740,8 +2745,7 @@ function observeVideo(video) {
characterDataOldValue: false,
// Set to an array of attribute local names (without namespace) if not all attribute mutations
// need to be observed.
// TODO: Add srcObject, mozSrcObject
attributeFilter: ['src']
attributeFilter: ['src', 'srcObject']
});

// Intercept video 'error' events if it's due to the attached MediaStream.
Expand All @@ -2760,49 +2764,69 @@ function observeVideo(video) {
*/

function handleVideo(video) {
var xhr = new XMLHttpRequest();
var
xhr = new XMLHttpRequest(),
stream;

// The app has set video.src.
if (video.src) {
xhr.open('GET', video.src, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status !== 200) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);

xhr.open('GET', video.src, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status !== 200) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);
return;
}

return;
}
var reader = new FileReader();

var reader = new FileReader();
// Some versions of Safari fail to set onloadend property, some others do not react
// on 'loadend' event. Try everything here.
try {
reader.onloadend = onloadend;
} catch (error) {
reader.addEventListener('loadend', onloadend);
}
reader.readAsText(xhr.response);

// Some versions of Safari fail to set onloadend property, some others do not react
// on 'loadend' event. Try everything here.
try {
reader.onloadend = onloadend;
} catch (error) {
reader.addEventListener('loadend', onloadend);
}
reader.readAsText(xhr.response);
function onloadend() {
var mediaStreamBlobId = reader.result;

function onloadend() {
var mediaStreamBlobId = reader.result;
// The retrieved URL does not point to a MediaStream.
if (!mediaStreamBlobId || typeof mediaStreamBlobId !== 'string' || !MEDIASTREAM_ID_REGEXP.test(mediaStreamBlobId)) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);

// The retrieved URL does not point to a MediaStream.
if (!mediaStreamBlobId || typeof mediaStreamBlobId !== 'string' || !MEDIASTREAM_ID_REGEXP.test(mediaStreamBlobId)) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);
return;
}

return;
provideMediaStreamRenderer(video, mediaStreamBlobId);
}
};
xhr.send();
}

provideMediaStreamRenderer(video, mediaStreamBlobId);
// The app has set video.srcObject.
else if (video.srcObject) {
stream = video.srcObject;

if (!stream.getBlobId()) {
// If this video element was previously handling a MediaStreamRenderer, release it.
releaseMediaStreamRenderer(video);

return;
}
};
xhr.send();

provideMediaStreamRenderer(video, stream.getBlobId());
}
}


function provideMediaStreamRenderer(video, mediaStreamBlobId) {
var mediaStream = mediaStreams[mediaStreamBlobId],
var
mediaStream = mediaStreams[mediaStreamBlobId],
mediaStreamRenderer = mediaStreamRenderers[video._iosrtcMediaStreamRendererId];

if (!mediaStream) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-iosrtc",
"version": "4.0.0",
"version": "4.0.1",
"description": "Cordova iOS plugin exposing the full WebRTC W3C JavaScript APIs",
"author": "Iñaki Baz Castillo (https://inakibaz.me)",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-iosrtc"
version="4.0.0">
version="4.0.1">

<name>iosrtc</name>
<description>Cordova iOS plugin exposing the full WebRTC W3C JavaScript APIs</description>
Expand Down

0 comments on commit c4e0ea0

Please sign in to comment.