Browse Source

fix websocket 信息推送

release_0.0.2
巴林闲侠 3 years ago
parent
commit
756231efa7
  1. 4
      code/VideoAccess-VCMP/api/app/lib/service/socket.js
  2. 3
      code/VideoAccess-VCMP/web/client/src/app.jsx
  3. 19
      code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js
  4. 5
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  5. 4
      code/VideoAccess-VCMP/web/package.json

4
code/VideoAccess-VCMP/api/app/lib/service/socket.js

@ -21,6 +21,6 @@ module.exports = async function factory (app, opts) {
app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, }) app.socket.to(roomId).emit('TEST', { someProperty: `【星域 ROOM:${roomId}】呼叫自然选择号!!!`, })
} }
app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', }) // app.socket.emit('TEST', { someProperty: '【广播】呼叫青铜时代号!!!', })
}, 500) }, 3000)
} }

3
code/VideoAccess-VCMP/web/client/src/app.jsx

@ -25,7 +25,8 @@ const App = props => {
return ( return (
<Layout <Layout
title={projectName} title={projectName}
sections={[Example, sections={[
// Example,
Auth, Monitor, EquipmentWarehouse, AiAbility, offline, Auth, Monitor, EquipmentWarehouse, AiAbility, offline,
openness, journaling, archive, application, member, system openness, journaling, archive, application, member, system
]} ]}

19
code/VideoAccess-VCMP/web/client/src/layout/actions/webSocket.js

@ -21,30 +21,13 @@ export function initWebSocket ({ ioUrl, token }) {
return dispatch => { return dispatch => {
const socket = io( const socket = io(
// ioUrl ioUrl
// 'http://127.0.0.1:4000' // 'http://127.0.0.1:4000'
'ws://127.0.0.1:4000'
// '_api/'
, { , {
query: { query: {
token: token token: token
}, },
}); });
socket.on("connect", () => {
console.log('connect');
});
socket.io.on("error", (error) => {
console.error(error);
});
socket.io.on("reconnect_error", (error) => {
console.error(error);
});
socket.io.on("reconnect_failed", () => {
console.error(error);
});
socket.on('TEST', function (msg) {
console.info(msg);
});
dispatch({ dispatch({
type: INIT_WEB_SOCKET, type: INIT_WEB_SOCKET,
payload: { payload: {

5
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -84,10 +84,6 @@ const Root = props => {
} }
} }
useEffect(async () => { useEffect(async () => {
let innerRoutes = [] let innerRoutes = []
let outerRoutes = [] let outerRoutes = []
@ -158,7 +154,6 @@ const Root = props => {
// IOT system cross // IOT system cross
window.addEventListener('message', async function (e) { // message window.addEventListener('message', async function (e) { // message
const { data } = e const { data } = e
console.log(e);
if (data && data.action) { if (data && data.action) {
if (data.action == 'initUser') { if (data.action == 'initUser') {
await store.dispatch(actions.auth.initAuth(data.user)) await store.dispatch(actions.auth.initAuth(data.user))

4
code/VideoAccess-VCMP/web/package.json

@ -66,8 +66,8 @@
"perfect-scrollbar": "^1.5.5", "perfect-scrollbar": "^1.5.5",
"qs": "^6.10.5", "qs": "^6.10.5",
"screenfull": "5.2.0", "screenfull": "5.2.0",
"socket.io-client": "^4.5.0", "socket.io-client": "^1.7.4",
"socket.io-parser": "^4.2.0", "socket.io-parser": "^3.4.1",
"superagent": "^6.1.0", "superagent": "^6.1.0",
"webpack": "^5.3.2", "webpack": "^5.3.2",
"webpack-bundle-analyzer": "^4.1.0", "webpack-bundle-analyzer": "^4.1.0",

Loading…
Cancel
Save