How to Integrate Quickblox with angularjs? - javascript

How to integrate Quickblox with AngularJs?
I already have done Login using it's sample's js and also getting response of incoming call looking at console.
But now I want to integrate Quickblox's listeners like
onCallListener,onAcceptCallListener,onRejectCallListener etc. are not working.
Please help me to solved it out, what i have missed? Thanks.

Just add below code in body of your main index page for quickblox integration.
<aside class="msg_board" id="msg_board"></aside>

Go through this link for integrating quickblox into angular js Here
after integration SDK initialize SDK using user credentials(email or password), then initialize all handler for event handling like.
function setupAllListeners() {
QB.chat.onDisconnectedListener = onDisconnectedListener;
QB.chat.onReconnectListener = onReconnectListener;
QB.chat.onMessageListener = onMessage;
QB.chat.onSystemMessageListener = onSystemMessageListener;
QB.chat.onDeliveredStatusListener = onDeliveredStatusListener;
QB.chat.onReadStatusListener = onReadStatusListener;
setupIsTypingHandler();
}
then implement function that handle all events like
// on message listener
//
function onMessage(userId, msg) {
// check if it's a mesasges for current dialog
//
if (isMessageForCurrentDialog(userId, msg.dialog_id)){
dialogsMessages.push(msg);
if (msg.markable === 1) {
sendReadStatus(userId, msg.id, msg.dialog_id);
}
// сheck if it's an attachment
//
var messageAttachmentFileId = null;
if (msg.extension.hasOwnProperty("attachments")) {
if(msg.extension.attachments.length > 0) {
messageAttachmentFileId = msg.extension.attachments[0].id;
}
}
showMessage(userId, msg, messageAttachmentFileId);
}
// Here we process the regular messages
//
updateDialogsList(msg.dialog_id, msg.body);
}
It will call whenever message is sended from otherend.

Related

Microsoft Azure Text to Speech - Stop Recording On Button Press - StopRecognitionOnceAsync() Not Working?

Apologies in advance for any terminology mistakes, I'm a student and trying my hardest to be as clear as possible! and thanks in advance for any help!
I'm trying to use Azure Speech-To-Text services. I'd like the user to be able to press a start and stop button to record themselves and print out the transcription. My app will eventually be a React Frontend and Rails backend, but right now I am just trying to understand and work through the demo.
I'm confused by the documentation but was able to get things half working. However, right now it just continuously listens to the speaker and never stops.
I want to use stopContinuousRecognitionAsync() or recognizer.close() once a button is pressed, but I cannot seem to get it working. The farthest I've gotten is the result is logged only once the stop button is pressed, but it continues to listen and print out results. I've also tried using recognizer.close() -> recognizer = undefined but to no avail. I am guessing that due to the asynchronous behavior, it closes out the recognizer before logging a result.
The latest code I've tried is below. This result starts listening on start click and prints speech on stop, but continues to listen and log results.
// subscription key and region for speech services.
var subscriptionKey, serviceRegion;
var authorizationToken;
var SpeechSDK;
var recognizer;
document.addEventListener("DOMContentLoaded", function () {
startRecognizeOnceAsyncButton = document.getElementById("startRecognizeOnceAsyncButton");
subscriptionKey = document.getElementById("subscriptionKey");
serviceRegion = document.getElementById("serviceRegion");
phraseDiv = document.getElementById("phraseDiv");
startRecognizeOnceAsyncButton.addEventListener("click", function () {
startRecognizeOnceAsyncButton.disabled = true;
phraseDiv.innerHTML = "";
// if we got an authorization token, use the token. Otherwise use the provided subscription key
var speechConfig;
if (authorizationToken) {
speechConfig = SpeechSDK.SpeechConfig.fromAuthorizationToken(authorizationToken, serviceRegion.value);
} else {
speechConfig = SpeechSDK.SpeechConfig.fromSubscription(“API_KEY”, serviceRegion.value);
}
speechConfig.speechRecognitionLanguage = "en-US";
var audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
recognizer.startContinuousRecognitionAsync(function () {}, function (err) {
console.trace("err - " + err);});
stopButton = document.querySelector(".stopButton")
stopButton.addEventListener("click", () =>{
console.log("clicked")
recognizer.recognized = function(s,e) {
console.log("recognized text", e.result.text)
}
})
});
Assuming the recognizer is conjured correctly outside of the code, there's a few things to change to get the result you want.
The events should be hooked to the recognizer before calling startContinuousRecognition().
In the stop button handler, call stop. I'd also hook the stop event outside of the start button click handler.
Quick typed changes, didn't compile. :-)
startRecognizeOnceAsyncButton.addEventListener("click", function () {
startRecognizeOnceAsyncButton.disabled = true;
//div where text is being shown
phraseDiv.innerHTML = "";
// The event recognized signals that a final recognition result is received.
recognizer.recognized = function(s,e) {
console.log("recognized text", e.result.text)
}
//start listening to speaker
recognizer.startContinuousRecognitionAsync(function () {}, function (err) {
console.trace("err - " + err);});
});
stopButton = document.querySelector(".stopButton")
stopButton.addEventListener("click", () =>{
console.log("clicked");
recognizer.stopContinuousRecongition();
};

GoogleAuth.signOut() does not work

I have a google sign-in button on my page, using gapi.signin2.render to render the button (https://developers.google.com/identity/sign-in/web/reference#gapisignin2renderid-options).
However it ALWAYS renders as signed-in, despite calling GoogleAuth.signOut(). In fact I can actually call GoogleAuth.signOut() and immediatly check GoogleAuth.isSignedIn.get() to check the state and returns as true.
Does anyone know how to fix this? My sign-out code is as follows:
var GoogleAuth = gapi.auth2.getAuthInstance();
GoogleAuth.signOut().then(() => {
var status = GoogleAuth.isSignedIn.get(); //ALWAYS TRUE!!!!
alert('IP.common.oAuth.signOut: signin status: ' + status);
});
This should be work fine. Delete then(this.props.onLogoutSuccess)) if you don't need it.
signOut() {
if (window.gapi) {
const auth2 = window.gapi.auth2.getAuthInstance()
if (auth2 != null) {
auth2.signOut().then(auth2.disconnect().then(this.props.onLogoutSuccess))
}
}
}
Very nice lib, if you wanna learn how to work with Google API https://github.com/anthonyjgrove/react-google-login. Yes it's react, but methods should be similar, I think.

Navigate to a specific html page on clicking toasts with params (WinJS)

I have a WinJS project and I receive toasts notification from my webservice. In my webservice my XML is like:
string type = "Computer";
string toast1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?> ";
string message = "{\"Message\":{\"Id\":\"6724d22a-87fe-4137-b501-9d9a9a0558b1\",\"DetailId\":\"dc02e784-7832-4625-a538-29be7f885ccb\",\"Description\":\" Message\",\"UserName\":null,\"ActionDateTime\":\"2015-09-15T15:36:14+05:45\",\"CalamityId\":\"c0fa848e-ee6c-4b91-8391-a12058f25387\",\"UseConferenceCalls\":true,\"IsActionCompleted\":false},\"Type\":\"COmp\"}";
string toast2 = string.Format(#"<toast launch= '{0}'>
<visual version='1'>
<binding template='ToastText04'>
<text id='1'>{1}</text>
<text id='2'>{2}</text>
</binding>
</visual>
</toast>", message, "Alert", type);
string xml = toast1 + toast2;
I want to navigate to a specific html page with the useful json as parameters when user click on toasts. Please suggest me some ways to do this.
Currently I have implemented the following function to handle my toasts.This only works when the app is in active state i.e. running in foreground or background. But when the app is closed completely this function won't hit and failed to meet my requirement.
WinJS.Application.addEventListener("activated", onActivatedHandler, true);
function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
var messageDetails = (args.detail.arguments).replace(/\\/g, '');
PhonegapService.setNotificationMessage(messageDetails, function () {
window.location.href = "page3.html";
});
}
}
I was facing a similar issue. In my case I was calling functions even before cordova deviceready was fired. From your question not sure if yours is a cordova app or not but make sure all the required javascript files are loaded. You can execute your logic once document is ready. I assume you are using jquery.
function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
$(document).ready(function(){
var messageDetails = (args.detail.arguments).replace(/\\/g, '');
PhonegapService.setNotificationMessage(messageDetails, function () {
window.location.href = "page3.html";
});
});
}
}

Call Javascript After Saving Calendar Item

I am having a script as below:-
function getColorValue(aId,atitle) {
try{
var clientContext = new SP.ClientContext();
var oWebsite = clientContext.get_web();
var oList = oWebsite.get_lists().getByTitle('Item type');
var oListItem = oList.getItemById(parseInt(aId));
clientContext.load(oListItem);
clientContext.executeQueryAsync(function () {
var listItem = oListItem;
var colorname = listItem.get_item('Color_x0020_Name');
if (typeof colorname != 'undefined') {
if (colorname != null) {
$("div[title$='" + atitle + "']").css("background-color", colorname);
}
}
}, onColorQueryFail);
}
catch(e){
}
}
I need to call this script each time after a SharePoint Calendar Item is created.
Can anyone help?
The following JavaScript example demonstrates how to register event that will be triggered after Calendar item is created:
//custom handler that will be triggered after Calendar item is created
function onEventCreated(){
alert('Event has been created...');
}
function registerCalendarEventOnItemCreated(event)
{
var currentCtx = getCurrentContextInfo();
var calContainer = SP.UI.ApplicationPages.CalendarInstanceRepository.lookupInstance(currentCtx.ctxId);
for(var name in calContainer) {
if(calContainer.hasOwnProperty(name)) {
var p = calContainer[name];
if(p instanceof SP.UI.ApplicationPages.CalendarNewFormDialog) {
p.get_events().addHandler("newitemcreated",event);
}
}
}
}
//get current context info
function getCurrentContextInfo()
{
var currentListId = new SP.Guid(_spPageContextInfo.pageListId);
for(var ctxKey in g_ctxDict){
var curCtx = g_ctxDict[ctxKey];
if(curCtx.listName == currentListId.toString()){
return curCtx;
}
}
return null;
}
//register Calendar events
$('body').on('click', 'div#AsynchronousViewDefault_CalendarView', function() {
registerCalendarEventOnItemCreated(onEventCreated);
});
Has been tested against SharePoint 2013/Online
In your case the function getColorValue could be invoked from onEventCreated, for example:
function onEventCreated(){
getColorValue (id,title);
}
How to apply changes
Switch the page into Edit mode
Add Script Editor webpart into page.
Put the specified code by wrapping it using script tag code into the Script Editor, for example: <script type="text/javascript">{JavaScipt code goes here}</script>
Save the page
Results
Create an Event Receiver with List Item Events for type and Calendar for Source then check 'An item is being added' in handling the event.
Then in the code behind of your Event Receiver:
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
//Call your function through this
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "MyFunction()", true);
}
Hope that helps :)
I know this is an old question, but there is an issue with the solution given.
I had a requirement to implement an workaround to the missing Resource Reservation feature in Sharepoint online. It was not possible to use an approach more suitable to the Modern Experience, due its dependency of Azure (no Azure subscription available for it), so I use Sharepoint API calls to perform the the same functionality of Resource Reservation.
To use the Sharepoint API, some Ajax calls were needed. But I observed that two calls were executed for each request.
The point is when you register calendar events, it is needed to attach the click event using one, as seen below, to prevent the click event to be fired more than once.
//register Calendar events
$('body').one('click', 'div#AsynchronousViewDefault_CalendarView', function() {
registerCalendarEventOnItemCreated(onEventCreated);
});

Titanium Facebook module not completing login on iOS 7

I've run into a weird issue using Titanium 3.2.0.GA and the Facebook module. When I try calling fb.authorize(); and if I'm logged into Facebook through iOS 7, the dialog pops up asking if I would like to allow it to blah blah blah. But once I tap "Allow", it triggers the login event with code -1, and is unsuccessful. However, if I'm not logged into Facebook through iOS 7, and login to Facebook through Safari after calling fb.authorize();, everything works as expected and the login event is triggered successfully.
var fb = require('facebook');
fb.appid = ****;
fb.permissions = ['email'];
fb.forceDialogAuth = false;
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
And like I said above, when the Facebook button is pressed I just call fb.authorize();.
Is anyone else having issues like this on iOS 7 using Titanium?
Looks like I fixed it. On my Facebook app, I had to add an iOS app and turn the "Single Sign On" on. Facebook was having issues last night and wouldn't let me make changes to my app but I just tried it today and it works now. I think this might be something new for iOS 7, but I'm not sure. However, turning Single Sign On to On worked for me.
Just declare All bellow variables in calling function only not globally other wise each time it will call fb.authorize().
i.e
var fb = null;
function facbooksharing(sharingData){
if(fb == null){
fb = require('facebook');
fb.appid = "******";
fb.permissions = ['publish_stream', 'read_stream','publish_actions'];
fb.forceDialogAuth = true; `enter code here`
}
if(fb.loggedIn==true)
{
fb.dialog("feed", sharingData, showRequestResult);
}else{
fb.authorize();
}
function showRequestResult(e)
{
if (e.success)
{
if (e.result)
{
Ti.API.info("Data Shared between your friend successfully.");
}
}
}
fb.addEventListener("login", function(e) {
if (fb.success && fb.accessToken != null) {
console.log(fb.accessToken);
}
});
}
Let me know is this resolve your problem or not.

Categories