From f69525056b83a204809578fb04656d865daa2d37 Mon Sep 17 00:00:00 2001 From: wenlele Date: Wed, 22 Jun 2022 15:39:15 +0800 Subject: [PATCH] socket --- code/VideoAccess-VCMP/web/client/src/app.jsx | 2 +- .../src/layout/containers/layout/index.jsx | 21 ++++++++++++++++--- .../web/client/src/layout/index.jsx | 4 ++++ .../sections/example/containers/example.jsx | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/code/VideoAccess-VCMP/web/client/src/app.jsx b/code/VideoAccess-VCMP/web/client/src/app.jsx index 7538d02..13cf884 100644 --- a/code/VideoAccess-VCMP/web/client/src/app.jsx +++ b/code/VideoAccess-VCMP/web/client/src/app.jsx @@ -25,7 +25,7 @@ const App = props => { return ( { const { dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight, - location, match, routes, history, authCrossLoading + location, match, routes, history, authCrossLoading,socket } = props const [collapsed, setCollapsed] = useState(false) @@ -79,6 +79,20 @@ const LayoutContainer = props => { } }) + + // websocket 使用测试 + useEffect(() => { + console.log(socket) + if (socket) { + socket.on('CAMERA_ONLINE', function (msg) { + console.info(msg); + }); + return () => { + socket.off("CAMERA_ONLINE"); + } + } +}, [socket]) + return ( { @@ -149,7 +163,7 @@ const LayoutContainer = props => { } function mapStateToProps (state) { - const { global, auth, ajaxResponse } = state; + const { global, auth, ajaxResponse , webSocket} = state; return { title: global.title, copyright: global.copyright, @@ -158,7 +172,8 @@ function mapStateToProps (state) { clientWidth: global.clientWidth, clientHeight: global.clientHeight, msg: ajaxResponse.msg, - user: auth.user + user: auth.user, + socket: webSocket.socket }; } diff --git a/code/VideoAccess-VCMP/web/client/src/layout/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/index.jsx index 3878387..9566aee 100644 --- a/code/VideoAccess-VCMP/web/client/src/layout/index.jsx +++ b/code/VideoAccess-VCMP/web/client/src/layout/index.jsx @@ -84,6 +84,10 @@ const Root = props => { } } + + + + useEffect(async () => { let innerRoutes = [] let outerRoutes = [] diff --git a/code/VideoAccess-VCMP/web/client/src/sections/example/containers/example.jsx b/code/VideoAccess-VCMP/web/client/src/sections/example/containers/example.jsx index 98bfe12..ca3ecb7 100644 --- a/code/VideoAccess-VCMP/web/client/src/sections/example/containers/example.jsx +++ b/code/VideoAccess-VCMP/web/client/src/sections/example/containers/example.jsx @@ -6,6 +6,7 @@ const { Meta } = Card; const Example = (props) => { const { dispatch, actions, user, loading, socket } = props + console.log(props) useEffect(() => { // ACTION 示例