Implementation of JsSIP on actual phone - javascript

I just took a look JsSIP library, and it seems pretty promising except the fact that it has no actual demonstration or code which implements calling actual mobile phone. so is it actually possible to call phone which is in offline mode or in online? here is code on docs
var ua = new JsSIP.UA(configuration);
ua.start();
// Register callbacks to desired call events
var eventHandlers = {
'progress': function(e) {
console.log('call is in progress');
},
'failed': function(e) {
console.log('call failed with cause: '+ e.data.cause);
},
'ended': function(e) {
console.log('call ended with cause: '+ e.data.cause);
},
'confirmed': function(e) {
console.log('call confirmed');
}
};
var options = {
'eventHandlers' : eventHandlers,
'mediaConstraints' : { 'audio': true, 'video': true }
};
var session = ua.call('sip:bob#example.com', options);
even demo is implementing call within browsers, which is more easily done with WebRTC but i want to call phone. how is that possible, if it is possible in OFFLINE mode it would be better

You need first to look for a PSTN provider that provides you with a SIP account to make calls to phone numbers. That's not free typically. Then you probably want to configure such a SIP account in your SIP server and router calls from JsSIP to the PSTN provider. And deal with accounting and so on. Not something trivial.

Related

Can't get localhost mode to work in split.io

According to the documentation on split.io I should be able to create a Split client in 'localhost' mode, i.e. it will work offline. Here is the link: https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#localhost-mode
But nothing happens when I run this code:
// Import the SDK
var SplitFactory = require("#splitsoftware/splitio").SplitFactory;
// Instantiate the SDK
var factory = SplitFactory({
core: {
authorizationKey: "localhost",
},
features: {
"my-feature": "on",
},
});
// Get the client instance you'll use
var client = factory.client();
console.log("created the client");
// Set a callback to listen for the SDK_READY event, to make sure the SDK is properly loaded before asking for a treatment
client.on(client.Event.SDK_READY, function () {
console.log("SDK_READY");
var treatment = client.getTreatment("CUSTOMER_ID", "my-feature");
console.log(treatment);
});
client.on(client.Event.SDK_UPDATE, () => {
console.log("SDK_UPDATE");
});
client.once(client.Event.SDK_READY_TIMED_OUT, () => {
console.log("SDK_READY_TIMED_OUT");
});
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
console.log("SDK_READY_FROM_CACHE");
});
"created the client" is logged but then nothing after that. How do I get SDK_READY to fire? It works fine if I give it a real API key.
I also put the code in a github project: https://github.com/philipbeber/splitlocalhost
It turns out that the Split SDK behaves differently if you are running from nodejs rather than in the browser. So if you use jest with its default settings then you need to reference different docs: https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK
There is no way to force the Split module to "client mode" which is infuriating.

How to set playback rate from chrome browser?

This one if probably for chromecast API devs.
Android and iOS have a setPlaybackRate method, but the Chrome Sender API doesn't appear to have an equivalent feature.
Is there a javascript method to do this besides using sendMessage?
If not, please consider this a feature request! :D
I know you've long since moved on from this problem, but here is what got me rolling on this, and yours was the only question I found about it.
playerTarget.setHalfSpeed = function (){
var media = castSession.getMediaSession();
castSession.sendMessage("urn:x-cast:com.google.cast.media",{
type: "SET_PLAYBACK_RATE",
playbackRate: 0.5,
mediaSessionId: media.mediaSessionId,
requestId: 2
}).then(
function (a) { console.log('Set playback rate success'); },
function (errorCode) {
console.log('Set playback rate error: ' + errorCode);
});
}.bind(this);

how to detect the mobile connection is 2G/3G/WIFI using javascript

i have a similar requirement as in link below but i have to handle it by using JavaScript. where i have to detect whether the mobile internet connection is 2g/3g or it is WIFI . based on connection i have to perform diffent operations..
note : mobile can b of any OS like andriod/ iOS/BB .. i need to handle any mobile OS.
Is there a way to detect what kind of connection I'm using ? WiFi, 3G or Ethernet?
request masters to help me with inputs. thanks :)
Network Information API (This is an experimental technology):
The Network Information API provides information about the system's
connection, which is in term of general connection type (e.g., 'wifi',
'cellular', etc.). This can be used to select high definition content
or low definition content based on the user's connection. The entire
API consists of the addition of the domxref("NetworkInformation")
interface and a single property to the Navigator interface:
Navigator.connection.
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
var type = connection.type;
function updateConnectionStatus() {
alert("Connection type is change from " + type + " to " + connection.type);
}
connection.addEventListener('typechange', updateConnectionStatus);
I wrote a small utility to do this. You can try it here
http://ashanbh.github.io/detectClientSpeed/example2.html
and fork it on github: https://github.com/ashanbh/detectClientSpeed
Usage:
<script src="scripts/require.js"></script>
<script>
requirejs(['scripts/detectSpeed'], function (detectSpeed) {
//Callback to receive timing information
var callback = function (timings) {
console.log(timings);
}
detectSpeed.startSpeedCheck("https://s3-us-west-1.amazonaws.com/amit.shanbhag/3g/coffee-apple-iphone-laptop.jpg", callback);
});
</script>

OpenTok accessDenied issue in Chrome

I'm having some trouble with the OpenTok 2 API. When I start to publish a stream and I'm prompted to allow or deny the website to use my webcam and microphone, if I allow allowed() should run, but if I deny denied() should run.
publisher.addEventListener('accessAllowed', allowed);
publisher.addEventListener('accessDenied', denied);
function allowed() {
console.log('Allowed');
}
function denied() {
console.log('Denied');
}
It works as expected in Firefox. In Chrome accessAllowed works, however, accessDenied doesn't. Instead I get the following error:
OT.Publisher.onStreamAvailableError PermissionDeniedError:
TB.exception :: title: Internal Error (2000) msg: Publisher failed to access camera/mic:
Any ideas?
This is a bug in the current JS library at OpenTok. I do have a workaround that should get you going and I'll come back with an update when the bug is fixed.
var waiting = false;
publisher.addEventListener('accessAllowed', function() {
waiting = false;
allowed();
});
publisher.addEventListener('accessDenied', function() {
waiting = false;
denied();
});
publisher.addEventListener('accessDialogOpened', function() {
waiting = true;
});
publisher.addEventListener('accessDialogClosed', function() {
setTimeout(function() {
if (waiting) {
waiting = false;
denied();
}
}, 0);
});
This workaround is slightly limited because Chrome has some weirdness when it comes to denying access once and then visiting the page again. If the user hasn't changed his/her preferences regarding the media permissions, the video will continue to be denied and the 'accessDialogOpened' won't even fire. I'll inform the team and continue to look into this.

How to know if the network is (dis)connected?

How can I know, in Xul, if the network is (dis)connected?
--update
Using:
function observe(aSubject, aTopic, aState) {
if (aTopic == "network:offline-status-changed") {
write("STATUS CHANGED!");
}
}
var os = Components.classes["#mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
os.addObserver(observe, "network:offline-status-changed", false);
and the preference:
pref("network.manage-offline-status", true);
it's not working.. There's a bug report here, but I don't think it has something to do with it.
--
Actually I think it's not possible to be notified, as even in Firefox we're never notified, and the user need to manually mark "work offline" if he wants the browser to know that it's offline..
--
Screenshot my of Firefox "about:config" filtering for "offline" string, unfortunately, there no "network.manage-offline-status":
You should be able to use navigator.onLine. Here is the help page
https://developer.mozilla.org/en/Online_and_offline_events
navigator.onLine is a property that
maintains a true/false value (true for
online, false for offline). This
property is updated whenever the user
switches into "Offline Mode" by
selecting the corresponding menu item
(File -> Work Offline in Firefox).
Another solution (as commented by #Neil):
Components.classes["#mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService)
.addObserver(myF­unction, "network:offline-status-changed", false);
The best way I found is to use the following javascript code, that behaves like a ping, and make the test with some big websites, and assume that if none of them answers, so the network must be disconnected.
var ping = {};
ping = {
img:null,
imgPreload:null,
timer:null,
init:function() {
var sess = new Date();
var nocache = sess.getTime();
var imguri = ping.img+"?time="+nocache;
var ping.imgPreload = new Image();
ping.imgPreload.onload = function() {
clearTimeout(ping.timer);
ping.timer = null;
alert("Domain is available");
};
ping.imgPreload.src = imguri;
ping.timer = setTimeout("ping.fail_to_ping()",60000);
},
fail_to_ping:function() {
clearTimeout(ping.timer);
ping.timer = null;
ping.imgPreload = null;
alert("Ping to domain failed!");
}
};
(from http://crynobone.com/ci/index.php/archive/view/852)
--update
But, as it's not a reliable solution (as you can't rely that the image will be in the website forever), the best solution might be to develop a new XPCom component.
Eh... as per HTML5 (read echmascript 5), the on-/offline events are available.
See it here at Mozilla Hacks
Edit 20/4/2011:
I just encountered an update for this answer, when i was watching a podcast from MS MIX11:
http://channel9.msdn.com/Events/MIX/MIX11/HTM14 around time 43:36, the lecturer is actually talking about the window.navigator.onLine property, where he uses it for detecting if the browser (and the computer) is online. Then he uses the online event to do something when he gets online again.
This method is only available in modern browsers, however. So IE 8 and below have to poll for the connection.

Categories