zhibing.pu
2024-08-21 f10ef4933c6decda69308c1cf6e4d0449856ba1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.ruoyi.other.controller;
 
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.webSocket.NettyChannelMap;
import com.ruoyi.other.webSocket.NettyWebSocketController;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.web.bind.annotation.*;
 
/**
 * @author zhibing.pu
 * @Date 2024/8/21 17:31
 */
@RestController
@RequestMapping("/webSocket")
public class WebSocketController {
    
    
    /**
     * 发送websocket消息
     * @param userId
     * @param msg
     * @return
     */
    @ResponseBody
    @PostMapping("/send")
    public R send(@RequestParam("userId") Long userId, @RequestParam("msg") String msg){
        ChannelHandlerContext channel = NettyChannelMap.getData("Applets" + userId);
        return NettyWebSocketController.sendMsgToClient(channel, msg);
    }
    
}