{"id":13536427,"url":"https://github.com/secreter/websocket_chat","last_synced_at":"2025-04-02T03:30:44.145Z","repository":{"id":45786508,"uuid":"68393245","full_name":"secreter/websocket_chat","owner":"secreter","description":"基于vue的websocket聊天室","archived":false,"fork":false,"pushed_at":"2017-02-20T16:16:57.000Z","size":70,"stargazers_count":417,"open_issues_count":4,"forks_count":132,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-11-03T01:33:11.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/secreter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-16T15:49:01.000Z","updated_at":"2024-10-28T00:10:06.000Z","dependencies_parsed_at":"2022-07-16T14:30:29.752Z","dependency_job_id":null,"html_url":"https://github.com/secreter/websocket_chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secreter%2Fwebsocket_chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secreter%2Fwebsocket_chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secreter%2Fwebsocket_chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secreter%2Fwebsocket_chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secreter","download_url":"https://codeload.github.com/secreter/websocket_chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246750834,"owners_count":20827788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T09:00:39.085Z","updated_at":"2025-04-02T03:30:43.842Z","avatar_url":"https://github.com/secreter.png","language":"Vue","readme":"# 基于vue和websocket的多人在线聊天室\n* author： So\n------\n\n最近看到一些关于websocket的东西，就决定写一个在线聊天室尝试一下。最终决定配合vue来写，采用了官方的vue脚手架vue-cli和官方的router，在本例中呢，我是用了CHAT这个对象来存储app的数据的，但后来一想，虽然项目很小，但如果用官方的vuex会更好，方便以后扩展，比如可以加上私信功能，可以在对方不在线的时候缓存发送的消息，这些都是可以的。（现在比较尴尬的就是，我把聊天室写好放到公众号号redream里，但是很少有人会同时在线，所以你会经常发现你进去的时候只有你一个人，就导致群聊不起来）\n\n### 1.好吧，先来看一下我们的效果图\n![login](http://item.redream.cn/chat/0.jpg )\n![login](http://item.redream.cn/chat/447.jpg )\n![login](http://item.redream.cn/chat/445.jpg )\n详细见[redream文章](http://mp.weixin.qq.com/s?__biz=MzAwMjAzNDU1NQ==\u0026mid=2650166098\u0026idx=1\u0026sn=8ea7fda842823a1a0528742589f9f238\u0026chksm=82d26d46b5a5e4503e830de7f41469b5fe93a08058bf839838f13597914037230ea114a57f3a#rd)\n\n### 2.用到的一些东西\n\u003e * nodejs node服务器运行环境\n\u003e * express 搭建node服务器\n\u003e * websocket 本例核心，推送服务器消息到所有人\n\u003e * socketio websocket第三方库\n\u003e * vue + router 视图层双向数据绑定框架，用来简化开发、组件化开发的\n\u003e * es6语法 就是好用简洁哈哈\n\u003e * https 因为像websocket和很多h5的新功能，浏览器为了安全起见都仅支持https下开发\n关于nodejs搭建express服务器可以看[这里](http://www.plhwin.com/2014/05/28/nodejs-socketio/)我就是在这里学的，代码里也借鉴了很多，关于搭建https服务器就不简介了，内容太多，推荐阿里云一年的免费证书，可以访问[我的站点](https://node.redream.cn)查看\n\n### 3.代码架构简介\n* server里是需要运行在node服务器上的js文件，监听websocket连接\n* src/api/client是客户端连接服务器的核心js\n* src/components下是页面的组件。我分成了三大部分，login组件(登录页面)，chat组件（聊天页面），groupinfo组件（群信息页面），其实是单页应用，反应速度更快，接近原生app，只不过用router联系在了一起。像chat组件，又又head、body、foot组件组成，组件化是很好的习惯和架构方式，条理清晰，而且在大项目里很多可以复用。\n具体都在代码了，大家可以下载下来在本地跑一跑。\n\n### 4.运行代码\n* install dependencies\n\u003e npm install\n\n* serve with hot reload at localhost:8080\n\u003e npm run dev\n\n* build for production with minification\n\u003e npm run build\n\n这是在我站点上跑着的[例子](http://item.redream.cn/chat/),大家可以看一看，在手机上效果更加，最近校招比较忙，就花了两天，没考虑兼容，欢迎大家提出意见。\n\n-------\n\u003e 这是我第一次写技术介绍文章，其实我也并没有介绍什么细节。不过感觉上面提到的每一个知识点都可以讲很多。一想写起来那么多就没耐心了，看来还是太毛躁。希望大家多多包涵，我会慢慢改进的，大家一起进步！\n\nhttps://github.com/secreter/websocket_chat\n","funding_links":[],"categories":["Vue","Demo示例"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecreter%2Fwebsocket_chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecreter%2Fwebsocket_chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecreter%2Fwebsocket_chat/lists"}