Identify online user in weemo video call application - javascript

I am working on Weemo JS API for video conference.
1) I need some technical help for identify online user for conference.
2) How can i pass data from caller to callee?
3) How online user can disconnected from cloud?
please provide some technical ref for same.
Thanks.

You can know if a user is online or not by using the weemo.getStatus('USER_UID') method.
(void) getStatus('USER_UID')
When 'USER_UID' is the value of the target user Uid (String).
You will need to use the weemo.onGetHandler(name, obj) callback to catch the answer.
Here is an example of how to get the status of a user with a 'USER_ID' equal to 'userTestStatus':
var weemo = new Weemo('AppId', 'Token', 'Type');
weemo.onGetHandler = function(name, obj) {
switch(name) {
case 'status':
var uid = obj.uid;
if(obj.value == 0) {
console.log("User "+uid+" is offline with a status "+obj.value);
} else {
console.log("User "+uid+" is online with a status "+obj.value);
}
break;
}
};
weemo.onConnectionHandler = function(message, code) {
console.log("Connection Handler : " + message + ' ' + code);
switch(message) {
case 'sipOk':
weemo.getStatus('userTestStatus');
break;
}
};
weemo.initialize();
FYI: In this example I used the getStatus in the onConnectionHandler after receiving a "sipOk" because I want to make sure that my user is completly connected before runing a getStatus. Once you user is connected to the Weemo Cloud you can execute a getStatus out of the onConnectionHandler.
Once connected you can disconnect your user by using the weemo.reset() method. This will disconnect your user from the Weemo cloud.
(void) reset()
The reset function is used in order to properly disconnect the user from the cloud, and be able to connect to the real-time platform with other credentials.
You can find more details in the documentation and sample code available on the Weemo github here.
You can also find the full Weemo JavaScript API here

Related

save/remember an Alexa user's intent confirmation response?

I have a confirmation prompt for one of my Alexa skill's intents, and now I need it to "remember" the user's answer and not ask the user again. Essencially, we want the user to be prompted only on the very first time they use the skill, and then never again. Is that possible?
I'm hoping I don't have to do a total code re-write, and can just update my existing code. Here is my intent's javascript code (simplified) for the lambda function for the skill:
'myIntent': function() {
// there is a required prompt setup in the language interaction model (in the Alexa Skill Kit platform)
// To use it we "deligate" it to Alexa via the delegate dialoge directive.
if (this.event.request.dialogState === 'STARTED') {
// Pre-fill slots: update the intent object with slot values for which
// you have defaults, then emit :delegate with this updated intent.
this.emit(':delegate');
} else if (this.event.request.dialogState !== 'COMPLETED'){
this.emit(':delegate');
} else {
// completed
var intentObj = this.event.request.intent;
if (intentObj.confirmationStatus !== 'CONFIRMED') {
// not confirmed
if (intentObj.confirmationStatus !== 'DENIED') {
// Intent is completed, not confirmed but not denied
this.emit(':tell', "You have neither confirmed or denied. Please try again.");
} else {
// Intent is completed, denied and not confirmed
this.emit(':ask', 'I am sorry but you cannot continue.');
}
} else {
// intent is completed and confirmed. Success!
var words = "You have confirmed, thank you!";
this.response.speak(words);
this.emit(':responseReady');
}
}
},
Thanks for any help!
Update: I have successfully implement this new feature using the accepted answer's help. However I had to totally re-write everything to fit the new version of the Alexa sdk.
You can persist/save/remember alexa user's data using persistent attributes.
I recommend you to follow alexa skill sample tutorial zero to hero it summarise everything you need to know about developing a skill on Alexa with examples & videos.
And what you need from this tutorial is the Part 4 - Persistence
And then, it will be as easy as:
attributesManager.setPersistentAttributes(sessionAttributes);
await attributesManager.savePersistentAttributes();

How to debug Directory API push notifications?

I used Directory API push notifications example of https://stackoverflow.com/users/6586255/dimu-designs from this question: Is it possible to watch Directory API changes from Google App Maker/Google Apps Script?
I have two projects setup, another one is webhook itself:
/** HTTP GET request handler */
function doGet(e) {
return ContentService.createTextOutput("GET message");
}
/** HTTP POST request handler */
function doPost(e) {
return ContentService.createTextOutput("POST message");
}
And other one is the watch request:
function startUpdateWatch() {
var channel = AdminDirectory.newChannel(),
receivingURL = "https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/exec",
gSuiteDomain = "[business-name].com",
event = "update";
channel.id = Utilities.getUuid();
channel.type = "web_hook";
channel.address = receivingURL + "?domain=" + gSuiteDomain + "&event=" + event;
channel.expiration = Date.now() + 21600000; // max of 6 hours in the future; Note: watch must be renew before expiration to keep sending notifications
AdminDirectory.Users.watch(
channel,
{
"domain":gSuiteDomain,
"event":event
}
);
}
Webhook url works fine, it fires "Get" when I try to open it via browser. startUpdateWatch function starts fine as well without errors and if I try to change the url to something else, I get an error, so that receiving url should be ok as well.
How you debug that push channel? I have tried to launch function with different events like 'add' and 'delete' as well and then deleted/added/modified user in G suite, but no push from that function towards the url.

Preserving web sockets with Laravel and JavaScript

I am currently using Ratchet with laravel 4 for my application's chat feature. I am using the following JS in the front-end to handle the web sockets.
function startChatSession(){
var person = prompt("Please enter your ID", "");
if(chatBoxes.length <= 0)
chatBoxes.push("onlineList");
if (person != null && person != "") {
myself = person;
if(conn == null){
conn = new WebSocket('ws://192.168.1.5:8080?'+person); // 'user facebook id' instead of name
conn.onmessage = msgReceive;
conn.onopen = function(e) {
console.log(e);
};
conn.onerror = function(e){setTimeout(startChatSession,5000);};
}
}
}
Now my problem is that the web socket connection disconnects on page refresh and page transition. After searching the web I decided this couldn't be fixed in the front-end. So I want to preserve the chat session at the Laravel's end. I am already storing the online users in the DB, when a connection is opened and deleting them on close.
I am trying to come up with a work around check for online users, since the sockets opens and closes often it creates too many inserts and deletes to table. How can I attach the socket with Laravel session or create a work-around that could solve my problem?

Getting unique ClientID from chrome extension?

I'm developing chrome extension. I need the ability to identify each client as a unique client.
I can't store guid in a cookie since cookie can be deleted. I need something to be read from the system itself which is unique.
Now - I know that JS doesn't has access to client resources ( local resources) but - and here is my question :
Question
Does chrome extensions Js's provide API for getting unique client information ( I dont care what data - as long as it is unique).
Edit :
Just to clarify :
The user will be shown a unique key ( which is a hash data of his computer). this code will be sent to me , and I will provide matching result which the user will be sent (via email) and only then - he will be able to use the extension.
(no , not all countries support extension payment via wallet , im at one of those countries)
To uniquely identify a user, I would suggest to generate a random token and store it in your extension's storage (chrome.storage). The userid has to be generated only once, when the token does not exist in storage.
For example:
function getRandomToken() {
// E.g. 8 * 32 = 256 bits token
var randomPool = new Uint8Array(32);
crypto.getRandomValues(randomPool);
var hex = '';
for (var i = 0; i < randomPool.length; ++i) {
hex += randomPool[i].toString(16);
}
// E.g. db18458e2782b2b77e36769c569e263a53885a9944dd0a861e5064eac16f1a
return hex;
}
chrome.storage.sync.get('userid', function(items) {
var userid = items.userid;
if (userid) {
useToken(userid);
} else {
userid = getRandomToken();
chrome.storage.sync.set({userid: userid}, function() {
useToken(userid);
});
}
function useToken(userid) {
// TODO: Use user id for authentication or whatever you want.
}
});
This mechanism relies on chrome.storage.sync, which is quite reliable. This stored ID will only be lost in the following scenarios:
The user re-installs the extension. Local storage will be cleared when uninstalling the extension.
One of the storage quotas has been exceeded (read the documentation).
This is not going to happen because the only write operation occurs at the first run of your extension.
Chrome's storage gets corrupted and fails to save the data.
Even if the user does not have Chrome Sync enabled, data will still be saved locally. There have been bugs with Chrome's internals that resulted in data loss, but these are incidents.
The user has opened the developer tools for your extension page and ran chrome.storage.sync.clear() or something similar.
You cannot protect against users who possess the knowledge to mess with the internals of Chrome extensions.
The previous method is sufficient if you want to uniquely identify a user. If you really want to get a hardware-based ID, use chrome.storage.cpu and chrome.storage.memory as well. I don't see any benefits in using these additional sources though, because they can change if the user replaces hardware, and they are not unique either (two identical laptops would report the same values, for instance).
As Xan suggested, the chrome.identity API is probably your best choice. You can get the users e-mail address and use that as a random seed to generate a code of your choosing. The user info also includes an "id" field which I believe is unique but I haven't ever seen any documentation that substantiates that. You can then use the chrome.storage.sync API to store the generated key in the users online data storage for your app. This way the user will be able to access their private key whenever and where ever they log in on any device.
Please note that you will have to enable the oAuth2 api's in the developers console for your application and include the application key and proper scopes in your app manifest.
Here is a crude example:
function getUserInfo (interactive, callback )
{
var xmlhttp = new XMLHttpRequest();
var retry = true;
var access_token;
getToken();
/**
* Request the Auth Token
*/
function getToken()
{
chrome.identity.getAuthToken( { 'interactive': interactive }, function (token) {
if ( chrome.runtime.lastError )
{
console.log( "ERROR! " + chrome.runtime.lastError.message );
return;
}
if ( typeof token != 'undefined ')
{
access_token = token;
sendRequest( );
}
else
callback( );
});
}
function sendRequest()
{
xmlhttp.open('GET', 'https://www.googleapis.com/userinfo/v2/me' );
xmlhttp.setRequestHeader('Authorization','Bearer ' + access_token );
xmlhttp.onload = requestComplete;
xmlhttp.send();
}
function requestComplete()
{
if ( this.status == 401 && retry )
{
retry = false; // only retry once
console.log( "Request failed, retrying... " + this.response );
}
else
{
console.log( "Request completed. User Info: " + this.response );
callback(null, this.status, this.response );
var userInfo = JSON.parse( this.response );
storeUniqueKey( userInfo );
}
}
}
function storeUniqueKey( info )
{
var key;
// TODO: Generate some key using the user info: info.loginName
// user info here contains several fields you might find useful.
// There is a user "id" field here which is numeric and I believe that
// is a unique identifier that could come in handy rather than generating your
// own key.
...
chrome.storage.sync.set ( { user_key: key } );
}
To add to Rob W's answer. In his method, the saved string would propagate to every Chrome instance signed in with the same Google user account - with a lot of big and small if's.
If you need to uniquely identify a local user profile, and not all Chrome profiles with the same Google user, you want to employ chrome.storage.local in the same manner. This will NOT be a unique Chrome install identifier though - only a profile within that install.
What also needs to be noted is that all this data is not in any way or form tied to anything - it just has a good probability of being unique. But absolutely nothing stops user from reading and cloning this data as he sees fit. You cannot, in this scenario, secure the client side.
I'm thinking that a more secure way would be to use chrome.identity API to request and maintain an offline (therefore, not expiring) token as proof of license. The user cannot easily clone this token storage.
I'm not versed in OAuth yet, so if anyone can point out what's wrong with this idea - they are welcome to.
We can also use Crypto.randomUUID() for generating a UUID and then save it to web storage. Refer to MSDN for details this API.
let uuid = self.crypto.randomUUID();
console.log(uuid); // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f"

Problem with redirect after FB.Connect.showPermissionDialog

I'm building a facebook connect app to publish content to user's streams. In order to do that, I need to get extended publish_stream permission from the users. I'm using the function code to do so.
Check connection status
<input type="button" onclick="statusSubmit('Permission to publish : ');" value="Check connection status" />
<script type="text/javascript">
function statusSubmit(status)
{
facebook_prompt_permission('publish_stream', function(accepted)
{
if(accepted) {
// User (already) has permission
alert(status + 'already granted');
}
else
{
// User does not have permission
alert(status + ' not granted');
}
});
}
function facebook_prompt_permission(permission, callbackFunc)
{
// Check if user has permission, if not invoke dialog.
FB.ensureInit(function() {
FB.Connect.requireSession(function(){
//check is user already granted for this permission or not
FB.Facebook.apiClient.users_hasAppPermission(permission,
function(result) {
// prompt offline permission
if (result == 0) {
// render the permission dialog
FB.Connect.showPermissionDialog(permission,
function(result){
if (null == result)
alert('no permissons granted');
else
alert('permissions ' + result);
}, true, null);
} else {
// permission already granted.
callbackFunc(true);
}
});
});
});
}
</script>
After the permissions dialog is displayed and the user grants the permissions, there is a redirect my current page on my local development machine. I cannot seem to control this redirect behaviour through my settings. I have tried changing the "Post-Authorize Callback URL" to a publicly visible page, but it does not get called. Is there something I'm missing? I would like to either
Get the post-authorize callback URL to something that works OR
Even better if there is no redirection after the user grants
permissions. This option would be the best.
Thank you for any suggestions.
abronte, Thank you for your suggestion. I actually figured out that the path to xd_receiver.htm was incorrect, which was causing all the weird behavior. When I corrected that, things were OK. But the FB Javascript API is very flaky, we decided not to use it as the behavior is erratic. We will be switching to a server based solution in the future.
I believe that the post-authorize callback url that is set in the application settings only deals with within facebook canvas sort of stuff. What url is called after you authorize the app in facebook.
What I think the best solution is (and this is what i do) is to manually redirect the user after the extended permissions prompt is completed.
window.location = '/path/to/something';

Categories

Resources