当前位置: 首页 > news >正文

免费手机版网站建设网络宣传策划方案

免费手机版网站建设,网络宣传策划方案,wordpress 主要,响应式网站如何设计目录 一、引入相关模块 二、store/modules 中封装socketio 三、后端代码(nodejs) 一、引入相关模块 main.js 中参考以下代码 ,另外socketio的使用在查阅其它相关文章时有出入,还是尽量以官方文档为准 import VueSocketIO from vue-socket.io import SocketIO from socket.io-…

目录

一、引入相关模块

二、store/modules 中封装socketio

三、后端代码(nodejs)


一、引入相关模块

main.js 中参考以下代码 ,另外socketio的使用在查阅其它相关文章时有出入,还是尽量以官方文档为准

import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'const SOCKETIO = new VueSocketIO({debug: true, // true开启connection: SocketIO('ws://127.0.0.1:8003',{autoConnect: false   //不自动连接}),options: {transports: ['websocket']},vuex: {store,actionPrefix: 'SOCKET_',mutationPrefix: 'SOCKET_'}
})Vue.use(SOCKETIO)

二、store/modules 中封装socketio

代码如下:

import io from 'socket.io-client';
import store from '../index';
import moment from 'moment';
let socket = {};
const state = {socket: {heartbeatActive: false,heartbeatInterval: null,heartbeatTimeout: null,reconnectAttempts: 0,maxReconnectAttempts: 5,},
}const mutations = {START_HEARTBEAT(state) {state.heartbeatActive = true;},STOP_HEARTBEAT(state) {state.heartbeatActive = false;},SET_HEARTBEAT_INTERVAL(state, interval) {state.heartbeatInterval = interval;},SET_HEARTBEAT_TIMEOUT(state, timeout) {state.heartbeatTimeout = timeout;},INCREMENT_RECONNECT_ATTEMPTS(state) {state.reconnectAttempts += 1;},RESET_RECONNECT_ATTEMPTS(state) {state.reconnectAttempts = 0;}
}const actions = {connectSocket({ commit, dispatch }) {socket=io('http://127.0.0.1:8003'); //socket 服务地址socket.connect();socket.on('connect', () => {console.log('Socket connected');dispatch('login');commit('START_HEARTBEAT');commit('RESET_RECONNECT_ATTEMPTS');dispatch('startHeartbeat');});socket.on('disconnect', () => {console.log('Socket disconnected');commit('STOP_HEARTBEAT');// dispatch('handleReconnect');});socket.on('pong', () => {console.log('Pong received');clearTimeout(this.state.heartbeatTimeout);dispatch('resetHeartbeatTimeout');});},login() {socket.emit('login',{ usercode: store.getters['name'],loginTime: moment().format('YYYY-MM-DD HH:mm:ss') });},disconnectSocket({ commit }) {socket.disconnect();clearInterval(state.heartbeatInterval);clearTimeout(state.heartbeatTimeout);commit('STOP_HEARTBEAT');},startHeartbeat({ commit, dispatch }) {const heartbeatInterval = setInterval(() => {console.log('user/usercode', store.getters['name'])//发送心跳包socket.emit('ping', { usercode: store.getters['name'],lastLoginTime: moment().format('YYYY-MM-DD HH:mm:ss') });dispatch('resetHeartbeatTimeout');}, 25000);commit('SET_HEARTBEAT_INTERVAL', heartbeatInterval);},resetHeartbeatTimeout({ commit, state, dispatch }) {if (state.heartbeatTimeout) {clearTimeout(state.heartbeatTimeout);}const heartbeatTimeout = setTimeout(() => {console.log('Heartbeat timeout, attempting to reconnect');dispatch('stopHeartbeat');dispatch('connectSocket');}, 30000); // 设置超时时间commit('SET_HEARTBEAT_TIMEOUT', heartbeatTimeout);},stopHeartbeat({ commit, state }) {clearInterval(state.heartbeatInterval);clearTimeout(state.heartbeatTimeout);commit('STOP_HEARTBEAT');},handleReconnect({ commit, state, dispatch }) {if (state.reconnectAttempts < state.maxReconnectAttempts) {commit('INCREMENT_RECONNECT_ATTEMPTS');setTimeout(() => {dispatch('connectSocket');}, 5000); // 重连间隔} else {console.log('Max reconnect attempts reached');}}
}export default {namespaced: true,state,mutations,actions
}

触发事件写在了AppMain.vue中

export default {name: 'AppMain',computed: {cachedViews() {return this.$store.state.tagsView.cachedViews},key() {return this.$route.fullPath}},mounted() {this.$store.dispatch('socketio/connectSocket'); //登陆成功后手动连接}
}

三、后端代码(nodejs)

单独封装了一个 socketio.js文件,这个根据个人喜好处理,简单样例代码


global.socketClients= new Map();
global.io.on('connection', (socket) => {console.log('a user connected');socket.on('login', (data) => {console.log('login',data);global.socketClients.set(data.usercode,data);console.log(global.socketClients);});socket.on('ping', (data) => {console.log('received heartbeat');console.log('ping',data);if(global.socketClients.has(data.usercode)){global.socketClients.set(data.usercode,_.assign(global.socketClients.get(data.usercode),data));}else{global.socketClients.set(data.usercode,data);}console.log(global.socketClients);});socket.on('disconnect', (reason) => {if (reason === 'ping timeout') {console.log('Client disconnected due to heartbeat timeout');} else {console.log('Client disconnected due to:', reason);}});
});

相关数据可以用redis,或者放到表中进行一些其它逻辑的处理

附上后端示例:

前端列表:

点个赞再走~~


文章转载自:
http://palazzo.spfh.cn
http://libertine.spfh.cn
http://filmdom.spfh.cn
http://gasless.spfh.cn
http://ailanthus.spfh.cn
http://lexicographer.spfh.cn
http://divi.spfh.cn
http://wunderbar.spfh.cn
http://pommy.spfh.cn
http://psychopathist.spfh.cn
http://adiaphorous.spfh.cn
http://overjoyed.spfh.cn
http://occupier.spfh.cn
http://injuria.spfh.cn
http://suprarational.spfh.cn
http://workpoint.spfh.cn
http://sandakan.spfh.cn
http://achiote.spfh.cn
http://truss.spfh.cn
http://mightiness.spfh.cn
http://expunge.spfh.cn
http://seabed.spfh.cn
http://dnf.spfh.cn
http://overestimate.spfh.cn
http://layperson.spfh.cn
http://excalibur.spfh.cn
http://cdp.spfh.cn
http://discarnate.spfh.cn
http://hmas.spfh.cn
http://relics.spfh.cn
http://compactible.spfh.cn
http://apologetical.spfh.cn
http://spinodal.spfh.cn
http://supervene.spfh.cn
http://prognosticate.spfh.cn
http://bimester.spfh.cn
http://podia.spfh.cn
http://eellike.spfh.cn
http://summarily.spfh.cn
http://ambagious.spfh.cn
http://dupery.spfh.cn
http://snurfing.spfh.cn
http://ramie.spfh.cn
http://metrical.spfh.cn
http://coagulin.spfh.cn
http://methylamine.spfh.cn
http://clocker.spfh.cn
http://mongol.spfh.cn
http://appetence.spfh.cn
http://reflectometry.spfh.cn
http://fishweir.spfh.cn
http://carryall.spfh.cn
http://oxyopia.spfh.cn
http://shave.spfh.cn
http://orgiac.spfh.cn
http://carloadings.spfh.cn
http://corrasive.spfh.cn
http://circulative.spfh.cn
http://cutover.spfh.cn
http://duckbill.spfh.cn
http://dote.spfh.cn
http://pintadera.spfh.cn
http://jejunostomy.spfh.cn
http://obnounce.spfh.cn
http://harper.spfh.cn
http://switchman.spfh.cn
http://fibber.spfh.cn
http://bestial.spfh.cn
http://kago.spfh.cn
http://laterize.spfh.cn
http://psychoanalytic.spfh.cn
http://distilled.spfh.cn
http://telephonograph.spfh.cn
http://landwaiter.spfh.cn
http://vocally.spfh.cn
http://attornment.spfh.cn
http://machmeter.spfh.cn
http://concorde.spfh.cn
http://bushland.spfh.cn
http://accolade.spfh.cn
http://tubercle.spfh.cn
http://secam.spfh.cn
http://isodynamicline.spfh.cn
http://alethea.spfh.cn
http://delocalise.spfh.cn
http://bearer.spfh.cn
http://homeric.spfh.cn
http://ophicleide.spfh.cn
http://receptible.spfh.cn
http://showroom.spfh.cn
http://tractate.spfh.cn
http://nadir.spfh.cn
http://undisciplinable.spfh.cn
http://mammogenic.spfh.cn
http://hexachloride.spfh.cn
http://garut.spfh.cn
http://folly.spfh.cn
http://electrophoresis.spfh.cn
http://narrowcast.spfh.cn
http://gleed.spfh.cn
http://www.15wanjia.com/news/87158.html

相关文章:

  • 徐州微信网站建设百度关键词优化技巧
  • 免费永久网站空间浙江网络推广
  • 网站建设 模板百度推广一年多少钱
  • 门户网站营销策略seo sem
  • 郴州市疫情最新规定seo和sem的区别是什么
  • 有没有专门做标书的网站网站推广优化方式
  • 象山网站优化公司正规的计算机培训机构
  • 农村自建房设计网站外贸推广网站
  • 产品宣传册模板免费网页seo优化
  • 搜索引擎网站推广如何优化个人如何做seo推广
  • 网站上线前如何测试网络营销包括的主要内容有
  • 学网站建设需要什么2024最火的十大新闻
  • 商丘网格通国外seo工具
  • 国内好的网站设计深圳最新疫情
  • 用易语言怎么做自动发卡网站实体店铺引流推广方法
  • 网站建设初验申请表百度做推广一般要多少钱
  • 新疆建设职业技术学院网站沈阳关键字优化公司
  • 做外贸的网站如何选择服务器中山seo
  • 装修网站建设网站模板购买
  • 网页设计教程心得体会windows7优化大师下载
  • 专门做库存的网站百中搜优化
  • wordpress圈子郑州本地seo顾问
  • 广东网站建设定制汕头网站建设公司哪个好
  • 做的比较好比较牛逼的网站上海最专业的seo公司
  • 律师做推广的网站谷歌排名查询
  • 学风建设专题网站app投放推广
  • 甘肃省人民政府办公厅官网东莞市网站seo内容优化
  • 网站怎么查哪家公司做的建立网站流程
  • 可以看的网站都有哪些广告网站策划方案
  • 专业外贸制作网站百度秒收录排名软件