| | |
| | | package org.springblade.modules.webscoket.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.group.ChannelGroup; |
| | | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
| | |
| | | import org.springblade.modules.webscoket.service.IPushMsgService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author lq |
| | | * @date 2020/4/1 11:20 |
| | | */ |
| | | @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(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("xqid", msg); |
| | | jsonObject.put("type", "taks"); |
| | | System.out.println("空间大小:" + group.size() + ",名字:" + name); |
| | | group.writeAndFlush(new TextWebSocketFrame(String.valueOf(jsonObject))); |
| | | } |
| | | |
| | | @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 int startTask(String serid, String rid,String type,String data) { |
| | | //返回值 |
| | | int res = 0; |
| | | String[] list = serid.split(","); |
| | | for (int i = 0; i <list.length ; i++) { |
| | | if (!list[i].equals("")){ |
| | | Channel channel = NettyConfig.getUserChannelMap().get(list[i]); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("type", type); |
| | | jsonObject.put("rid", rid); |
| | | jsonObject.put("data", data); |
| | | 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))); |
| | | } |
| | | |
| | | } |
| | | } |