use of com.akaxin.common.channel.ChannelSession in project openzaly by akaxincom.
the class GroupMessageImageHandler method handle.
public Boolean handle(Command command) {
ChannelSession channelSession = command.getChannelSession();
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.GROUP_IMAGE_VALUE == type) {
String siteUserId = command.getSiteUserId();
String deviceId = command.getDeviceId();
String gmsgId = request.getGroupImage().getMsgId();
String groupId = request.getGroupImage().getSiteGroupId();
String groupImageId = request.getGroupImage().getImageId();
long msgTime = System.currentTimeMillis();
GroupMessageBean gmsgBean = new GroupMessageBean();
gmsgBean.setMsgId(gmsgId);
gmsgBean.setSendUserId(siteUserId);
gmsgBean.setSendDeviceId(deviceId);
gmsgBean.setSiteGroupId(groupId);
gmsgBean.setContent(groupImageId);
gmsgBean.setMsgType(type);
gmsgBean.setMsgTime(msgTime);
LogUtils.requestDebugLog(logger, command, gmsgBean.toString());
boolean success = messageDao.saveGroupMessage(gmsgBean);
msgStatusResponse(command, gmsgId, msgTime, success);
return success;
}
return true;
} catch (Exception e) {
LogUtils.requestErrorLog(logger, command, this.getClass(), e);
}
return false;
}
use of com.akaxin.common.channel.ChannelSession in project openzaly by akaxincom.
the class GroupMessageImageSecretHandler method handle.
public Boolean handle(Command command) {
ChannelSession channelSession = command.getChannelSession();
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.GROUP_SECRET_TEXT_VALUE == type) {
String siteUserId = command.getSiteUserId();
String deviceId = command.getDeviceId();
// String group_user_id = request.getGroupSecretText().getSiteUserId();
String gmsg_id = request.getGroupSecretText().getMsgId();
String group_id = request.getGroupSecretText().getSiteGroupId();
String group_text = request.getGroupSecretText().getText().toStringUtf8();
command.setSiteGroupId(group_id);
// command.setField("group_id", group_id);
System.out.println("GroupMsg = id=" + gmsg_id + "," + siteUserId + "," + group_id + "," + group_text + ",");
long msgTime = System.currentTimeMillis();
GroupMessageBean gmsgBean = new GroupMessageBean();
gmsgBean.setSendDeviceId(deviceId);
gmsgBean.setMsgTime(msgTime);
messageDao.saveGroupMessage(gmsgBean);
msgResponse(channelSession.getChannel(), command, siteUserId, group_id, gmsg_id, msgTime);
return true;
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of com.akaxin.common.channel.ChannelSession in project openzaly by akaxincom.
the class GroupMessageTextHandler method handle.
public Boolean handle(Command command) {
ChannelSession channelSession = command.getChannelSession();
try {
ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest.parseFrom(command.getParams());
int type = request.getType().getNumber();
if (CoreProto.MsgType.GROUP_TEXT_VALUE == type) {
String siteUserId = command.getSiteUserId();
String deviceId = command.getDeviceId();
String gmsgId = request.getGroupText().getMsgId();
String groupId = request.getGroupText().getSiteGroupId();
String groupText = request.getGroupText().getText().toStringUtf8();
long msgTime = System.currentTimeMillis();
GroupMessageBean gmsgBean = new GroupMessageBean();
gmsgBean.setMsgId(gmsgId);
gmsgBean.setSendUserId(siteUserId);
gmsgBean.setSendDeviceId(deviceId);
gmsgBean.setSiteGroupId(groupId);
gmsgBean.setContent(groupText);
gmsgBean.setMsgType(type);
gmsgBean.setMsgTime(msgTime);
LogUtils.requestDebugLog(logger, command, gmsgBean.toString());
boolean success = messageDao.saveGroupMessage(gmsgBean);
msgStatusResponse(command, gmsgId, msgTime, success);
return success;
}
return true;
} catch (Exception e) {
LogUtils.requestErrorLog(logger, command, this.getClass(), e);
}
return false;
}
use of com.akaxin.common.channel.ChannelSession in project openzaly by akaxincom.
the class ImMessageHandler method handle.
public CommandResponse handle(Command command) {
try {
ChannelSession channelSession = command.getChannelSession();
String deviceId = channelSession.getDeviceId();
if (StringUtils.isEmpty(deviceId)) {
channelSession.getChannel().close();
logger.error("{} client={} im request error with deviceId={}.", AkxProject.PLN, command.getClientIp(), deviceId);
return customResponse(ErrorCode2.ERROR);
}
ChannelSession acsession = ChannelManager.getChannelSession(deviceId);
if (acsession == null) {
channelSession.getChannel().close();
logger.error("{} client={} im request error with channelSession={}", AkxProject.PLN, command.getClientIp(), acsession);
return customResponse(ErrorCode2.ERROR);
}
if (!checkSiteUserId(command.getSiteUserId(), acsession.getUserId())) {
channelSession.getChannel().close();
logger.error("{} client={} im request fail siteUserId={},sessionUserId={}", AkxProject.PLN, command.getClientIp(), command.getSiteUserId(), acsession.getUserId());
return customResponse(ErrorCode2.ERROR);
}
if (RequestAction.IM_CTS_PING.getName().equalsIgnoreCase(command.getAction())) {
Map<Integer, String> header = new HashMap<Integer, String>();
header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
CoreProto.TransportPackageData.Builder packBuilder = CoreProto.TransportPackageData.newBuilder();
packBuilder.putAllHeader(header);
channelSession.getChannel().writeAndFlush(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(RequestAction.IM_STC_PONG.getName()).add(packBuilder.build().toByteArray()));
// 检测是否需要给用户发送PSN
if (channelSession.detectPsn()) {
channelSession.getChannel().writeAndFlush(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(RequestAction.IM_STC_PSN.getName()).add(packBuilder.build().toByteArray()));
logger.debug("{} client={} siteUserId={} deviceId={} push psn {} {}", AkxProject.PLN, command.getClientIp(), command.getSiteUserId(), command.getDeviceId(), channelSession.getPsnTime(), channelSession.getSynFinTime());
}
} else {
// 排除ping请求,其他请求走im服务
new ImMessageService().execute(command);
}
return customResponse(ErrorCode2.SUCCESS);
} catch (Exception e) {
logger.error(StringHelper.format("{} client={} im request error.", AkxProject.PLN, command.getClientIp()), e);
}
return defaultErrorResponse();
}
use of com.akaxin.common.channel.ChannelSession in project openzaly by akaxincom.
the class NettyServerHandler method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
String clientIp = socketAddress.getAddress().getHostAddress();
logger.debug("{} client={} close connection... ChannelSize={}", AkxProject.PLN, clientIp, ChannelManager.getChannelSessionSize());
ChannelSession channelSession = ctx.channel().attr(ParserConst.CHANNELSESSION).get();
if (channelSession.getCtype() == 1 && StringUtils.isNotEmpty(channelSession.getUserId())) {
ChannelManager.delChannelSession(channelSession.getDeviceId());
String siteUserId = channelSession.getUserId();
String deviceId = channelSession.getDeviceId();
boolean offRes = SessionManager.getInstance().setUserOffline(siteUserId, deviceId);
logger.debug("{} set client={} siteUserId={} deviceId={} offline-status:{} ChannelSize={}", AkxProject.PLN, clientIp, siteUserId, deviceId, offRes, ChannelManager.getChannelSessionSize());
}
}
Aggregations