| | |
| | | System.out.println("客户端断开连接:" + ctx.channel()); |
| | | //用户离线状态 |
| | | String name = ChannelSupervise.findName(ctx.channel().id().asShortText()); |
| | | System.out.println(name); |
| | | if ( name != null &&!name.equals("ping") ){ |
| | | NettyConfig.getChannelGroup().remove(ctx.channel()); |
| | | removeUserId(ctx); |
| | |
| | | @RequestMapping("pushMsg") |
| | | public class PushMsgController { |
| | | |
| | | @Autowired |
| | | private IPushMsgService pushMsgService; |
| | | @Autowired |
| | | private IPushMsgService pushMsgService; |
| | | |
| | | @PostMapping("/pushUser") |
| | | public String pushUser(String userId,String msg){ |
| | | pushMsgService.pushMsg(userId, msg); |
| | | return "消息发送成功:"+msg; |
| | | } |
| | | @PostMapping("/pushUser") |
| | | public String pushUser(String userId, String msg) { |
| | | pushMsgService.pushMsg(userId, msg); |
| | | return "消息发送成功:" + msg; |
| | | } |
| | | |
| | | @PostMapping("/pushAll") |
| | | public String pushAll(String msg){ |
| | | pushMsgService.pushMsg(msg); |
| | | return "消息发送成功:"+msg; |
| | | } |
| | | @PostMapping("/pushAll") |
| | | public String pushAll(String msg) { |
| | | pushMsgService.pushMsg(msg); |
| | | return "消息发送成功:" + msg; |
| | | } |
| | | |
| | | @GetMapping("/inviteVideoCall") |
| | | public R<Map> inviteVideoCall(String userId,String type){ |
| | | //获取当前时间戳作为房间号 |
| | | @GetMapping("/inviteVideoCall") |
| | | public R<Map> inviteVideoCall(String userId, String type, String name,String faqiid) { |
| | | //获取当前时间戳作为房间号 |
| | | String roomId = ""; |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | String time = String.valueOf(new Date().getTime()); |
| | | int msg = pushMsgService.inviteVideoCall(userId,time,type); |
| | | map.put("type",type); |
| | | map.put("roomId",time); |
| | | map.put("res",0); |
| | | int msg = pushMsgService.inviteVideoCall(userId, time, type, name,faqiid); |
| | | map.put("type", type); |
| | | map.put("roomId", time); |
| | | map.put("res", msg); |
| | | |
| | | return R.data(map); |
| | | } |
| | | |
| | | @GetMapping("/closeVideoCall") |
| | | public void closeVideoCall(String sentId, String acceptId) { |
| | | |
| | | pushMsgService.closeVideoCall(sentId, acceptId); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public interface IPushMsgService { |
| | | |
| | | /** |
| | | * 给指定用户发送消息 |
| | | * @param userId |
| | | * @param msg |
| | | */ |
| | | void pushMsg(String userId,String msg); |
| | | /** |
| | | * 给指定用户发送消息 |
| | | * |
| | | * @param userId |
| | | * @param msg |
| | | */ |
| | | void pushMsg(String userId, String msg); |
| | | |
| | | /** |
| | | * 给所有用户发送消息 |
| | | * @param msg |
| | | */ |
| | | void pushMsg(String msg); |
| | | /** |
| | | * 给所有用户发送消息 |
| | | * |
| | | * @param msg |
| | | */ |
| | | void pushMsg(String msg); |
| | | |
| | | /** |
| | | * 给指定用户发起视频邀请 |
| | | */ |
| | | int inviteVideoCall(String userid,String time,String type); |
| | | int inviteVideoCall(String userid, String time, String type, String name,String faqiid); |
| | | |
| | | /** |
| | | * 关闭视频请求 |
| | | * |
| | | * @return |
| | | */ |
| | | void closeVideoCall(String sentId, String acceptId); |
| | | |
| | | } |
| | |
| | | */ |
| | | @Service |
| | | public class PushMsgServiceImpl implements IPushMsgService { |
| | | @Override |
| | | public void pushMsg(String userId, String msg) { |
| | | Channel channel = NettyConfig.getUserChannelMap().get(userId); |
| | | if (channel != null){ |
| | | @Override |
| | | public void pushMsg(String userId, String msg) { |
| | | Channel channel = NettyConfig.getUserChannelMap().get(userId); |
| | | if (channel != null) { |
| | | channel.writeAndFlush(new TextWebSocketFrame(msg)); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void pushMsg(String msg) { |
| | | ChannelGroup group = NettyConfig.getChannelGroup(); |
| | | String name = group.name(); |
| | | System.out.println("空间大小:"+group.size()+",名字:"+name); |
| | | group.writeAndFlush(new TextWebSocketFrame(msg)); |
| | | } |
| | | @Override |
| | | public void pushMsg(String msg) { |
| | | ChannelGroup group = NettyConfig.getChannelGroup(); |
| | | String name = group.name(); |
| | | System.out.println("空间大小:" + group.size() + ",名字:" + name); |
| | | group.writeAndFlush(new TextWebSocketFrame(msg)); |
| | | } |
| | | |
| | | @Override |
| | | public int inviteVideoCall(String userId,String time,String type) { |
| | | //返回值 |
| | | @Override |
| | | public int inviteVideoCall(String userId, String time, String type, String name,String faqiid) { |
| | | //返回值 |
| | | int res = 0; |
| | | Channel channel = NettyConfig.getUserChannelMap().get(userId); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("type",type); |
| | | jsonObject.put("roomId",time); |
| | | if (channel != null){ |
| | | jsonObject.put("type", type); |
| | | jsonObject.put("roomId", time); |
| | | jsonObject.put("name", name); |
| | | jsonObject.put("faqiid", faqiid); |
| | | if (channel != null) { |
| | | channel.writeAndFlush(new TextWebSocketFrame(String.valueOf(jsonObject))); |
| | | res = 1; |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | @Override |
| | | public void closeVideoCall(String sentId, String acceptId) { |
| | | Channel channel1 = NettyConfig.getUserChannelMap().get(sentId); |
| | | Channel channel2 = NettyConfig.getUserChannelMap().get(acceptId); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("type", "close"); |
| | | if (channel1 != null) { |
| | | channel1.writeAndFlush(new TextWebSocketFrame(String.valueOf(jsonObject))); |
| | | } |
| | | if (channel2 != null) { |
| | | channel2.writeAndFlush(new TextWebSocketFrame(String.valueOf(jsonObject))); |
| | | } |
| | | |
| | | } |
| | | } |