Search in sources :

Example 6 with ChannelSession

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;
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 7 with ChannelSession

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;
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 8 with ChannelSession

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;
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) ImCtsMessageProto(com.akaxin.proto.site.ImCtsMessageProto) GroupMessageBean(com.akaxin.site.storage.bean.GroupMessageBean)

Example 9 with ChannelSession

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();
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) HashMap(java.util.HashMap) ImMessageService(com.akaxin.site.message.service.ImMessageService) RedisCommand(com.akaxin.common.command.RedisCommand)

Example 10 with ChannelSession

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());
    }
}
Also used : ChannelSession(com.akaxin.common.channel.ChannelSession) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

ChannelSession (com.akaxin.common.channel.ChannelSession)16 ImCtsMessageProto (com.akaxin.proto.site.ImCtsMessageProto)8 GroupMessageBean (com.akaxin.site.storage.bean.GroupMessageBean)6 InetSocketAddress (java.net.InetSocketAddress)4 U2MessageBean (com.akaxin.site.storage.bean.U2MessageBean)3 ByteString (com.google.protobuf.ByteString)3 RedisCommand (com.akaxin.common.command.RedisCommand)2 ImSyncMessageProto (com.akaxin.proto.site.ImSyncMessageProto)2 Command (com.akaxin.common.command.Command)1 CommandResponse (com.akaxin.common.command.CommandResponse)1 CoreProto (com.akaxin.proto.core.CoreProto)1 ImSiteHelloProto (com.akaxin.proto.site.ImSiteHelloProto)1 ImMessageService (com.akaxin.site.message.service.ImMessageService)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1