Websocket on Android 4.4 with Phonegap - javascript

I'm working on an app which needs Websocket to communicate with my server. I'm working with Phonegap so I can run all the code first of all in my browser.
Since Android 4.4 Websockets got native support in Android so it should work...
I've implemented the Websocket with this code:
$(document).ready(function () {
console.log('websocketready');
startwebsocket();
});
var ws;
function startwebsocket() {
ws = new WebSocket('ws://192.168.1.131:8080/.....');
ws.onopen = function () {
console.log("Websocket Ready!!");
}
ws.onclose = function () {
console.log("Websocket Closed!!");
}
ws.onerror = function () {
console.log("Websocket Error!!");
}
ws.onmessage = function (data) {
console.log('getvalue : ' + data.data);
}
}
function sendMessage(temp) {
ws.send(temp);
}
This is just working fine in my browser (Chrome and firefox). But if I start the app with Phonegap on my Nexus 5 with android 4.4.2 I'm getting : 'WebSocket connection to 'ws://192.168.1.131:8080/.....' failed: Unexpected response code: 403'
Do you have any suggestions what I could have missed to do or what I did wrong?

Do you provide 192.168.1.131 as authorised origin to cordova ?
Maybe you should try to add that to your config.xml :
<access origin="192.168.1.131" />
Take a look here for more informations.
Hope that help :)

Related

Why web push not work from iframe in chrome with both load through https?

Web push works fine from iframe in local but when i uploaded to cloud server then it does not work in only chrome or chromium browser.
I have developed a webpush micro-service that serve from a Iframe. That works fine in local but when i uploaded to cloud server then it does not work in only chrome or chromium browser. You can check from https:alemran.me (click ^ icon from bot).
Web Worker:
self.addEventListener('push', function (event) {
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
const sendNotification = (title, body ) => {
return self.registration.showNotification(title,
body
);
};
if (event.data) {
const message = JSON.parse(event.data.text());
event.waitUntil(sendNotification(message.title,message.message));
}
});
There is no error show in console
You can open a new window with a url and get permission from user....
Like :
let win = window.open("your url", "_blank");
let winInterval = window.setInterval(function() {
if (win.closed !== false) {
window.clearInterval(winInterval );
//check your api for user subscription status
}
}, 200);

How to launch javascript universal windows application from another UWP app in windows IoT?

My requirement is to launch UWP app from another UWP app.And i made it but its working in windows 10 desktop system not on Windows IoT OS,Kindly help me to fix this.
$(document).on('click', '.openTAT', function () {
var testAppUri = new Windows.Foundation.Uri("test-app2app:");
var options = new Windows.System.LauncherOptions();
options.TargetApplicationPackageFamilyName = "TATApp_ehke6zp0mbebr";
Windows.System.Launcher.launchUriAsync(testAppUri, options).then(
function (success) {
if (success) {
// URI launched
x = "success";
$("#errorLabel").html("success");
} else {
x = "failed";
$("#errorLabel").html("failed");
// URI launch failed
}
});
});

Meteor DOMException: Unable to decode audio data

EDIT : I just created a new Meteor Project and it worked :D wow.But it still doesnt work on my core project..looks like i have different settings.
In my Meteor.js project i have 4 .mp3-files located in public/sounds/xyz.mp3.
I load these .mp3 with :
let soundRequest = new XMLHttpRequest();
soundRequest.open('GET', this._soundPath, true);
soundRequest.responseType = 'arraybuffer';
let $this = this;
soundRequest.onload = function () {
Core.getAudioContext().decodeAudioData(soundRequest.response, function (buffer) {
$this.source.buffer = buffer;
$this.source.loop = true;
$this.source.connect($this.panner);
});
};
soundRequest.send();
This WORKS on google Chrome, but when i build the app via meteor run android-device, i get the following error message : DOMException: Unable to decode audio data
I wonder if this is a bug because loading .png or .jpg works just fine in the mobile version. I have not installed any packages beside meteor add crosswalk but deinstalling this doesnt help either.
You shouldn't need to do a http request to get a local resource. You can just refer to a local url. On the Android device the path is different. See this code:
function getSound(file) {
var sound = "/sounds/"+file;
if (Meteor.isCordova) {
var s;
if (device.platform.toLowerCase() === "android") {
sfile = cordova.file.applicationDirectory.replace('file://', '') + 'www/application/app' + sound;
}
else {
sfile = cordova.file.applicationDirectory.replace('file://', '') + sound;
}
var s = new Media(
sfile,
function (success) {
console.log("Got sound "+file+" ok ("+sfile+")");
s.play();
},
function (err) {
console.log("Get sound "+file+" ("+sfile+") failed: "+err);
}
);
} else {
var a = new Audio(sound);
a.play();
}
}
On a device it loads the sound file asynchronously and then plays it. In the browser it just loads and plays it synchronously.
This web API is not supported on android device but works on chrome browser of android
Check browser specification in this link
https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/decodeAudioData

Cordova Camera access crash app on Nexus 7 with Android 6.0.1

Using Cordova 6.3.1, I installed the following Crodova plugins:
cordova-plugin-camera, cordova.plugins.diagnostic, phonegap-plugin-barcodescanner
I'm using the following JavaScript code to access the Camera and scan a QR code:
function scanQR() {
cordova.plugins.diagnostic.requestCameraAuthorization(function(status) {
console.log("Authorization request for camera returned " + status);
if (status == cordova.plugins.diagnostic.permissionStatus.GRANTED) {
try {
cordova.plugins.barcodeScanner.scan(scanQRDone, function (error) {
console.log(error);
});
} catch (e) {
console.log(e.message);
}
}
}, function (error) {
console.log(error);
});
}
function scanQRDone(result) {
console.log(result);
}
The requestCameraAuthorization call prompts for a confirmation on the device and when allowed returns status GRANTED.
However the call to cordova.plugins.barcodeScanner.scan simply crashes the application on the Nexus 7.
The actual line in which the crash occurs is cordova.js line 940:
var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
Where service="BarcodeScanner" and action="scan"
Seems like some kind of version mismatch in native code, any ideas are welcomed.
Creating a new ionic application from scratch and copying the content of the www folder into it has resolved the problem.
in the file config.xml add this
< platform name="android" > <br>
< preference name="android-targetSdkVersion" value="23" /> <br>
< /platform>

Cannot record audio with Cordova Media plugin on Windows (Phone) 8.1

I'm trying to create an app that allows the user to record audio. I'm using the cordova-plugin-media for this.
Using the sample from the documentation I can record sound on iOS (specifying a *.wav file), Android (*.amr), Windows Phone 8 (*.aac), but Windows Phone 8.1 doesn't work. I've tried it with *.mp3, *.wma, and *.m4a, but in every case I get this error:
No suitable transform was found to encode or decode the content.
Here's part of the code:
var that = this;
try {
this._media = new Media('recording.mp3', function () {
that._log('Audio success');
}, function (e) {
that._log('Error: ' + e.code + ': ' + e.message);
});
// Bind buttons
document.querySelector('#recordStart').addEventListener('click', function () {
// Record
that._log('Recording...');
that._media.startRecord();
});
document.querySelector('#recordStop').addEventListener('click', function () {
that._log('Recording stopped');
that._media.stopRecord();
});
}
catch (e) {
this._log('An error occurred!');
this._log(e.message);
}

Categories

Resources