{"id":13470,"date":"2025-04-18T20:27:24","date_gmt":"2025-04-18T12:27:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/13470.html"},"modified":"2025-04-18T20:27:24","modified_gmt":"2025-04-18T12:27:24","slug":"%e6%90%ad%e5%bb%ba%e4%bf%a1%e4%bb%a4%e6%9c%8d%e5%8a%a1%e5%99%a8-springboot%e7%ae%80%e5%8d%95%e4%bd%bf%e7%94%a8webrtc%ef%bc%88%e5%90%8e%e7%ab%af%e7%af%87%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/13470.html","title":{"rendered":"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668---SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09"},"content":{"rendered":"<h2>\u524d\u7aef\u7bc7\u5728\u8fd9<\/h2>\n<h2>\u5176\u5b9e\u540e\u7aef\u7684\u5b9e\u73b0\u8fd8\u6bd4\u8f83\u5bb9\u6613&#xff0c;\u5c31\u662f\u914d\u5408\u524d\u7aef\u8fdb\u884c\u6570\u636e\u7684\u4f20\u9012<\/h2>\n<p>\u5176\u5b9e\u73b0\u4e5f\u5c31\u662f\u8ddf\u4f7f\u7528SpringBoot\u5b9e\u73b0WebSocket\u4e00\u6837&#xff0c;\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8bf4&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u672c\u6765\u5c31\u662f<span style=\"color:#fe2c24\">\u57fa\u4e8eWebSocket\u8fdb\u884cWebRTC\u8fde\u63a5<\/span>\u7684&#xff0c;\u6240\u4ee5\u540e\u7aef\u5c31\u662f\u5b9e\u73b0\u4e00\u4e2aWebSocket\u670d\u52a1\u5373\u53ef&#xff0c;\u4ed6\u5c31\u662f\u6211\u4eec\u524d\u7aef\u7bc7\u6240\u8bf4\u7684<span style=\"color:#fe2c24\">\u4fe1\u4ee4\u670d\u52a1\u5668<\/span>\u4e86<\/p>\n<hr \/>\n<h2>\u672c\u6b21\u4f7f\u7528\u9700\u8981\u7684\u4f9d\u8d56&#xff08;\u9664\u53bbSpringBoot\u7684Web\u9879\u76ee\u6240\u5fc5\u987b\u7684\u4f9d\u8d56\u5916&#xff09;<\/h2>\n<p>&lt;!&#8211;        websocket&#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;spring-boot-starter-websocket&lt;\/artifactId&gt;<br \/>\n        &lt;\/dependency&gt;<br \/>\n&lt;!&#8211;        JSON\u5904\u7406\u5de5\u5177&#8211;&gt;<br \/>\n        &lt;dependency&gt;<br \/>\n            &lt;groupId&gt;com.alibaba&lt;\/groupId&gt;<br \/>\n            &lt;artifactId&gt;fastjson&lt;\/artifactId&gt;<br \/>\n            &lt;version&gt;1.2.79&lt;\/version&gt;<br \/>\n        &lt;\/dependency&gt;<\/p>\n<h2>\u9996\u5148\u5148\u6765\u5b9e\u73b0\u4e00\u4e0b\u524d\u7aef\u7684\u767b\u5f55\u63a5\u53e3<\/h2>\n<p>\u5728\u524d&#xff0c;\u6211\u4eec\u524d\u7aef\u767b\u5f55\u7684\u65f6\u5019\u5c31\u53d1\u9001\u4e86\u4e00\u4e2a\u8bf7\u6c42\u7ed9\u6211\u4eec\u7684\u540e\u7aef\u63a5\u53e3&#xff0c;\u5373http:\/\/localhost:8080\/user\/login<\/p>\n<p>\u73b0\u5728\u6765\u770b\u540e\u7aef\u6765\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;\u9996\u5148\u9700\u8981\u4e00\u4e2aUser\u7c7b\u6765\u63a5\u6536\u524d\u7aef\u4f20\u6765\u7684\u53c2\u6570<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418122723-6802452b37c82.png\" \/><\/p>\n<p>package org.xwx.videodemo.pojo;<\/p>\n<p>import lombok.Data;<\/p>\n<p>\/\/ \u8fd9\u4e2a\u7c7b\u7528\u4e8e\u63cf\u8ff0\u7528\u6237\u4fe1\u606f<br \/>\n&#064;Data<br \/>\npublic class User {<br \/>\n    private String username;<br \/>\n    private String password;<br \/>\n}<\/p>\n<p>\u4e00\u4e2a\u7ed3\u679c\u7c7b\u6765\u8fd4\u56de\u7ed9\u524d\u7aef&#xff1a;<\/p>\n<p>package org.xwx.videodemo.pojo;<\/p>\n<p>import lombok.Data;<\/p>\n<p>\/**<br \/>\n * \u8fd9\u4e2a\u7c7b\u4e3b\u8981\u7528\u4e8e\u5904\u7406\u5904\u7406\u767b\u5f55\u65f6\u7684\u8fd4\u56de\u7ed3\u679c<br \/>\n *\/<br \/>\n&#064;Data<br \/>\npublic class Result {<br \/>\n    \/\/ \u6807\u5fd7\u4f4d&#xff1a;true \u8868\u793a\u6210\u529f&#xff0c;false \u8868\u793a\u5931\u8d25<br \/>\n    private boolean flag;<br \/>\n    \/\/ \u63cf\u8ff0\u4fe1\u606f<br \/>\n    private String message;<\/p>\n<p>    public Result(boolean flag, String message) {<br \/>\n        this.flag &#061; flag;<br \/>\n        this.message &#061; message;<br \/>\n    }<\/p>\n<p>    public static Result success(String message) {<br \/>\n        return new Result(true,message);<br \/>\n    }<\/p>\n<p>    public static Result failed() {<br \/>\n        return new Result(false,&#034;\u5931\u8d25&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>(2)\u6765\u5230\u63a7\u5236\u5c42\u5904\u7406\u8bf7\u6c42&#xff0c;\u6211\u8fd9\u91cc\u5c31\u968f\u4fbf\u5199\u4e00\u4e2a\u6821\u9a8c&#xff0c;\u53ea\u8981\u7528\u6237\u540d\u4e0d\u4e3a\u7a7a\u5373\u53ef&#xff01;&#xff08;\u56e0\u4e3a\u7528\u6237\u540d\u6bd4\u8f83\u91cd\u8981&#xff09;\u628a\u6821\u9a8c\u5b8c\u7684\u7528\u6237\u540d\u653e\u5230httpSession\u4e2d\u53d1\u7ed9\u524d\u7aef&#xff0c;\u4e4b\u540e\u7684\u8bf7\u6c42\u90fd\u4f1a\u643a\u5e26\u8fd9\u4e2aSession&#xff0c;\u4ee5\u4fbf\u6211\u4eec\u6765\u83b7\u53d6\u672c\u6b21\u8bf7\u6c42\u7684\u7528\u6237\u662f\u8c01\u3002\u4e5f\u6709\u8981\u6ce8\u610f\u70b9!!!<\/p>\n<p>package org.xwx.videodemo.controller;<\/p>\n<p>import org.springframework.web.bind.annotation.PostMapping;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RestController;<br \/>\nimport org.xwx.videodemo.pojo.Result;<br \/>\nimport org.xwx.videodemo.pojo.User;<\/p>\n<p>import javax.servlet.http.HttpSession;<\/p>\n<p>&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class UserController {<\/p>\n<p>    &#064;PostMapping(&#034;\/login&#034;)<br \/>\n    public Result login(User user, HttpSession httpSession) {<br \/>\n        if(user&#061;&#061;null||user.getUsername()&#061;&#061;null)return Result.failed();<br \/>\n        \/\/\u8fd9\u4e00\u6b65\u975e\u5e38\u91cd\u8981&#xff01;&#xff01;&#xff0c;\u4e0d\u7136\u540e\u9762\u6709\u4e00\u4e2a\u5730\u65b9\u4f1a\u83b7\u53d6httpSession\u4e3aNULL<br \/>\n        httpSession.setAttribute(&#034;user&#034;,user.getUsername());<\/p>\n<p>        return Result.success(&#034;\u767b\u5f55\u6210\u529f&#xff01;&#034;);<\/p>\n<p>    }<br \/>\n}<\/p>\n<h2><span style=\"color:#fe2c24\">\u5230\u6b64&#xff0c;\u7528\u6237\u7684\u767b\u5f55\u63a5\u53e3\u5c31\u5b8c\u6210\u4e86&#xff01;&#xff01;&#xff01;<\/span><\/h2>\n<h2>\u4e0b\u9762\u6211\u4eec\u5c06\u6765\u5f00\u59cb\u642d\u5efaWebSocket&#xff01;<\/h2>\n<h3>1\u3001\u8981\u5b9a\u4e49\u4e00\u4e2aWebSocket\u7684\u914d\u7f6e\u7c7b<\/h3>\n<p>\u5728Java\u4e2d\u4f7f\u7528Spring\u6846\u67b6\u7f16\u5199\u7684\u4e0b\u9762\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u914d\u7f6e\u7c7bWebSocketConfig&#xff0c;\u5b83\u914d\u7f6e\u4e86WebSocket\u670d\u52a1\u7aef\u70b9&#xff08;ServerEndpoint&#xff09;\u7684\u5bfc\u51fa\u5668\u3002\u00a0<\/p>\n<p>\u5177\u4f53\u6765\u8bf4&#xff1a;<\/p>\n<ul>\n<li>\n<p>&#064;Configuration\u6ce8\u89e3\u8868\u793a\u8fd9\u4e2a\u7c7b\u662f\u4e00\u4e2a\u914d\u7f6e\u7c7b&#xff0c;\u5728Spring\u5e94\u7528\u542f\u52a8\u65f6\u4f1a\u52a0\u8f7d\u5e76\u6267\u884c\u5176\u4e2d\u7684\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>&#064;Bean\u6ce8\u89e3\u7528\u4e8e\u544a\u8bc9Spring&#xff0c;\u4e0b\u9762\u7684\u65b9\u6cd5\u5c06\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u8fd9\u4e2a\u5bf9\u8c61\u5e94\u8be5\u88ab\u6ce8\u518c\u5230Spring\u7684\u4e0a\u4e0b\u6587\u4e2d&#xff0c;\u4f7f\u5f97\u5176\u4ed6\u9700\u8981\u5b83\u7684\u5730\u65b9\u53ef\u4ee5\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u6765\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>serverEndpointExporter()\u65b9\u6cd5\u521b\u5efa\u5e76\u8fd4\u56de\u4e86\u4e00\u4e2aServerEndpointExporter\u7684\u5b9e\u4f8b\u3002ServerEndpointExporter\u662fSpring\u7528\u4e8e\u626b\u63cf\u548c\u6ce8\u518c\u6240\u6709\u4f7f\u7528&#064;ServerEndpoint\u6ce8\u89e3\u7684\u7c7b\u7684\u7ec4\u4ef6\u3002\u7b80\u5355\u6765\u8bf4&#xff0c;\u8fd9\u4e2aBean\u786e\u4fdd\u4e86\u4efb\u4f55\u6807\u6ce8\u4e3a&#064;ServerEndpoint\u7684\u7c7b\u90fd\u4f1a\u88ab\u8bc6\u522b\u5e76\u6ce8\u518c\u4e3aWebSocket\u7aef\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7b80\u800c\u8a00\u4e4b&#xff0c;WebSocketConfig\u7c7b\u7684\u4f5c\u7528\u662f\u542f\u7528Spring\u5bf9WebSocket\u7aef\u70b9\u7684\u652f\u6301&#xff0c;\u8fd9\u6837\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5c31\u53ef\u4ee5\u5904\u7406WebSocket\u8fde\u63a5\u4e86\u3002\u5f53\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6&#xff0c;Spring\u5c06\u4f1a\u626b\u63cf\u9879\u76ee\u4e2d\u6240\u6709\u7684&#064;ServerEndpoint\u6ce8\u89e3\u7684\u7c7b&#xff0c;\u5e76\u5c06\u5b83\u4eec\u4f5c\u4e3aWebSocket\u7aef\u70b9\u8fdb\u884c\u6ce8\u518c&#xff0c;\u5373\u6807\u8bc6\u8fd9\u4e9b\u7c7b\u6765\u5904\u7406\u524d\u7aef\u53d1\u6765\u7684WebSocket\u8bf7\u6c42\u3002<\/p>\n<p>package org.xwx.videodemo.config;<\/p>\n<p>import org.springframework.context.annotation.Bean;<br \/>\nimport org.springframework.context.annotation.Configuration;<br \/>\nimport org.springframework.web.socket.server.standard.ServerEndpointExporter;<\/p>\n<p>&#064;Configuration<br \/>\npublic class WebSocketConfig {<br \/>\n    &#064;Bean<br \/>\n    public ServerEndpointExporter serverEndpointExporter() {<br \/>\n        return new ServerEndpointExporter();<br \/>\n    }<br \/>\n}<\/p>\n<h3>2\u3001\u8981\u8ba9WebSocket\u4f1a\u8bdd\u4e2d\u6709httpSession\u6765\u83b7\u53d6\u7528\u6237\u6570\u636e<\/h3>\n<p>\u5728\u767b\u5f55\u63a5\u53e3\u6211\u4eec\u5df2\u7ecf\u628a\u7528\u6237\u7684\u4fe1\u606f\u5b58\u5230\u4e86httpSession\u4e2d\u4e86&#xff0c;\u4e4b\u540e\u7684\u6bcf\u6b21\u7684http\u8bf7\u6c42\u90fd\u4f1a\u643a\u5e26\u8fd9\u4e2ahttpSession\u3002\u56e0\u4e3a\u6211\u4eec\u8bbe\u7f6e\u4e86\u3002<\/p>\n<p>        \/\/\u8fd9\u4e00\u6b65\u975e\u5e38\u91cd\u8981&#xff01;&#xff01;&#xff0c;\u4e0d\u7136\u540e\u9762\u6709\u4e00\u4e2a\u5730\u65b9\u4f1a\u83b7\u53d6httpSession\u4e3aNULL<br \/>\n        httpSession.setAttribute(&#034;user&#034;,user.getUsername()); <\/p>\n<p><span style=\"color:#fe2c24\">\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e&#xff0c;\u540e\u9762\u8981\u83b7\u53d6\u8fd9\u4e2ahttpSession\u7684\u65f6\u5019\u5c31\u4f1a\u83b7\u53d6\u5230NULL\u503c<\/span><\/p>\n<p><span style=\"color:#4da8ee\">\u4f46\u662f\u53ea\u662f\u5728http\u8bf7\u6c42\u80fd\u83b7\u53d6\u5230httpSession&#xff0c;\u53ef\u662f\u540e\u9762\u5efa\u7acb\u4e86WebSocket\u8fde\u63a5\u540e\u6211\u4eec\u7684\u8bf7\u6c42\u90fd\u662f\u57fa\u4e8eWebSocket\u534f\u8bae\u7684&#xff0c;\u4e0d\u662fHTTP\u534f\u8bae&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u5982\u679c\u4e0d\u8fdb\u884c\u4e00\u4e9b\u5176\u4ed6\u7684\u64cd\u4f5c&#xff0c;\u6211\u4eec\u540e\u9762\u7528WebSocket\u8fdb\u884c\u901a\u4fe1\u7684\u65f6\u5019\u5c31\u65e0\u6cd5\u83b7\u53d6httpSession&#xff0c;\u5373\u83b7\u53d6\u4e0d\u5230\u6211\u4eec\u767b\u5f55\u7684\u65f6\u5019\u5b58\u7684\u7528\u6237\u4fe1\u606f\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6765\u505a\u4ee5\u4e0b\u7684\u64cd\u4f5c&#xff1a;<\/span><\/p>\n<h4><span style=\"color:#0d0016\">2.1\u600e\u4e48\u5728WebSocket\u4f1a\u8bdd\u4e2d\u600e\u4e48\u83b7\u53d6\u5230\u8fd9\u4e2ahttpSession\u5462&#xff1f;<\/span><\/h4>\n<p><span style=\"color:#0d0016\">\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u5bf9WebSocket\u521d\u59cb\u8fde\u63a5\u7684\u65f6\u5019\u8fdb\u884c\u4e00\u4e9b\u914d\u7f6e&#xff1a;<\/span><\/p>\n<p>package org.xwx.videodemo.ws;<\/p>\n<p>import javax.servlet.http.HttpSession;<br \/>\nimport javax.websocket.HandshakeResponse;<br \/>\nimport javax.websocket.server.HandshakeRequest;<br \/>\nimport javax.websocket.server.ServerEndpointConfig;<br \/>\npublic class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {<\/p>\n<p>    &#064;Override<br \/>\n    public void modifyHandshake(ServerEndpointConfig  sec, HandshakeRequest request, HandshakeResponse response) {<br \/>\n            \/\/ \u83b7\u53d6httpsession\u5bf9\u8c61<br \/>\n            HttpSession httpSession &#061; (HttpSession) request.getHttpSession();<br \/>\n            \/\/\u5c06\u4ecehttp\u8bf7\u6c42\u83b7\u53d6\u5230\u7684httpSession\u5b58\u5230WebSocket\u670d\u52a1\u7aef\u70b9\u4e2d<br \/>\n            \/\/ \u8fd9\u6837\u540e\u9762\u5c31\u53ef\u4ee5\u901a\u8fc7EndpointConfig\u6765\u83b7\u53d6\u8fd9\u4e2ahttpSession<br \/>\n            sec.getUserProperties().put(HttpSession.class.getName(), httpSession);<\/p>\n<p>    }<br \/>\n}<\/p>\n<p>\u521b\u5efa\u4e00\u4e2aGetHttpSessionConfigurator\u00a0\u7c7b\u7ee7\u627f\u81ea\u00a0ServerEndpointConfig.Configurator&#xff0c;\u5e76\u91cd\u5199\u4e86\u00a0modifyHandshake\u00a0\u65b9\u6cd5\u3002\u8fd9\u4e2a\u7c7b\u7684\u4f5c\u7528\u662f\u5728WebSocket\u63e1\u624b&#xff08;handshake&#xff09;\u8fc7\u7a0b\u4e2d\u4fee\u6539\u914d\u7f6e&#xff0c;\u5e76\u5141\u8bb8\u8bbf\u95eeWebSocket\u4f1a\u8bdd\u7684HTTP\u4f1a\u8bdd&#xff08;HttpSession&#xff09;\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\u7684\u5177\u4f53\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\n<p>modifyHandshake\u00a0\u65b9\u6cd5\u4f1a\u5728WebSocket\u63e1\u624b\u9636\u6bb5\u88ab\u8c03\u7528&#xff0c;\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u5bf9\u63e1\u624b\u8bf7\u6c42\u548c\u54cd\u5e94\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<\/li>\n<li>\n<p>ServerEndpointConfig sec\u00a0\u53c2\u6570\u4ee3\u8868WebSocket\u7aef\u70b9\u7684\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>HandshakeRequest request\u00a0\u53c2\u6570\u5305\u542b\u4e86\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u63e1\u624b\u8bf7\u6c42\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>HandshakeResponse response\u00a0\u53c2\u6570\u4ee3\u8868\u4e86\u670d\u52a1\u5668\u7aef\u5c06\u8981\u53d1\u9001\u7684\u63e1\u624b\u54cd\u5e94\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u00a0modifyHandshake\u00a0\u65b9\u6cd5\u4e2d&#xff0c;\u4ee5\u4e0b\u662f\u5173\u952e\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u4ece\u00a0HandshakeRequest\u00a0\u5bf9\u8c61\u4e2d\u83b7\u53d6\u00a0HttpSession\u00a0\u5bf9\u8c61\u3002\u8fd9\u4e2a\u00a0HttpSession\u00a0\u5bf9\u8c61\u662fHTTP\u4f1a\u8bdd\u7684\u4e00\u90e8\u5206&#xff0c;\u5b83\u5b58\u50a8\u4e86\u4e0e\u5f53\u524d\u7528\u6237\u4f1a\u8bdd\u76f8\u5173\u7684\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u83b7\u53d6\u5230\u7684\u00a0HttpSession\u00a0\u5bf9\u8c61\u5b58\u50a8\u5230\u00a0ServerEndpointConfig\u00a0\u7684\u7528\u6237\u5c5e\u6027\u4e2d\u3002\u8fd9\u662f\u901a\u8fc7\u00a0sec.getUserProperties().put(HttpSession.class.getName(), httpSession);\u00a0\u5b9e\u73b0\u7684\u3002<\/p>\n<\/li>\n<p><span style=\"color:#fe2c24\">\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728WebSocket\u4f1a\u8bdd\u4e2d\u83b7\u53d6\u5230\u8fd9\u4e2ahttpSession\u4e86&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<p>\u81f3\u4e8eServerEndpointConfig\u4e0eEndpointConfig\u7684\u533a\u522b\u53ef\u4ee5\u5230\u7f51\u4e0a\u641c\u7d22\u4e00\u4e0b\u3002<\/p>\n<h3>3\u3001\u5b9e\u73b0\u6211\u4eec\u81ea\u5df1\u7684WebSocket\u7aef\u70b9\u6765\u5904\u7406WebSocket\u8bf7\u6c42<\/h3>\n<p>\u5148\u4e0a\u4ee3\u7801\u5728\u9010\u4e2a\u5206\u6790&#xff1a;<\/p>\n<p>package org.xwx.videodemo.ws;<\/p>\n<p>import com.alibaba.fastjson.JSON;<br \/>\nimport com.fasterxml.jackson.core.JsonProcessingException;<br \/>\nimport com.fasterxml.jackson.databind.JsonMappingException;<br \/>\nimport com.fasterxml.jackson.databind.ObjectMapper;<br \/>\nimport org.slf4j.Logger;<br \/>\nimport org.slf4j.LoggerFactory;<br \/>\nimport org.springframework.stereotype.Component;<br \/>\nimport org.xwx.videodemo.pojo.Message;<\/p>\n<p>import javax.servlet.http.HttpSession;<br \/>\nimport javax.websocket.*;<br \/>\nimport javax.websocket.server.ServerEndpoint;<br \/>\nimport java.io.IOException;<br \/>\nimport java.util.concurrent.ConcurrentHashMap;<\/p>\n<p>&#064;Component<br \/>\n&#064;ServerEndpoint(value &#061; &#034;\/video&#034;, configurator &#061; GetHttpSessionConfigurator.class)<br \/>\npublic class ChatEndpoint {<br \/>\n    private static final Logger log &#061; LoggerFactory.getLogger(ChatEndpoint.class);<br \/>\n    \/\/\u5b58\u50a8\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5bf9\u8c61,\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2a\u8fde\u63a5\u5bf9\u8c61<br \/>\n    private static ConcurrentHashMap&lt;String,ChatEndpoint&gt; onlineClient &#061; new ConcurrentHashMap&lt;String,ChatEndpoint&gt;();<\/p>\n<p>    \/\/ \/\/\u6bcf\u4e2a\u8fde\u63a5\u90fd\u4f1a\u6709\u81ea\u5df1\u7684\u4f1a\u8bddSession&#xff0c;\u901a\u8fc7\u8be5\u5bf9\u8c61\u53ef\u4ee5\u53d1\u751f\u6d88\u606f\u7ed9\u6307\u5b9a\u7684\u5ba2\u6237\u7aef<br \/>\n    private Session session;<br \/>\n    \/\/ \u58f0\u660eHttpsession\u5bf9\u8c61&#xff0c;\u91cc\u9762\u8bb0\u5f55\u4e86\u7528\u6237\u76f8\u5173\u4fe1\u606f<br \/>\n    private HttpSession httpSession;<\/p>\n<p>    &#064;OnOpen<br \/>\n    public void onOpen(Session session, EndpointConfig config) {<br \/>\n        log.info(&#034;onOpen&#034;);<br \/>\n        this.session &#061; session;<br \/>\n        this.httpSession &#061; (HttpSession) config.getUserProperties().get(HttpSession.class.getName());<\/p>\n<p>        String userName &#061; (String) this.httpSession.getAttribute(&#034;user&#034;);<br \/>\n        onlineClient.put(userName,this);<\/p>\n<p>    }<\/p>\n<p>    &#064;OnMessage<br \/>\n    public void onMessage(String message) {<br \/>\n        log.info(message);<br \/>\n        Message msg &#061; JSON.parseObject(message, Message.class);<br \/>\n        if(this.session.isOpen()){<br \/>\n            try {<br \/>\n                ChatEndpoint chatEndpoint &#061; onlineClient.get(msg.getName());<br \/>\n                chatEndpoint.session.getBasicRemote().sendText(message);<br \/>\n            } catch (IOException e) {<br \/>\n                throw new RuntimeException(e);<br \/>\n            }<\/p>\n<p>        }<br \/>\n    }<\/p>\n<p>    &#064;OnClose<br \/>\n    public void onClose(Session session) {<br \/>\n        String userName &#061; (String) this.httpSession.getAttribute(&#034;user&#034;);<br \/>\n        onlineClient.remove(userName);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<h4>3.1\u3001\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u7aef\u70b9\u7c7b<\/h4>\n<p>\u6211\u8fd9\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a\u00a0ChatEndpoint\u00a0\u7684WebSocket\u670d\u52a1\u5668\u7aef\u70b9\u7c7b\u3002\u8fd9\u4e2a\u7c7b\u4f7f\u7528\u00a0&#064;ServerEndpoint\u00a0\u6ce8\u89e3\u6807\u8bb0&#xff0c;\u8868\u660e\u5b83\u662f\u4e00\u4e2aWebSocket\u7aef\u70b9&#xff0c;\u5e76\u4e14\u5b83\u6307\u5b9a\u4e86\u7aef\u70b9\u7684URL\u8def\u5f84\u4e3a\u00a0\/video&#xff0c;\u540c\u65f6\u6307\u5b9a\u4e86\u4e00\u4e2a\u914d\u7f6e\u5668\u00a0GetHttpSessionConfigurator.class&#xff0c;\u8fd9\u4e2a\u914d\u7f6e\u5668\u7528\u4e8e\u5728WebSocket\u63e1\u624b\u9636\u6bb5\u5173\u8054HTTP\u4f1a\u8bdd\u3002&#064;Component\u6ce8\u89e3\u786e\u4fdd\u4e86\u7aef\u70b9\u7c7b\u88abSpring\u5bb9\u5668\u7ba1\u7406\u3002<\/p>\n<hr \/>\n<p>\u65e5\u5fd7\u8bb0\u5f55&#xff1a;\u901a\u8fc7\u00a0LoggerFactory\u00a0\u83b7\u53d6\u4e00\u4e2a\u65e5\u5fd7\u8bb0\u5f55\u5668&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u65e5\u5fd7\u4fe1\u606f&#xff1b;<\/p>\n<p>\u6211\u4eec\u9700\u8981\u8fd9\u4e24\u4e2a\u6210\u5458\u53d8\u91cf&#xff1a;<\/p>\n<ul>\n<li>session&#xff1a;\u6bcf\u4e2a\u8fde\u63a5\u90fd\u4f1a\u6709\u81ea\u5df1\u7684\u4f1a\u8bddSession&#xff0c;\u901a\u8fc7\u8be5\u5bf9\u8c61\u53ef\u4ee5\u53d1\u751f\u6d88\u606f\u7ed9\u6307\u5b9a\u7684\u5ba2\u6237\u7aef&#xff0c;\u7528\u4e8e\u53d1\u9001\u548c\u63a5\u6536\u6d88\u606f\u3002<\/li>\n<li>httpSession&#xff1a;\u83b7\u53d6\u5230\u5f53\u524d\u4e0e\u670d\u52a1\u7aefWebSocket\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u7684Httpsession\u5bf9\u8c61&#xff0c;\u91cc\u9762\u8bb0\u5f55\u4e86\u7528\u6237\u6211\u4eec\u518d\u767b\u5f55\u7684\u65f6\u5019\u5b58\u50a8\u7684\u7528\u6237\u4fe1\u606f&#xff0c;\u4ee5\u4fbf\u6765\u8ba9\u670d\u52a1\u7aef\u77e5\u9053\u8fd9\u4e00\u4e2aChatEndpoint\u00a0\u662f\u8c01\u7684\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u6210\u5458\u53d8\u91cf\u5728\u00a0onOpen()\u4e2d\u521d\u59cb\u5316&#xff0c;\u6765\u5b58\u50a8\u5f53\u524d\u5ba2\u6237\u7aef\u7684session\u548chttpSession\u5230\u5f53\u524d\u5ba2\u6237\u7aef\u521b\u5efa\u7684\u8fd9\u4e2aChatEndpoint\u7c7b\u7684\u5b9e\u4f8b\u4e2d\u3002\u56e0\u4e3a\u6bcf\u4e2a\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u5efa\u7acb\u4e00\u6b21WebSocket\u8fde\u63a5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u5c5e\u4e8e\u81ea\u5df1\u7684ChatEndpoint\u5b9e\u4f8b\u3002\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> &#064;OnOpen<br \/>\n    public void onOpen(Session session, EndpointConfig config) {<br \/>\n        log.info(&#034;onOpen&#034;);<br \/>\n        this.session &#061; session;<br \/>\n        this.httpSession &#061; (HttpSession) config.getUserProperties().get(HttpSession.class.getName());<\/p>\n<p>        String userName &#061; (String) this.httpSession.getAttribute(&#034;user&#034;);<br \/>\n        onlineClient.put(userName,this);<\/p>\n<p>    } <\/p>\n<p>\u7136\u540e\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u4e3a\u4ec0\u4e48\u4f1a\u6709\u8fd9\u6837\u4e00\u6bb5\u4ee3\u7801&#xff1a;<\/p>\n<p>onlineClient.put(userName,this); <\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6210\u5458\u53d8\u91cf&#xff1a;<\/p>\n<p>\/\/\u5b58\u50a8\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5bf9\u8c61,\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2a\u8fde\u63a5\u5bf9\u8c61<br \/>\n    private static ConcurrentHashMap&lt;String,ChatEndpoint&gt; onlineClient &#061; new ConcurrentHashMap&lt;String,ChatEndpoint&gt;();<\/p>\n<p>\u5728\u7ebf\u5ba2\u6237\u7aef\u5b58\u50a8&#xff1a;\u4f7f\u7528\u00a0ConcurrentHashMap\u00a0\u6765\u5b58\u50a8<span style=\"color:#fe2c24\">\u6bcf\u4e2a<\/span>\u5728\u7ebf\u7684\u5ba2\u6237\u7aef&#xff08;\u7528\u6237&#xff09;\u7684<span style=\"color:#fe2c24\">\u8fde\u63a5\u5bf9\u8c61ChatEndpoint<\/span>&#xff0c;\u4ee5\u7528\u6237\u540d\u4f5c\u4e3a\u952e\u3002\u6bcf\u4e2a\u5ba2\u6237\u7aef\u90fd\u4f1a\u6709\u4e00\u4e2a\u81ea\u5df1\u7684ChatEndpoint&#xff0c;\u800c\u6211\u4eec\u670d\u52a1\u5668\u9700\u8981\u501f\u52a9\u76ee\u6807\u7528\u6237\u7684ChatEndpoint\u4e2d\u7684\u6211\u4eec\u624b\u52a8\u5b58\u7684session\u6210\u5458\u53d8\u91cf\u624d\u80fd\u7ed9\u76ee\u6807\u7528\u6237\u53d1\u9001\u4fe1\u606f&#xff0c;\u5373\u670d\u52a1\u5668\u4e3b\u52a8\u5411\u5ba2\u6237\u7aef\u63a8\u9001\u6d88\u606f\u3002\u6240\u4ee5\u9700\u8981\u5728\u4e0e\u670d\u52a1\u7aef\u5f00\u59cb\u5efa\u7acbWebSocket\u7684\u65f6\u5019\u5b58\u8d77\u6765\u3002\u4e14<span style=\"color:#fe2c24\">\u5b83\u662f\u7c7b\u7684\u9759\u6001\u6210\u5458<\/span>&#xff0c;\u670d\u52a1\u5668\u53ea\u4f1a\u6709\u4e00\u4efd&#xff0c;\u4e14\u4e0e\u5176\u5b9e\u4f8b\u5171\u4eab\u3002<\/p>\n<p><span style=\"color:#4da8ee\">\u8fd9\u6837\u6211\u4eec\u670d\u52a1\u7aef\u4e0e\u5ba2\u6237\u7aef\u4e4b\u95f4\u5efa\u7acbWebSocket\u7684\u6d41\u7a0b\u5c31\u7ed3\u675f\u4e86&#xff0c;\u5efa\u7acb\u6210\u529f\u540e\u670d\u52a1\u7aef\u53ef\u4ee5\u5f00\u59cb\u6536\u53d1\u5ba2\u6237\u7aef\u7684\u6d88\u606f\u4e86&#xff01;&#xff01;&#xff01;\u4f46\u662f\u5728\u54ea\u91cc\u6536\u53d1\u6d88\u606f\u5462&#xff1f;&#xff1f;&#xff1f;<\/span><\/p>\n<hr \/>\n<h5>3.1.2\u3001\u8fd8\u8981\u4e86\u89e3\u4e00\u4e0bWebSocket\u7684\u751f\u547d\u5468\u671f\u65b9\u6cd5&#xff1a;<\/h5>\n<p>\u751f\u547d\u5468\u671f\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>&#064;OnOpen&#xff1a;\u5f53WebSocket\u8fde\u63a5\u6253\u5f00\u65f6\u8c03\u7528\u3002<\/li>\n<li>&#064;OnMessage&#xff1a;\u5f53\u4ece\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u6d88\u606f\u65f6\u8c03\u7528\u3002<\/li>\n<li>&#064;OnClose&#xff1a;\u5f53WebSocket\u8fde\u63a5\u5173\u95ed\u65f6\u8c03\u7528\u3002<br \/>\n<hr \/>\n<\/li>\n<\/ul>\n<h5>3.1.3\u00a0\u3001\u5728\u54ea\u91cc\u6536\u53d1\u6d88\u606f\u5462&#xff1f;<\/h5>\n<p>\u4ece\u751f\u547d\u5468\u671f\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u77e5\u9053&#xff1a;\u80af\u5b9a\u662f\u5728onMessage()\u65b9\u6cd5\u4e2d&#xff0c;\u4e0d\u8fc7\u90fd\u8981\u5e26\u4e0a\u6ce8\u89e3&#xff0c;\u5176\u4ed6\u751f\u547d\u5468\u671f\u65b9\u6cd5\u4e5f\u4e00\u6837\u3002<\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u4e0e\u524d\u7aef\u7ea6\u5b9a\u597d\u4e86&#xff0c;\u524d\u540e\u7aef\u4e4b\u95f4\u53c2\u6570\u7684\u6570\u636e\u683c\u5f0f\u662fJSON\u683c\u5f0f&#xff0c;\u5185\u5bb9\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p>         {<br \/>\n            type:&#034;&#034;,\u6d88\u606f\u7684\u7c7b\u578b<br \/>\n            sdp:&#034;&#034;,\u6d88\u606f\u4f20\u8f93\u7684sdp\u4fe1\u606f<br \/>\n            name:&#034;&#034;,\u53d1\u7ed9\u8c01<br \/>\n            from:&#034;&#034; \u8c01\u53d1\u7684<br \/>\n          } <\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2aMessage\u7c7b&#xff0c;\u6765\u4e13\u95e8\u89e3\u6790\u8fd9\u6761\u6570\u636e&#xff0c;\u4ee5\u4fbf\u83b7\u53d6\u5230\u8fd9\u4e00\u6761\u6570\u636e\u662f\u8981\u670d\u52a1\u7aef\u53d1\u9001\u4e2a\u8c01\u7684&#xff1a;<\/p>\n<p>package org.xwx.videodemo.pojo;<\/p>\n<p>import lombok.Data;<\/p>\n<p>&#064;Data<br \/>\npublic class Message {<br \/>\n    \/\/ \u63a5\u6536\u4eba<br \/>\n    private String name;<br \/>\n    \/\/\u6d88\u606f\u7c7b\u578b<br \/>\n    private String type;<br \/>\n    \/\/ \u6d88\u606f\u5185\u5bb9<br \/>\n    private String sdp;<br \/>\n    private String from;<br \/>\n}<\/p>\n<p>\u518d\u6765\u770b\u8fd9\u4e2aonMessage\u65b9\u6cd5&#xff1a;<\/p>\n<p>&#064;OnMessage<br \/>\n    public void onMessage(String message) {<br \/>\n        log.info(message);<br \/>\n        \/\/\u5c06JSON\u5b57\u7b26\u4e32message\u8f6c\u6362\u4e3aMessage\u5bf9\u8c61<br \/>\n        Message msg &#061; JSON.parseObject(message, Message.class);<br \/>\n        \/\/\u5224\u65ad\u662f\u5426\u8fd9\u4e2a\u4f1a\u8bdd\u662f\u5904\u4e8e\u6253\u5f00\u72b6\u6001<br \/>\n        if(this.session.isOpen()){<br \/>\n            try {<br \/>\n                \/\/\u6839\u636e\u524d\u7aef\u4f20\u8fc7\u6765\u7684\u6d88\u606f\u4e2d\u7684name&#xff0c;\u5373\u8981\u53d1\u9001\u7684\u76ee\u6807\u7528\u6237\u6765\u627e\u5230\u76ee\u6807\u7528\u6237\u7684chatEndpoint<br \/>\n                ChatEndpoint chatEndpoint &#061; onlineClient.get(msg.getName());<br \/>\n                \/\/\u518d\u901a\u8fc7\u76ee\u6807\u7528\u6237\u7684chatEndpoint\u6765\u7ed9\u5ba2\u6237\u7aef\u53d1\u6d88\u606f<br \/>\n                chatEndpoint.session.getBasicRemote().sendText(message);<br \/>\n            } catch (IOException e) {<br \/>\n                throw new RuntimeException(e);<br \/>\n            }<\/p>\n<p>        }<br \/>\n    } <\/p>\n<p>\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u524d\u540e\u7aef\u8981\u7ea6\u5b9a\u7684JSON\u683c\u5f0f\u8981\u6709name&#xff0c;\u5373\u76ee\u6807\u7528\u6237\u7684\u7528\u6237\u540d\u7684\u539f\u56e0&#xff0c;\u5b83\u53ef\u4ee5\u8ba9\u6211\u4eec\u670d\u52a1\u7aef\u66f4\u52a0\u65b9\u4fbf\u7684\u627e\u5230\u76ee\u6807\u7528\u6237\u7684chatEndpoint\u6765\u53d1\u9001\u6d88\u606f&#xff01;\u7ec8\u4e8e\u4e3a\u4ec0\u4e48\u6709from&#xff0c;\u5219\u662f\u5728\u524d\u7aef\u6709\u7528\u5230\u3002<\/p>\n<p>3.1.4\u5728\u54ea\u91cc\u5173\u95ed\u4e0e\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u5462&#xff1f;<\/p>\n<p>\u4ece\u751f\u547d\u5468\u671f\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u77e5\u9053&#xff1a;\u80af\u5b9a\u662f\u5728onClose()\u65b9\u6cd5\u4e2d&#xff01;&#xff01;&#xff01;<\/p>\n<p>\u76f4\u63a5\u628a\u65ad\u5f00\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u7684ChatEndpoint\u79fb\u9664\u5373\u53ef&#xff1a;<\/p>\n<p>&#064;OnClose<br \/>\n    public void onClose(Session session) {<br \/>\n        String userName &#061; (String) this.httpSession.getAttribute(&#034;user&#034;);<br \/>\n        onlineClient.remove(userName);<\/p>\n<p>    } <\/p>\n<h2>\u5230\u6b64&#xff0c;\u6211\u4eec\u5c31\u5b8c\u6210\u4e86\u540e\u7aef\u7684\u4fe1\u4ee4\u670d\u52a1\u5668\u7684\u642d\u5efa&#xff01;&#xff01;&#xff01;<\/h2>\n<p>\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u8fd9\u4e0d\u5c31\u662f\u5728\u540e\u7aef\u642d\u5efa\u4e00\u4e2aWebSocket\u670d\u52a1\u7aef\u70b9\u5417&#xff1f;\u786e\u5b9e\u662f&#xff0c;\u56e0\u4e3a\u4fe1\u4ee4\u670d\u52a1\u5668\u5c31\u662f\u8d77\u5230\u4e00\u4e2a\u8fde\u63a5\u591a\u4e2a\u5ba2\u6237\u7aef&#xff0c;\u8ba9\u5ba2\u6237\u7aef\u4e4b\u95f4\u53ef\u4ee5\u8fdb\u884c\u4fe1\u606f\u4f20\u8f93\u7684\u4f5c\u7528\u3002\u6240\u4ee5\u548c\u7528WebSocket\u6765\u642d\u5efa\u5728\u7ebf\u804a\u5929\u5ba4\u662f\u4e00\u6837\u7684&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf33\u6b21\u3002\u540e\u7aef\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668\u6765\u914d\u5408\u524d\u7aef\u4f7f\u7528WebRTC_springboot webrtc<\/p>\n","protected":false},"author":2,"featured_media":13469,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,98,537,292],"topic":[],"class_list":["post-13470","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-spring-boot","tag-webrtc","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/13470.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf33\u6b21\u3002\u540e\u7aef\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668\u6765\u914d\u5408\u524d\u7aef\u4f7f\u7528WebRTC_springboot webrtc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/13470.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T12:27:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418122723-6802452b37c82.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/13470.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/13470.html\",\"name\":\"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T12:27:24+00:00\",\"dateModified\":\"2025-04-18T12:27:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/13470.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/13470.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/13470.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668---SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/13470.html","og_locale":"zh_CN","og_type":"article","og_title":"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.8k\u6b21\uff0c\u70b9\u8d5e27\u6b21\uff0c\u6536\u85cf33\u6b21\u3002\u540e\u7aef\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668\u6765\u914d\u5408\u524d\u7aef\u4f7f\u7528WebRTC_springboot webrtc","og_url":"https:\/\/www.wsisp.com\/helps\/13470.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T12:27:24+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418122723-6802452b37c82.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/13470.html","url":"https:\/\/www.wsisp.com\/helps\/13470.html","name":"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668-SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T12:27:24+00:00","dateModified":"2025-04-18T12:27:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/13470.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/13470.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/13470.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u642d\u5efa\u4fe1\u4ee4\u670d\u52a1\u5668---SpringBoot\u7b80\u5355\u4f7f\u7528WebRTC\uff08\u540e\u7aef\u7bc7\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/13470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=13470"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/13470\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/13469"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=13470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=13470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=13470"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=13470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}