void CefManager::PostQuitMessage(int nExitCode)
{
#if !defined(SUPPORT_CEF)
	::PostQuitMessage(nExitCode);
	return;
#endif

	// 当我们需要结束进程时,千万不要直接调用::PostQuitMessage,这是可能还有浏览器对象没有销毁
	// 应该等所有浏览器对象都销毁后再调用::PostQuitMessage
	if (browser_count_ == 0)
	{
		Post2UI([nExitCode]()
	 	{
			::PostQuitMessage(nExitCode);
	 	});
	}
	else
	{
		auto cb = [nExitCode]()
		{
			CefManager::GetInstance()->PostQuitMessage(nExitCode);
		};

		nbase::ThreadManager::PostDelayedTask(kThreadUI, cb, nbase::TimeDelta::FromMilliseconds(500));
	}
}
void LoginCallback::OnReLoginCallback(const nim::LoginRes& login_res)
{
	QLOG_APP(L"OnReLoginCallback: {0} - {1}") << login_res.login_step_ << login_res.res_code_;

	if (login_res.res_code_ == nim::kNIMResSuccess)
	{
		if (login_res.login_step_ == nim::kNIMLoginStepLogin)
		{
			Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, true));
		}
	}
	else
	{
		Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, true));
	}
}
//多端
void LoginCallback::OnMultispotLoginCallback(const nim::MultiSpotLoginRes& res)
{
	QLOG_APP(L"OnMultispotLoginCallback: {0} - {1}") << res.notiry_type_ << res.other_clients_.size();

	bool online = res.notiry_type_ == nim::kNIMMultiSpotNotiyTypeImIn;
	if (!res.other_clients_.empty())
		Post2UI(nbase::Bind(LoginCallback::OnMultispotChange, online, res.other_clients_));

}
void LoginCallback::OnLoginCallback( const nim::LoginRes& login_res, const void* user_data )
{
	QLOG_APP(L"OnLoginCallback: {0} - {1}") << login_res.login_step_ << login_res.res_code_;

	if (login_res.res_code_ == nim::kNIMResSuccess)
	{
		if (login_res.login_step_ == nim::kNIMLoginStepLogin)
		{
			Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, false));
			if (!login_res.other_clients_.empty())
			{
				Post2UI(nbase::Bind(LoginCallback::OnMultispotChange, true, login_res.other_clients_));
			}
		}
	}
	else
	{
		Post2UI(nbase::Bind(&UILoginCallback, login_res.res_code_, false));
	}
}
void ChatroomCallback::OnExitCallback(__int64 room_id, int error_code, NIMChatRoomExitReason exit_reason)
{
	QLOG_APP(L"Chatroom:OnExitCallback: id={0} code={1}") << room_id << error_code;

	StdClosure cb = [room_id, exit_reason]()
	{
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form)
			chat_form->Close(ChatroomForm::kAllowClose);

		if (exit_reason == kNIMChatRoomExitReasonExit)
			return;

		ChatroomFrontpage* front_page = nim_ui::WindowsManager::GetInstance()->SingletonShow<ChatroomFrontpage>(ChatroomFrontpage::kClassName);
		if (!front_page) return;

		std::wstring kick_tip_str;
		ui::MutiLanSupport *multilan = ui::MutiLanSupport::GetInstance();
		switch (exit_reason)
		{
		case kNIMChatRoomExitReasonKickByManager:
			kick_tip_str = multilan->GetStringViaID(L"STRID_CHATROOM_TIP_KICKED");
			break;
		case kNIMChatRoomExitReasonBeBlacklisted:
			kick_tip_str = multilan->GetStringViaID(L"STRID_CHATROOM_TIP_BLACKLISTED");
			break;
		case kNIMChatRoomExitReasonKickByMultiSpot:
			kick_tip_str = multilan->GetStringViaID(L"STRID_CHATROOM_TIP_MULTIPOT_LOGIN");
			break;
		default:
			QLOG_APP(L"Exit reason: {0}, {1}") << room_id << exit_reason;
			return;
		}

		ui::Box* kicked_tip_box = (ui::Box*)front_page->FindControl(L"kicked_tip_box");
		kicked_tip_box->SetVisible(true);
		nbase::ThreadManager::PostDelayedTask(front_page->ToWeakCallback([kicked_tip_box]() {
			kicked_tip_box->SetVisible(false);
		}), nbase::TimeDelta::FromSeconds(2));

		ui::Label* kick_tip_label = (ui::Label*)kicked_tip_box->FindSubControl(L"kick_tip");
		kick_tip_label->SetText(kick_tip_str);

		ui::Label* room_name_label = (ui::Label*)kicked_tip_box->FindSubControl(L"room_name");
		room_name_label->SetDataID(nbase::Int64ToString16(room_id));
		ChatRoomInfo info = front_page->GetRoomInfo(room_id);
		if (!info.name_.empty())
			room_name_label->SetUTF8Text(info.name_);
		else
			room_name_label->SetText(nbase::StringPrintf(L"直播间(id %lld)", room_id));
	};
	Post2UI(cb);
}
void ChatroomCallback::OnSendMsgCallback(__int64 room_id, int error_code, const ChatRoomMessage& result)
{
	QLOG_APP(L"Chatroom:OnSendMsgCallback: id={0} msg_id={1} code={2}") << result.room_id_ << result.client_msg_id_ << error_code;

	if (error_code != 200)
	{
		StdClosure cb = [=](){
			std::wstring toast = nbase::StringPrintf(L"Send room msg error(%d), content:%s", error_code, nbase::UTF8ToUTF16(result.msg_attach_).c_str());
			nim_ui::ShowToast(toast, 5000);
		};
		Post2UI(cb);
	}
}
void ChatroomCallback::OnRegLinkConditionCallback(__int64 room_id, const NIMChatRoomLinkCondition condition)
{
	QLOG_APP(L"Chatroom:OnRegLinkConditionCallback: id={0} condition={1}") << room_id << condition;

	StdClosure cb = [=](){
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form != NULL)
		{
			chat_form->OnRegLinkConditionCallback(room_id, condition);
		}
	};
	Post2UI(cb);

}
void ChatroomCallback::OnNotificationCallback(__int64 room_id, const ChatRoomNotification& notification)
{
	QLOG_APP(L"Chatroom:OnNotificationCallback: id={0}") << room_id;
	//QLOG_APP(L"Chatroom:OnNotificationCallback: ext : {0}") << notification.ext_;

	StdClosure cb = [=](){
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form != NULL)
		{
			chat_form->OnNotificationCallback(notification);
		}
	};
	Post2UI(cb);
}
void ChatroomCallback::OnReceiveMsgCallback(__int64 room_id, const ChatRoomMessage& result)
{
	QLOG_PRO(L"Chatroom:OnReceiveMsgCallback: {0} from client: {1}") << result.client_msg_id_ << result.from_client_type_;
	//QLOG_PRO(L"Chatroom:OnReceiveMsgCallback ext: {0}") << result.ext_;
	//QLOG_PRO(L"Chatroom:OnReceiveMsgCallback from_ext: {0}") << result.from_ext_;

	StdClosure cb = [=](){
		ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
		if (chat_form != NULL && result.msg_type_ != kNIMChatRoomMsgTypeUnknown)
		{
			chat_form->OnReceiveMsgCallback(result);
		}
	};
	Post2UI(cb);
}
void ChatroomFrontpage::InvokeGetRoomList()
{
	FindControl(L"loading_tip")->SetVisible(true);

	auto http_cb = ToWeakCallback([this](bool ret, int response_code, const std::string& reply)
	{
		StdClosure error_cb = ToWeakCallback([this]()
		{
			FindControl(L"loading_tip")->SetVisible(false);
			FindControl(L"load_error_tip")->SetVisible(true);
		});

		if (!ret || response_code != nim::kNIMResSuccess)
		{
			QLOG_ERR(L"Invoke get room list error. Error code: {0}.") << response_code;
			Post2UI(error_cb);

			return;
		}

		Json::Value json_reply;
		Json::Reader reader;
		if (reader.parse(reply, json_reply) && json_reply.isObject())
		{
			int res = json_reply["res"].asInt();
			if (res != 200)
			{
				QLOG_ERR(L"Invoke get room list error. Json rescode: {0}.") << res;
				Post2UI(error_cb);

				return;
			}

			int count = json_reply["msg"]["total"].asInt();
			Json::Value json_list = json_reply["msg"]["list"];
			if (!json_list.isArray())
			{
				QLOG_ERR(L"Invoke get room list error. Reason: Not an array.");
				Post2UI(error_cb);

				return;
			}

			StdClosure closure = ToWeakCallback([this, json_list, count]() 
			{
				FindControl(L"loading_tip")->SetVisible(false);

				for (int i = 0; i < count; i++)
				{
					ChatRoomInfo info;
					info.id_ = json_list[i]["roomid"].asInt64();
					info.name_ = json_list[i]["name"].asString();
					info.creator_id_ = json_list[i]["creator"].asString();
					nbase::StringToInt(json_list[i]["onlineusercount"].asString(), &info.online_count_);
					info.valid_flag_ = json_list[i]["status"].asInt();
					info.ext_ = json_list[i]["ext"].asString();
					info.announcement_ = json_list[i]["announcement"].asString();
					info.broadcast_url_ = json_list[i]["broadcasturl"].asString();
					id_info_map_[info.id_] = info;

					CreateRoomItem(info);
				}
			});
			Post2UI(closure);
		}
		else
		{
			QLOG_ERR(L"invoke get room list json parse error {0}.") << reply;
			Post2UI(error_cb);
		}
	});

	std::string api_addr = "https://app.netease.im/api/chatroom/homeList";
	std::string new_api_addr = GetConfigValue("kNIMChatRoomAddress");
	if (!new_api_addr.empty())
		api_addr = new_api_addr;

	std::string app_key = "45c6af3c98409b18a84451215d0bdd6e";
	std::string new_app_key = GetConfigValue(g_AppKey);
	if (!new_app_key.empty())
		app_key = new_app_key;
	nim_http::HttpRequest request(api_addr, "", 0, http_cb);
	request.AddHeader("Content-Type", "application/json; charset=utf-8");
	request.AddHeader("appKey", app_key);
	nim_http::PostRequest(request);
}
Example #11
0
void VChatCallback::StartDeviceCb(nim::NIMDeviceType type, bool ret, const char *json, const void*)
{
	auto closure = nbase::Bind(&OnStartDeviceCb, type, ret);
	Post2UI(closure);
}
Example #12
0
void VChatCallback::DeviceStatusCb(nim::NIMDeviceType type, UINT status, const char* path, const char *json, const void *user_data)
{
	std::string device(path);
	auto closure = nbase::Bind(&OnDeviceStatusCb, type, status, device);
	Post2UI(closure);
}
Example #13
0
void TeamService::GetLocalTeamInfoCb(const std::string& tid, const nim::TeamInfo& result)
{
	auto task = nbase::Bind(&TeamService::UIGetLocalTeamInfoCb, this, tid, result);
	Post2UI(task);
}
Example #14
0
void TeamService::QueryAllTeamInfoCb(int team_count, const std::list<nim::TeamInfo>& team_info_list)
{
	auto task = nbase::Bind(&TeamService::UIQueryAllTeamInfoCb, this, team_count, team_info_list);
	Post2UI(task);
}
void ChatroomCallback::OnEnterCallback(__int64 room_id, const NIMChatRoomEnterStep step, int error_code, const ChatRoomInfo& info, const ChatRoomMemberInfo& my_info)
{
	QLOG_APP(L"Chatroom:OnEnterCallback: id={0} step={1} code={2}") << room_id << step << error_code;

	if (step != kNIMChatRoomEnterStepRoomAuthOver)
		return;

	StdClosure cb = [=](){
		if (error_code != nim::kNIMResSuccess && error_code != nim::kNIMResTimeoutError)
		{
			ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
			if (chat_form)
			{
				if (error_code == nim::kNIMResRoomLocalNeedRequestAgain)
				{//重新登录
					chat_form->RequestEnter(room_id);
					return;
				}
				else
					chat_form->Close();
			}

			ChatroomFrontpage* front_page = nim_ui::WindowsManager::GetInstance()->SingletonShow<ChatroomFrontpage>(ChatroomFrontpage::kClassName);
			if (!front_page) return;

			std::wstring kick_tip_str;
			ui::MutiLanSupport *multilan = ui::MutiLanSupport::GetInstance();
			switch (error_code)
			{
			case nim::kNIMResNotExist:
				kick_tip_str = L"聊天室不存在";
				break;
			case nim::kNIMResForbidden:
				kick_tip_str = L"权限问题";
				break;
			case nim::kNIMResRoomLinkError:
			case nim::kNIMResRoomError:
				kick_tip_str = L"聊天室异常";
				break;
			case nim::kNIMResRoomBlackBeOut:
				kick_tip_str = L"黑名单用户禁止进入聊天室";
				break;
			case nim::kNIMResFrequently:
				kick_tip_str = L"操作太频繁,稍后重试";
				break;
			default:
				QLOG_APP(L"enter faled: {0} , {1}") << room_id << error_code;
				return;
			}

			ui::Box* kicked_tip_box = (ui::Box*)front_page->FindControl(L"kicked_tip_box");
			kicked_tip_box->SetVisible(true);
			nbase::ThreadManager::PostDelayedTask(front_page->ToWeakCallback([kicked_tip_box]() {
				kicked_tip_box->SetVisible(false);
			}), nbase::TimeDelta::FromSeconds(2));

			ui::Label* kick_tip_label = (ui::Label*)kicked_tip_box->FindSubControl(L"kick_tip");
			kick_tip_label->SetText(kick_tip_str);

			ui::Label* room_name_label = (ui::Label*)kicked_tip_box->FindSubControl(L"room_name");
			room_name_label->SetDataID(nbase::Int64ToString16(room_id));
			ChatRoomInfo info = front_page->GetRoomInfo(room_id);
			if (!info.name_.empty())
				room_name_label->SetUTF8Text(info.name_);
			else
				room_name_label->SetText(nbase::StringPrintf(L"直播间(id %lld)", room_id));
		}
		else
		{
			ChatroomForm* chat_form = static_cast<ChatroomForm*>(nim_ui::WindowsManager::GetInstance()->GetWindow(ChatroomForm::kClassName, nbase::Int64ToString16(room_id)));
			if (chat_form != NULL)
				chat_form->OnEnterCallback(error_code, info, my_info);
		}
	};
	Post2UI(cb);
}
Example #16
0
void VChatCallback::VChatCb(nim::NIMVideoChatSessionType type, __int64 channel_id, int code, const char *json, const void*)
{
	std::string json_temp(json);
	auto closure = nbase::Bind(&OnVChatCb, type, channel_id, code, json_temp);
	Post2UI(closure);
}
Example #17
0
void AudioCallback::OnStopAudioCallback( int code, const char* file_path, const char* sid, const char* cid )
{
	QLOG_APP(L"OnStopAudioCallback: sid={0} cid={1} code={2}") <<sid <<cid <<code;
	Post2UI( nbase::Bind(&UIStopAudioCallback, code, std::string(sid), std::string(cid)) );
}