Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement android-rtc with basic Enumerate device SHIM to start #596

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,33 @@ gulp.task('lint', function () {
.pipe(jshint.reporter('fail'));
});


gulp.task('browserify', function () {
return browserify([path.join(__dirname, PKG.main)], {
gulp.task('browserify-ios', function () {
return browserify([path.join(__dirname, 'js/ios/iosrtc.js')], {
standalone: 'iosrtc'
})
.exclude('cordova/exec') // Exclude require('cordova/exec').
.bundle()
.pipe(vinyl_source_stream(PKG.name + '.js'))
.pipe(vinyl_source_stream('cordova-plugin-ios-rtc.js'))
.pipe(vinyl_buffer())
.pipe(header(banner, banner_options))
.pipe(derequire())
.pipe(gulp.dest('www/'));
});


gulp.task('browserify-android', function () {
return browserify([path.join(__dirname, 'js/android/androidrtc.js')], {
standalone: 'androidrtc'
})
.exclude('cordova/exec') // Exclude require('cordova/exec').
.bundle()
.pipe(vinyl_source_stream('cordova-plugin-android-rtc.js'))
.pipe(vinyl_buffer())
.pipe(header(banner, banner_options))
.pipe(derequire())
.pipe(gulp.dest('www/'));
});

gulp.task('browserify', gulp.series('browserify-ios', 'browserify-android'));

gulp.task('default', gulp.series('lint', 'browserify'));
83 changes: 83 additions & 0 deletions js/android/androidrtc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
var exec = require('cordova/exec');
var deviceChangesListenerIsAdded = false;

module.exports = {
getEnumerateDevices: getEnumerateDevices,
};

function getEnumerateDevices(arg0, success, error) {

if(!deviceChangesListenerIsAdded){
console.log("Adding devicechange listener");
addDeviceChangeListener();
exec(success, error, 'EnumerateDevicesPlugin', 'addDeviceListener', [arg0]);
deviceChangesListenerIsAdded = true;
}

var isPromise, callback;
if (typeof arguments[0] !== 'function') {
isPromise = true;
} else {
isPromise = false;
callback = arguments[0];
}

if (isPromise) {
return new Promise(function(resolve) {
function onResultOK(devices) {
console.info('enumerateDevices() | success');
resolve(getMediaDeviceInfos(devices));
}
exec(onResultOK, error, 'EnumerateDevicesPlugin', 'enumerateDevices', [arg0]);
});
}

function onResultOK(devices) {
console.info('enumerateDevices() | success');
callback(getMediaDeviceInfos(devices));
}
exec(onResultOK, error, 'EnumerateDevicesPlugin', 'enumerateDevices', [arg0]);
}

/**
* Private API
*/

function addDeviceChangeListener() {
navigator.mediaDevices.addEventListener('devicechange', navigator.mediaDevices.ondevicechange);
}

function getMediaDeviceInfos(devices) {
console.info('getMediaDeviceInfos() ', devices);

var id,
mediaDeviceInfos = [];

for (id in devices) {
if (devices.hasOwnProperty(id)) {
mediaDeviceInfos.push(mediaDeviceInfo(devices[id]));
}
}

return devices;
}

function mediaDeviceInfo(data) {
data = data || {};

return {
// MediaDeviceInfo spec.
deviceId: {
value: data.deviceId,
},
kind: {
value: data.kind,
},
label: {
value: data.label,
},
groupId: {
value: data.groupId || '',
},
};
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 34 additions & 17 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
<engine name="cordova-ios" version=">=4.5.1" />
</engines>

<platform name="android">

<js-module src="www/cordova-plugin-androidrtc.js" name="Plugin">
<clobbers target="cordova.plugins.androidrtc" />
</js-module>

<config-file parent="/*" target="res/xml/config.xml">
<feature name="EnumerateDevicesPlugin">
<param name="android-package" value="cordova.plugin.android.enumeratedevices.EnumerateDevicesPlugin" />
<param name="onload" value="true" />
</feature>
</config-file>
<config-file parent="/*" target="AndroidManifest.xml"></config-file>
<source-file src="src/android/EnumerateDevicesPlugin.java" target-dir="src/cordova-plugin-android-enumeratedevices/EnumerateDevicesPlugin" />

</platform>

<platform name="ios">

<hook type="after_prepare" src="extra/hooks/iosrtc-swift-support.js" />
Expand Down Expand Up @@ -54,24 +71,24 @@
</js-module>

<!-- Bridging header for using ObjetiveC libraries in Swift -->
<header-file src="src/cordova-plugin-iosrtc-Bridging-Header.h" />
<header-file src="src/ios/cordova-plugin-iosrtc-Bridging-Header.h" />

<!-- Project source files -->
<source-file src="src/iosrtcPlugin.swift" />
<source-file src="src/PluginRTCTypes.swift" />
<source-file src="src/PluginRTCPeerConnection.swift" />
<source-file src="src/PluginRTCPeerConnectionConfig.swift" />
<source-file src="src/PluginRTCPeerConnectionConstraints.swift" />
<source-file src="src/PluginRTCDataChannel.swift" />
<source-file src="src/PluginRTCDTMFSender.swift" />
<source-file src="src/PluginMediaStream.swift" />
<source-file src="src/PluginMediaStreamTrack.swift" />
<source-file src="src/PluginGetUserMedia.swift" />
<source-file src="src/PluginEnumerateDevices.swift" />
<source-file src="src/PluginUtils.swift" />
<source-file src="src/PluginMediaStreamRenderer.swift" />
<source-file src="src/PluginRTCAudioController.swift" />
<source-file src="src/PluginRTCVideoCaptureController.swift" />
<source-file src="src/ios/iosrtcPlugin.swift" />
<source-file src="src/ios/PluginRTCTypes.swift" />
<source-file src="src/ios/PluginRTCPeerConnection.swift" />
<source-file src="src/ios/PluginRTCPeerConnectionConfig.swift" />
<source-file src="src/ios/PluginRTCPeerConnectionConstraints.swift" />
<source-file src="src/ios/PluginRTCDataChannel.swift" />
<source-file src="src/ios/PluginRTCDTMFSender.swift" />
<source-file src="src/ios/PluginMediaStream.swift" />
<source-file src="src/ios/PluginMediaStreamTrack.swift" />
<source-file src="src/ios/PluginGetUserMedia.swift" />
<source-file src="src/ios/PluginEnumerateDevices.swift" />
<source-file src="src/ios/PluginUtils.swift" />
<source-file src="src/ios/PluginMediaStreamRenderer.swift" />
<source-file src="src/ios/PluginRTCAudioController.swift" />
<source-file src="src/ios/PluginRTCVideoCaptureController.swift" />

<!-- iOS shared dependencies -->
<framework src="AVFoundation.framework" />
Expand All @@ -92,7 +109,7 @@
<framework src="VideoToolbox.framework" />

<!-- WebRTC library -->
<framework src="lib/WebRTC.framework" custom="true" embed="true" />
<framework src="lib/ios/WebRTC.framework" custom="true" embed="true" />
</platform>

</plugin>
Loading