getUserMedia fails with TrackStartError when allowing accessing to microphone - javascript

I am using Chrome Version 35.0.1916.114 m
When I run my html page using IIS (e.g., localhost/test.html) and hit "Allow" to the http://localhost/ wants to use your microphone prompt, getUserMedia() fails with the following error:
NavigatorUserMediaError {constraintName: "", message: "", name: "TrackStartError"}
Code:
var constraints = {audio: true, video: false};
...
function successCallback(stream) {
...
}
function errorCallback(error){
console.log("navigator.getUserMedia error: ", error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
What could be the cause of this error?

var mediaConstraints =
{
'mandatory' :
{
'OfferToReceiveAudio' : true,
'OfferToReceiveVideo' : false
}
};
declare this in your code before using constraints.

Related

AbortError - Screen Sharing using WebRTC

I am trying to implement Screen sharing functionality using webrtc. In firefox it is working, but in chrome it showing "Abort Error"
var constraints = {
video: {
mandatory: {
chromeMediaSource: 'screen'
},
optional: []
},
audio: true,
};
if(navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia(constraints).then(getUserMediaSuccess).catch(errorHandler);
} else {
alert('Your browser does not support getUserMedia API');
}
console error:
{name: "AbortError", message: "Error starting screen capture", constraint: undefined, toString: ƒ}
here you are trying to access 'getUserMedia' and your target is 'screen'.
Solution:
So you need to make use of 'getDisplayMedia'
And your constraints will be like:
var constraints = {
video: true,
audio: true,
};
Try this.
This will solve your problem.

BrowserStack + Nightwatch.js How to set up proxy which is password protected (ERROR: httpProxy was not of the form host[:port]

BrowserStack + Nightwatch.js How to set up proxy which is password protected
common_capabilities: {
'browserstack.user': 'user',
'browserstack.key': 'key',
'browserstack.debug': true,
},
test_settings: {
default: {
desiredCapabilities: {
'os': 'OS X',
'os_version': 'Sierra',
'browser': 'Firefox',
'browser_version': '53.0',
'resolution': '1280x960',
"acceptSslCerts": 'false',
'proxy': {
'httpProxy': 'user:password#server:80',
'protocol': 'http',
'proxyType': 'manual',
//'httpProxy': 'server:80',
//'user': 'user',
//'pass': 'password'
}
},
I have en ERROR:
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
message: 'Could not start Browser / Emulator
Reason: httpProxy was not of the form host[:port]
BrowserStack Support asked me to provide my solution based on the specifics of my setup:
I had to use BrowserStack.local
  "scripts": {
   "test": "./bin/BrowserStackLocal --key ACCESS_KEY --local-proxy-host PROXY_HOST --local-proxy-port PROXY_PORT --local-proxy-user PROXY_USER --local-proxy-pass PROXY_PASS --local-identifier Test123 & ./node_modules/nightwatch/bin/nightwatch -c conf/local.conf.js tests",
   "local": "./bin/BrowserStackLocal --key ACCESS_KEY --local-identifier Test123 && ./node_modules/nightwatch/bin/nightwatch -c conf/local.conf.js tests",
   "nightwatch": "./node_modules/nightwatch/bin/nightwatch -c conf/local.conf.js tests"
  },
1st step: launching BrowserStackLocal through Proxy (in one Terminal's window
2nd step: run tests in "tests" folder
I found the better solution, using nightwatch-browserstack
and customize local.runner.js:
#!/usr/bin/env node
process.env.NODE_ENV = 'testing';
const access = require('../conf/browserStackAccess.js').access; //{'USERNAME':'', 'ACCESS_KEY': ''}
const bsLocalOptions = {
'key': access.ACCESS_KEY,
'local-proxy-host': PROXY_HOST,
'local-proxy-port': PROXY_PORT,
'local-proxy-user': PROXY_USER,
'local-proxy-pass': ROXY_PASS,
'local-identifier': LOCAL_ID //'Test123'
}
var Nightwatch = require('nightwatch');
var browserstack = require('browserstack-local');
var bs_local;
try {
process.mainModule.filename = "./node_modules/nightwatch/bin/nightwatch"
// Code to start browserstack local before start of test
console.log("Connecting local");
Nightwatch.bs_local = bs_local = new browserstack.Local();
bs_local.start(bsLocalOptions, function (error) {
if (error) throw error;
console.log('Connected. Now testing...');
Nightwatch.cli(function (argv) {
Nightwatch.CliRunner(argv)
.setup(null, function () {
// Code to stop browserstack local after end of parallel test
bs_local.stop(function () { });
})
.runTests(function () {
// Code to stop browserstack local after end of single test
bs_local.stop(function () { });
});
});
});
} catch (ex) {
console.log('There was an error while starting the test runner:\n\n');
process.stderr.write(ex.stack + '\n');
process.exit(2);
}

Handle Push notification in Nativescript

I am working on application in Nativescript which implements push notification. Lets say server sends push notification and based on action mentioned in payload of notification i will have to redirect in application. This redirection should be performed if user taps on notification from drawer and application is in background. Other case when application should not redirect if its in foreground. I have managed a flag for that as follow
app.js
application.on(application.launchEvent, function (args) {
appSettings.setBoolean('AppForground', true);
});
application.on(application.suspendEvent, function (args) {
appSettings.setBoolean('AppForground', false);
});
application.on(application.resumeEvent, function (args) {
appSettings.setBoolean('AppForground', true);
});
application.on(application.exitEvent, function (args) {
appSettings.setBoolean('AppForground', false);
});
application.on(application.lowMemoryEvent, function (args) {
appSettings.setBoolean('AppForground', false);
});
application.on(application.uncaughtErrorEvent, function (args) {
appSettings.setBoolean('AppForground', false);
});
And on Push notification listener
var settings = {
// Android settings
senderID: '1234567890', // Android: Required setting with the sender/project number
notificationCallbackAndroid: function(data, pushNotificationObject) { // Android: Callback to invoke when a new push is received.
var payload = JSON.parse(JSON.parse(pushNotificationObject).data);
if (appSettings.getBoolean('AppForground') == false){
switch (payload.action) {
case "APPOINTMENT_DETAIL":
frame.topmost().navigate({
moduleName: views.appointmentDetails,
context: {
id: payload.id
}
});
break;
case "MESSAGE":
frame.topmost().navigate({
moduleName: views.appointmentDetails,
context: {
id: payload.id,
from: "messages"
}
});
break;
case "REFERENCES":
frame.topmost().navigate({
moduleName: views.clientDetails,
context: {
id: payload.id,
name: ""
}
});
break;
default:
}
}
},
// iOS settings
badge: true, // Enable setting badge through Push Notification
sound: true, // Enable playing a sound
alert: true, // Enable creating a alert
// Callback to invoke, when a push is received on iOS
notificationCallbackIOS: function(message) {
alert(JSON.stringify(message));
}
};
pushPlugin.register(settings,
// Success callback
function(token) {
// if we're on android device we have the onMessageReceived function to subscribe
// for push notifications
if(pushPlugin.onMessageReceived) {
pushPlugin.onMessageReceived(settings.notificationCallbackAndroid);
}
},
// Error Callback
function(error) {
alert(error);
}
);
Now the problem, is that if application is in killed state and notification arrives. Then it sets flag to true as application is launched which it should not. So due to that redirection is not performed and in other cases when application is in foreground state then also its navigating through pages (which should not be) on receiving notification.
I doubt about flag management is causing the problem but not sure. Would you please guide me if anything is wrong with what i did ?
UPDATE
I am using push-plugin.
Thanks.
I use this for notifications
https://github.com/EddyVerbruggen/nativescript-plugin-firebase
This plugin use FCM, it adds to datas received from notifications foreground parameter so from payload you can determine if app was background(foreground==false, app is not active or was started after notification arrived) or foreground(foreground==true, app is open and active), but you need to some changes to code as they are different plugins
You can use pusher-nativescript npm module.
import { Pusher } from 'pusher-nativescript';
/*Observation using the above.
- Project gets build successfully.
- on run -> ERROR TypeError: pusher_nativescript__WEBPACK_IMPORTED_MODULE_6__.Pusher is not a constructor
- Use: import * as Pusher from 'pusher-nativescript';
- Make sure to install nativescript-websocket with this package.
*/
var pusher = new Pusher('Your_app_key', { cluster: 'your_cluster_name' });
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(JSON.stringify(data));
});

How to report angular pending requests on protractor timeouts?

I've been working on some protractor tests lately and from time to time some of my tests randomly fail with the following error:
DEBUG - WebDriver session successfully started with capabilities { caps_:
{ platform: 'LINUX',
acceptSslCerts: true,
javascriptEnabled: true,
browserName: 'chrome',
chrome: { userDataDir: '/tmp/.com.google.Chrome.czw4dR' },
rotatable: false,
locationContextEnabled: true,
mobileEmulationEnabled: false,
'webdriver.remote.sessionid': '3afc09d9-d06d-4c99-a788-d1118093c08d',
version: '40.0.2214.111',
takesHeapSnapshot: true,
cssSelectorsEnabled: true,
databaseEnabled: false,
handlesAlerts: true,
browserConnectionEnabled: false,
nativeEvents: true,
webStorageEnabled: true,
applicationCacheEnabled: false,
takesScreenshot: true } }
Started
token: a62e88d34991f4eef0894102e004e92032857700
.F...........................
Failures:
1) login form filled should fail on wrong credentials
Message:
Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
Looking at protractor documentation this error usually happens when there are pending $http requests or i'm using $timeout for something. I've tried setting a longer timeout for my tests(minutes) but it hasn't helped. My latest idea has been to report what requests are pending so i made the following Jasmine Reporter:
var AngulaRequestsReporter = function(dir){
dir = (dir || '/tmp/protractors/');
this.requests = function(testDescription) {
var fname = testDescription.replace(/\s/g, '_') + '.pending_requests';
mkdirp(dir);
browser.executeScript(function(){
try{
var $http = angular.injector(["ng"]).get("$http");
return $http.pendingRequests;
}catch(e){
return [];
}
}).then(function(pendingRequests){
var stream = fs.createWriteStream(path.join(dir, fname));
stream.write(util.inspect(pendingRequests, {showHidden: false, depth: null}));
stream.end();
});
};
return this;
};
// takes screenshot on each failed spec (including timeout)
AngulaRequestsReporter.prototype = {
specDone: function(result) {
if (result.status !== 'passed') {
this.requests(result.description );
}
}
};
However the result is always an empty []. Have you guys had this problem before and if so how did you solve it? Also, is there anything i can make to improve this reporter?

Getting NavigatorUserMediaError while using chromeMediaSource: "desktop"

I have created a DesktopCapture extension for chrome to get chromeMediaSourceId for desktop capture.
The extension returns the chromeMediaSourceId successfully to the main html page when i run it on the localhost.
Here is what i am getting in the constrains :
{
"audio":false,
"video":{
"mandatory":{
"chromeMediaSource":"desktop",
"maxWidth":1920,"maxHeight":1080,
"chromeMediaSourceId":"ouIW7wIZYullGDpZid/S2w=="
},
"optional":[]
}
}
But when i call
navigator.webkitGetUserMedia(screen_constraints, function (stream) {
document.querySelector('video').src = URL.createObjectURL(stream);
}, function (error) {
console.log(error);
});
I am getting the following error
NavigatorUserMediaError {constraintName: "", message: "", name: "InvalidStateError"}
The only thing that looks odd to me is
{
"audio":false,
"video":{
"mandatory":{
"chromeMediaSource":"desktop",
"maxWidth":1920,"maxHeight":1080,
"chromeMediaSourceId":"ouIW7wIZYullGDpZid/S2w=="
},
"optional":[]
}
}
should be
{
audio:false,
video:{
mandatory:{
chromeMediaSource:"desktop",
maxWidth:1920,maxHeight:1080,
chromeMediaSourceId:"ouIW7wIZYullGDpZid/S2w=="
},
optional:[]
}
}
The difference being that audio, false, video, chromeMediaSource, ... should not be in quotes.

Categories

Resources