Browse Source

fix websocket 信息推送

release_0.0.2
巴林闲侠 3 years ago
parent
commit
756231efa7
  1. 14
      code/VideoAccess-VCMP/api/app/lib/service/socket.js
  2. 27
      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

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

@ -11,16 +11,16 @@ module.exports = async function factory (app, opts) {
// 使用测试 保持链接 // 使用测试 保持链接
setInterval(async () => { setInterval(async () => {
const { connected } = app.socket.sockets const { connected } = app.socket.sockets
const roomId = 'ROOM_' + Math.random() const roomId = 'ROOM_' + Math.random()
if (connected) { if (connected) {
for (let c in connected) { for (let c in connected) {
connected[c].join(roomId) connected[c].join(roomId)
} }
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)
} }

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

@ -16,21 +16,22 @@ import application from './sections/application';
import member from './sections/member'; import member from './sections/member';
const App = props => { const App = props => {
const { projectName } = props const { projectName } = props
useEffect(() => { useEffect(() => {
document.title = projectName; document.title = projectName;
}, []) }, [])
return ( return (
<Layout <Layout
title={projectName} title={projectName}
sections={[Example, sections={[
Auth, Monitor, EquipmentWarehouse, AiAbility, offline, // Example,
openness, journaling, archive, application, member, system Auth, Monitor, EquipmentWarehouse, AiAbility, offline,
]} openness, journaling, archive, application, member, system
/> ]}
) />
)
} }
export default App; export default App;

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