

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
12345# 即时通讯(Socket)67`cool-admin`即时通讯功能基于[Socket.io(v4)](https://socket.io/docs/v4)开发,[midwayjs 官方 Socket.io 文档](http://midwayjs.org/docs/extensions/socketio)89## 配置1011`configuration.ts`1213```ts14import * as socketio from "@midwayjs/socketio";1516@Configuration({17 imports: [18 // socketio http://www.midwayjs.org/docs/extensions/socketio19 socketio,20 ],21 importConfigs: [join(__dirname, "./config")],22})23export class ContainerLifeCycle {24 @App()25 app: koa.Application;2627 async onReady() {}28}29```3031## 配置`config/config.default.ts`3233需要配置 redis 适配器,让进程之间能够进行通讯3435```ts36import { CoolConfig, MODETYPE } from "@cool-midway/core";37import { MidwayConfig } from "@midwayjs/core";38import * as fsStore from "@cool-midway/cache-manager-fs-hash";39import { createAdapter } from "@socket.io/redis-adapter";40// @ts-ignore41import Redis from "ioredis";4243const redis = {44 host: "127.0.0.1",45 port: 6379,46 password: "",47 db: 0,48};4950const pubClient = new Redis(redis);51const subClient = pubClient.duplicate();5253export default {54 // ...55 // socketio56 socketIO: {57 upgrades: ["websocket"], // 可升级的协议58 adapter: createAdapter(pubClient, subClient),59 },60} as MidwayConfig;61```6263## 服务端6465```ts66import {67 WSController,68 OnWSConnection,69 Inject,70 OnWSMessage,71} from "@midwayjs/core";72import { Context } from "@midwayjs/socketio";73/**74 * 测试75 */76@WSController("/")77export class HelloController {78 @Inject()79 ctx: Context;8081 // 客户端连接82 @OnWSConnection()83 async onConnectionMethod() {84 console.log("on client connect", this.ctx.id);85 console.log("参数", this.ctx.handshake.query);86 this.ctx.emit("data", "连接成功");87 }8889 // 消息事件90 @OnWSMessage("myEvent")91 async gotMessage(data) {92 console.log("on data got", this.ctx.id, data);93 }94}95```9697## 客户端9899```ts100const io = require("socket.io-client");101102const socket = io("http://127.0.0.1:8001", {103 auth: {104 token: "xxx",105 },106});107108socket.on("data", (msg) => {109 console.log("服务端消息", msg);110});111```112113## 注意事项114115如果部署为多线程的,为了让进程之间能够进行通讯,需要配置 redis 适配器,[配置方式](http://midwayjs.org/docs/extensions/socketio#%E9%85%8D%E7%BD%AE-redis-%E9%80%82%E9%85%8D%E5%99%A8)116117```ts118// src/config/config.default119import { createRedisAdapter } from "@midwayjs/socketio";120121export default {122 // ...123 socketIO: {124 adapter: createRedisAdapter({ host: "127.0.0.1", port: 6379 }),125 },126};127```128
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| cool-team-official/cool-admin-midway.cursor/rules/authority.mdc · 3.3k | Cursor rules | security | 54/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/cache.mdc · 3.3k | Cursor rules | no sections | 58/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/controller.mdc · 3.3k | Cursor rules | api | 46/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/db.mdc · 3.3k | Cursor rules | setupdatabase | 62/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/event.mdc · 3.3k | Cursor rules | no sections | 45/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/module.mdc · 3.3k | Cursor rules | no sections | 50/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/service.mdc · 3.3k | Cursor rules | database | 54/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/task.mdc · 3.3k | Cursor rules | style | 58/100 | today | |
| cool-team-official/cool-admin-midway.cursor/rules/tenant.mdc · 3.3k | Cursor rules | no sections | 50/100 | today | |
| cool-team-official/cool-admin-midway.cursorrules · 3.3k | .cursorrules | no sections | 39/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 46 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/cool-team-official-cool-admin-midway-cursor-rules-socket)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.