我使用此代码从 http://quickblox.com/developers/Javascript 检索.
My SDK info: /* 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".
有人可以帮忙吗?
最佳答案
正如他们的 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 初始化后运行。
关于javascript - Quickblox JS SDK 在创建对话框时通知Occupants,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38459501/