从node.js连接quickblox聊天服务器

时间:2015-04-03 11:01:55

标签: node.js quickblox

请告诉我,我是否以正确的格式调用了这些方法

var QB=require('quickblox');
var QuickBlox = require('quickblox').QuickBlox;
var QBChat = require('quickblox');
var QB2 = new QuickBlox();
var params, chatUser, chatService;
params = {email: 'raji@gmail.com', password: ''};
QB.init(21000,'NBRQfWA2OWwfBre','GNwMJzqPL8wZb8g');
// QuickBlox session creation
QB.createSession(params, function(err, result) {
if (err) {
    console.log(err.detail);
} else {
    console.log(result.user_id);
    console.log(params.password)
    chatUser = {
        id: result.user_id,
        pass: params.password
            };
    console.log(chatUser)
    connectChat(chatUser);
}
});
function connectChat(chatUser) {
chatService = new QB.chat({
    onConnectFailed: onConnectFailed,
    onConnectSuccess: onConnectSuccess,
    onConnectClosed: onConnectClosed,
    onChatMessage: onChatMessage
});
// connect to QB chat service
console.log("connection")
//connection = new Strophe.Connection(CHAT.bosh_server);
chatService.connect(chatUser);
}
function onConnectFailed() {}
// Connection is success
function onConnectSuccess() {}
// Connection is closed
function onConnectClosed() {}
var recipientID = 978816;
var message = {
body: 'Hello world',
type: 'chat'
};
// send user message
//chatService.sendMessage(recipientID, 'hello'); 
// getting messages
function onChatMessage(senderID, message) {}

我收到以下错误

TypeError: object is not a function
at connectChat (C:\Program Files\nodejs\chat1.js:33:16)
at C:\Program Files\nodejs\chat1.js:28:3
at C:\Program Files\nodejs\node_modules\quickblox\js\modules\qbAuth.js:52:27

at Request.requestCallback [as _callback] (C:\Program Files\nodejs\node_modu
les\quickblox\js\qbProxy.js:126:16)
at Request.self.callback (C:\Program Files\nodejs\node_modules\request\reque
st.js:373:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (C:\Program Files\nodejs\node_modules\request\request
.js:1318:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (C:\Program Files\nodejs\node_modules\request
\request.js:1266:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)

如何从node.js连接quickblox聊天服务器。我尝试使用聊天插件进行连接,但甚至无法创建聊天实例。它显示错误

0 个答案:

没有答案