I am having trouble getting quickblox chat working on phonegap (javascript).I have used the revealing module pattern to expose instead of 'require' and this is the broken piece of code:
var chatParams = {
onConnectFailed: onConnectFailed,
onConnectSuccess: onConnectSuccess,
onConnectClosed: onConnectClosed,
onChatMessage: onChatMessage
};
QB.createSession(params, function(err, result) {
if (err==null) {
chatUser = {
id: result.user_id,
pass: params.password
};
connectChat(chatParams);
}
else {
alert("Something went wrong, please try again later or contact us at contact#domain.co.uk if the problem persists.");
}
});
function connectChat(chatParams) {
//This line here:
var chatService = new QBChat(chatParams);
console.log(chatService);
// connect to QB chat service
chatService.connect(chatUser);
};
I am getting the error 'object not a reference' at the highlighted line.
Please advise!
Try to use this code as an example to join chat:
QB.chat.connect({userId: user.id, password: user.pass}, function(err, roster) {
if (err) {
console.log(err);
} else {
console.log(roster);
}
});
instead of
function connectChat(chatParams) {
//This line here:
var chatService = new QBChat(chatParams);
console.log(chatService);
// connect to QB chat service
chatService.connect(chatUser);
};
Related
I have been trying to create users on quickblox without any success. I have reviewed their documentation and have searched the internet, including SO, to no avail. Below is my code:
var QB = require('quickblox');
//Inizializing quickblox
QB.init(6455, "7j9XXXXXXXX", "DdWCXXXXXXX");
QB.createSession(function(err, result) {
// callback function
console.log('Callback', err, result);//This display 'Callback null undefine'
});
var params = { 'login': 'displayName', 'password': 'userIdert'};
QB.users.create(params, function(err, user) {
if (user)
{
console.log('Sign Up SUCCESS: ', JSON.stringify(user));
} else {
console.log('Sign Up ERROR: ', JSON.stringify(err));
}
});
PS:
I used this to install quickblox in nodejs: npm install quickblox --save
What I've tried
Tried to output the result gotten from createSession() it return null for error and undefine for result
Added QB.users.create() inside the callback function
Use qbuserparam with createSession()
I'm developing an iOS app with Parse SDK hosted on back4app, my app in the back4app dashboard hosts a main.js file in Cloud Code that sends push notifications, it gets called by code and it works fine.
Now I've added a blockuser.js file in my Cloud Code, such file should edit the isBlocked column (of type Boolean) of a specific user in _User class and set it to true, here's the code I use:
Parse.Cloud.define("blockUser", function(request, response) {
var userId = request.params.userId,
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('isBlocked', true);
Parse.Cloud.useMasterKey();
user.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
Here's the Swift code I wrote to call that function:
let request = ["userId" : userPointer.objectId!] as [String : Any]
PFCloud.callFunction(inBackground: "blockUser", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\(userPointer["username"]!) has been blocked!")
// error in cloud code
} else {
print ("\(error!.localizedDescription)")
}})
The Xcode console prints out this message:
[Error]: Invalid function. (Code: 141, Version: 1.14.2)
In fact, that blockUser function doesn't work at all.
Anybody knows what I'm doing wrong in the .js or swift code?
After a few attempts, I've figured it out, here's the function I've added in my main.js file in Cloud Code:
// BLOCK A USER ----------------------------------------
Parse.Cloud.define("blockUser", function(request, response) {
var userId = request.params.userId;
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('isBlocked', true);
Parse.Cloud.useMasterKey();
user.save(null, { useMasterKey: true } ).then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
And here's the Swift 3 code to call blockUser function:
let request = [
"userId" : userPointer.objectId!
] as [String : Any]
PFCloud.callFunction(inBackground: "blockUser", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\(userPointer["username"]!) has been blocked!")
// error
} else {
print ("\(error!.localizedDescription)")
}})
it seems like you did not reload your main.js (file where you write cloud code functions) on server
Using node js i want to create persistent subscription for Azure service bus service topic. right now it is execute only once. Please guide me I am new to this. Thanks in advance. I am using following code to subscribe topic.
var azure = require('azure');
var azureConnection = "Endpoint=sb:My connection string"
var retryOperations = new azure.ExponentialRetryPolicyFilter();
var serviceBusService = azure.createServiceBusService(azureConnection).withFilter(retryOperations);
serviceBusService.receiveSubscriptionMessage('mytopic01', 'mytopicsub', function (error, receivedMessage) {
if (!error) {
// // // Message received and deleted
console.log(receivedMessage);
}
});
Also I don't want to use setInterval function. I want to solution if message publish to the topic it should automatically trigger subscription.
Actually, if your client application is an independent node.js application, we usually set up a cycle program to receive message from service bus in loop.
E.G.
var azure = require('azure');
var sbService = azure.createServiceBusService(<connection_string>);
function checkForMessages(sbService, queueName, callback) {
sbService.receiveSubscriptionMessage(queueName, { isPeekLock: true }, function (err, lockedMessage) {
if (err) {
if (err === 'No messages to receive') {
console.log('No messages');
} else {
callback(err);
}
} else {
callback(null, lockedMessage);
}
});
}
function processMessage(sbService, err, lockedMsg) {
if (err) {
console.log('Error on Rx: ', err);
} else {
console.log('Rx: ', lockedMsg);
sbService.deleteMessage(lockedMsg, function(err2) {
if (err2) {
console.log('Failed to delete message: ', err2);
} else {
console.log('Deleted message.');
}
})
}
}
setInterval(checkForMessages.bind(null, sbService, queueName, processMessage.bind(null, sbService)), 5000);
You can refer to the code sample in the similar scenario at GitHub provided by Azure Team.
Any further concern, please feel free to let me know.
I am trying to implement push notifications for my app using nodejs for the backend using quickblox. I'm following the steps to do that as mentioned on the quickblox site, i.e create a session user, create a push token, and last subscribe to notification channel. I'm facing a problem with the creation of the push token. My server side code looks like this:
app.post('/test_quickblox', function(req, res) {
var params = {
login: req.user.qb_username,
password: req.user.qb_password,
}
console.log(params);
QB.createSession(params, function(err, result) {
if (err) {
console.log(err);
}
console.log(result);
var options = {};
options.headers = {};
options.headers['QuickBlox-REST-API-Version'] = '0.1.0';
options.headers['QB-Token'] = result.token;
options.body = {};
options.body['push_token'] = {};
options.body['push_token']['environment'] = 'development';
options.body['push_token']['client_identification_sequence'] = '54b1e2b9e9081ed60520824054b1e2b8e9081ed60520823f';
options.body['device'] = {};
options.body['device']['platform'] = 'ios';
options.body['device']['udid'] = 'e0101010d38bde8e6740011221af335301010333';
options.url = 'http://api.quickblox.com/push_tokens.json';
QuickbloxRequest(options, function(err, response) {
if (err) {
console.log(err);
return apiError();
}
console.log(response);
res.apiSuccess();
});
});
});
when logging the response it looks like the following
{ _id: '54b1e3a1535c121c2000be66',
application_id: 18113,
created_at: '2015-01-11T02:44:49Z',
device_id: 0,
nonce: 8394,
token: 'bf61098a35fac9389be236caec44f0a9827630d1',
ts: 1420944288,
updated_at: '2015-01-11T02:44:49Z',
user_id: 2179940,
id: 56046 }
and the error I get is:
{"code":null,"message":"No device registered for current user session. Device is obligatory to be able to execute actions with push token."}
I guess the problem lies in the device_id being 0.
Note that I am creating the users in another controller without supplying any device_id upon creation, so I think that might be my problem but I am new to quickblox and do not understand yet all the semantics so please help me find out what the problem is. Thanks
And here we are 4 years later and I faced the same problem. No answer, no nothing, it makes you wonder how large is the quickblox community :O
Anyway, for anyone coming here with the same problem : It seems the problem is that the Android UUID returned by PhoneGap is too short so quickblox rejects it silently.
Here is what worked for me. Pay attention to the doubling of the uuid :
window.device.uuid + window.device.uuid
JS Code :
//REGISTER AS ANDROID
var message = {
environment: "development",
client_identification_sequence: e.regid,
platform: "android",
udid: window.device.uuid + window.device.uuid,
};
if (BBPushNotification.showLog) console.log(message);
QB.messages.tokens.create(message, function(err, response){
if (err) {
if (BBPushNotification.showLog) console.log("Create token error : ",err);
} else {
if (BBPushNotification.showLog) console.log("Create token success : ",response);
}
});
I have an Angular service that takes in a roleId and userId and assigns the user to that role and make a pointer in User to that role.
app.service('CRUD', function () {
this.addUserToRole = function (roleId, userId) {
// first we have to find the role we're adding to
var query = new Parse.Query(Parse.Role);
return query.get(roleId, {
success: function (role) {
// then add the user to it
var Database = Parse.Object.extend("User");
var query = new Parse.Query(Database);
console.log(role);
return query.get(userId, {
success: function (user) {
console.log(user);
role.getUsers().add(user);
role.save();
// now we need to tell the user that he has this role
console.log(user);
user.attributes.role.add(role);
user.save();
return user;
},
error: function (err) {
return err;
}
});
},
error: function (err) {
console.log(err);
}
});
}
});
I'm getting {"code":206,"error":"Parse::UserCannotBeAlteredWithoutSessionError"} on user.save();
After some research, I arrived at this website. He uses this code snippet as a JS SDK example:
Parse.Cloud.run('modifyUser', { username: 'userA' }, {
success: function(status) {
// the user was updated successfully
},
error: function(error) {
// error
}
});
and mentions something about a useMasterKey() function.
I'm still unsure how to fix this error.
Add
Parse.Cloud.useMasterKey();
at the beginning of your function.
Set it up as a background job. That is the code snip you found I think and a simpler far more secure means of fondling users and roles
https://parse.com/docs/cloud_code_guide#jobs