88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
define(function (require, exports, module) {
|
|
var ep = require("../../platform/extensionPort.js");
|
|
var port = ep.port;
|
|
var data = require("../../data.js");
|
|
var sessMgr = require("../../account/sessionMgr.js");
|
|
var ev = require("../../platform/EventObject.js");
|
|
var mp = require("../widget_message_popup.js");
|
|
|
|
//frames
|
|
var servernode = require("./servernode.js");
|
|
servernode.on("roomSelectHide", function () {
|
|
hideChatFrameUI();
|
|
showChatFloatTip();
|
|
});
|
|
servernode.on("chatServerLoaded", function (e, serverList) {
|
|
servers = serverList;
|
|
if (servers)
|
|
showChatFloatTip();
|
|
port.postMessage("getCurrentRoomInfo");
|
|
});
|
|
servernode.on("enterRoot", function (e, room) {
|
|
//进入房间
|
|
sessMgr.ensureLogined(enterroom.bind(room));
|
|
});
|
|
|
|
//服务器
|
|
var servers;
|
|
|
|
var showChatFloatTip = function () {
|
|
if ($("#chat_frame.open").length)
|
|
return;
|
|
|
|
var totalcount = _.reduce(_.pluck(servers, "onlinecount"), function (i, m) { return i + m; }, 0);
|
|
$("#chat_float_tip").find("span").html(totalcount + '').end().show();
|
|
};
|
|
var showChatFrameUI = function () {
|
|
$("#chat_frame").height();
|
|
$("#chat_frame").addClass("open");
|
|
$("div.wrap").addClass("chat-on");
|
|
$("#chat_float_tip").hide();
|
|
};
|
|
var hideChatFrameUI = function () {
|
|
$("div.wrap").removeClass("chat-on");
|
|
$("#chat_frame").removeClass("open");
|
|
};
|
|
var showServerList = function () {
|
|
showChatFrameUI();
|
|
servernode.showRoomSelect();
|
|
};
|
|
|
|
//进入房间
|
|
var roomSession = require("./roomsession.js");
|
|
var enterroom = function () {
|
|
showChatFrameUI();
|
|
roomSession.enterRoom(this);
|
|
};
|
|
roomSession.session.on("exitRoom", function () {
|
|
showServerList();
|
|
});
|
|
|
|
//扩展状态异常
|
|
port.on("disconnect", function () {
|
|
if (roomSession.session.room)
|
|
mp.alert("提示", "连接已丢失,请刷新界面重新进入聊天室。");
|
|
$("#chat").hide();
|
|
});
|
|
port.on("responseCurrentRoomInfo", function (e, r) {
|
|
if (r) {
|
|
if (r !== roomSession.session.room)
|
|
sessMgr.ensureLogined(enterroom.bind(r));
|
|
} else if (roomSession.session.room) {
|
|
roomSession.session.exitRoom();
|
|
}
|
|
});
|
|
|
|
(function ui() {
|
|
$("#chat_float_tip").click(showServerList);
|
|
})();
|
|
|
|
setTimeout(function() {
|
|
servernode.loadServers();
|
|
}, 1000 * 60 * 11);
|
|
|
|
return {
|
|
|
|
};
|
|
});
|