我从http://quickblox.com/developers/Javascript使用此代码检索。
我的SDK信息:/ * QuickBlox JavaScript SDK - v2.1.4 - 2016-07-19 * /
function notifyOccupants(dialogOccupants, newDialogId) {
dialogOccupants.forEach(function(itemOccupanId, i, arr) {
if (itemOccupanId != currentUser.id) {
var msg = {
type: 'chat',
extension: {
notification_type: 1,
_id: newDialogId,
},
};
QB.chat.send(itemOccupanId, msg);
}
});
}
当我执行此功能时,它总是返回:
"quickblox.min.js:7 Uncaught TypeError: Cannot read property 'send' of undefined".
有人可以帮忙吗?
答案 0 :(得分:0)
正如他们tutorial中所述, 您必须先初始化QB对象才能使用它。
确保代码中包含以下行:
QB.createSession({login: user.login, password: user.pass}, function(err, res) {
if (res) {
QB.chat.connect({userId: user.id, password: user.pass}, function(err, roster) {
并检查代码是否在connect
函数回调中,
确保您的代码仅在QB初始化后运行。
答案 1 :(得分:0)
我的代码:
var usersIds = [];
usersIds.push(user);
var params = {
type: 3,
occupants_ids: usersIds
};
console.log("Creating a dialog with params: " + JSON.stringify(params));
QB.chat.dialog.create(params, function (err, createdDialog) {
if (err) {
console.log(err);
errorCallback();
} else {
console.log("Dialog " + createdDialog._id + " created with users: " + usersIds);
// save dialog to local storage
var dialogId = createdDialog._id;
QuickbloxConfig.dialogs[dialogId] = createdDialog;
QuickbloxConfig.currentDialog = createdDialog;
//
// self.joinToNewDialogAndShow(createdDialog);
self.notifyOccupants(createdDialog.occupants_ids, createdDialog._id, 1);
//self.triggerDialog(createdDialog._id);
successCallback();
}
});
当我调用self.notifyOccupants(createdDialog.occupants_ids,createdDialog._id,1)时,它才会失败;