|
本帖最后由 08_luoting 于 2016-7-29 14:50 编辑
require(["require","jquery","actor/actorClient"],function(require,$,actorClient){
var peer;
var deferred=$.Deferred();
var messegeClient;
var currentUser={
flag:true,
message:null,
personID:"PSN01",//nickname
personName:"system"
};
actorClient.promise.done(function(client) {
var pid = currentUser.personID;
var pname = currentUser.personName;
client.validPerson(pid, pname).done(function(state) {
if (state === "logged_in") {
messegeClient=client;
deferred.resolve();
} else if (state === "signup") {
deferred.reject("signUp unSupported");
} else {
deferred.reject("Unsupported state: " + state);
}
}).fail(function(error) {
deferred.reject("登录出错! 原因: " + error);
});
});
deferred.done(function(){
$("#dddd").click(onSelectPeer);
$("#mes_send").click(sendMessege);
});
var onSelectPeer=function(){
/*peer={
id : 128888587,
key : "u128888587",
type : "user"
}*/
peer=getPeer("128888587", "user");
$("#mes_box").show();
messegeClient.onConversationOpen(peer);
messegeClient.bindMessages(peer, function(messages, delays) {
//消息接收
console.log("接收到消息");
});
messegeClient.bindUserOnline(peer.id, function(online) {
var isOnline = online ? (online.isOnline ? "-在线" : "-离线") : "";
console.log("isOnline:"+isOnline);
});
messegeClient.bindTyping(peer, function(typing) {
console.log(typing.typing ? "对方正在输入" : "");
});
};
var sendMessege=function(){
messegeClient.sendTextMessage(peer,$("#mes_content").val());
}
var getPeer=function(id, type) {
if (type === "user") {
return messegeClient.getUserPeer(id);
} else {
return messegeClient.getGroupPeer(id);
}
}
}) |
|