104 lines
2.9 KiB
JavaScript
104 lines
2.9 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");
|
|
|
|
//服务器
|
|
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();
|
|
}
|
|
});
|
|
|
|
$("#chat_float_tip div:eq(1)").click(showServerList);
|
|
$("#chat_float_tip div:eq(0)").click(function () {
|
|
var cnt = $("#chat_float_tip");
|
|
if (cnt.hasClass("off")) {
|
|
cnt.removeClass("off");
|
|
cnt.find(">div:eq(0)>i").removeClass("fa-caret-left").addClass("fa-caret-right");
|
|
localStorage.removeItem("chat_hide");
|
|
} else {
|
|
cnt.addClass("off");
|
|
cnt.find(">div:eq(0)>i").addClass("fa-caret-left").removeClass("fa-caret-right");
|
|
localStorage.setItem("chat_hide", 1);
|
|
}
|
|
});
|
|
if (document.body.scrollWidth < 1260 || localStorage.chat_hide) {
|
|
$("#chat_float_tip").addClass("off").find(">div:eq(0)>i").addClass("fa-caret-left").removeClass("fa-caret-right");
|
|
}
|
|
|
|
//加载服务器节点列表
|
|
servernode.loadServers();
|
|
setInterval(function () {
|
|
servernode.loadServers();
|
|
}, 1000 * 60 * 10);
|
|
|
|
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));
|
|
});
|
|
|
|
return {
|
|
|
|
};
|
|
});
|