弹幕服务器说明
wschat
是我们提供的一个高性能大并发弹幕服务器,支持win/linux系统,支持单机10万+并发,支持发送表情,支持违禁词设置,可为zwplayer
提供弹幕转发服务。
该模块是收费模块,如需试用,请加微信号: chenfanyu42 申请加入(请备注"wschat
")
1. 安装
1.1 linux平台
复制 wschat.zip
到 服务器目录,比如 /home/
cd /home unzip wschat.zip -d wschat cd wschat
1.2 windows平台
下载并解压wschat.zip
到指定目录, 比如 d:/
以管理员方式打开命令行
cd d:/wschat ./wschat.exe -i # 安装服务 net start iAVCastLBLService # 启动服务 net stop iAVCastLBLService # 停止服务
1.3 修改配置
文件为安装目录的 conf/lblserver.conf
port=3000 ssl=0 ssl_cert=/sslcerts/fullchain.cer ssl_key=/sslcerts/server.key
配置文件说明
port: 端口号
ssl: 是否启用ssl
ssl_cert/ssl_key: ssl 公私钥证书,使用nginx配置
2. 服务器访问地址
ws://serverhost.com:3000/
或
wss://serverhost.com:3000/
3. 消息实例说明
c: 客户端
s: 弹幕服务器
3.1 连接流程
服务器分配用户ID
客户端通过WebSocket连接服务器成功后,服务器分配用户ID:
s → c
{ "type": "setuserid", "uid": 1412956275600, "ip": "192.168.1.202" }
uid
: 服务器给客户端分配的唯一IDip
: 客户端的IP地址
客户端发送hello消息握手
c → s
{ "type": "hello" }
服务器回复
s → c
{ "type": "hello", "server": "Huayi Live Chat Server Version 1.0", "uid": 1412956275600, "ip": "192.168.1.202" }
3.2 房间操作
加入房间
c → s
{ "type": "join", "room": "videoroom_001" }
服务器反馈加入房间结果
s → c
{ "type": "event", "event": "joinroom", "uid": 1412956275600, "userscount": 1, "loginedcount": 0, "ip": "192.168.1.202" }
userscount
: 当前房间的总人数loginedcount
: 当前已经登录的总人数
3.3 弹幕功能
发送弹幕
c → s
{ "type": "danmu", "text": "测试发送弹幕" }
接收弹幕
s → c
{ "type": "danmu", "text": "测试发送弹幕", "uid": "1412956275600", "avatar": "", "username": "" }
3.4 用户登录/注销
用户登录
c → s
{ "type": "login", "uname": "用户61396", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "loginid": "uid61396", "info": "这家伙很懒,什么也没说" }
avatar
: 头像URL位置,必须能被当前页面访问
登录结果反馈 s → c
{ "type": "login", "result": "success" }
服务器广播登录信息 s → c
{ "type": "event", "event": "login", "uid": 1412956275248, "username": "用户61396", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "time": 1717737414, "userid": "uid61396", "userinfo": "这家伙很懒,什么也没说", "userscount": 2, "loginedcount": 1, "ip": "192.168.1.202" }
用户注销
c → s
{ "type": "logout" }
注销结果反馈 s → c
{ "type": "logout", "result": "success" }
服务器广播注销信息 s → c
{ "type": "event", "event": "logout", "uid": 1412956275248, "username": "用户61396", "userscount": 1, "loginedcount": 0, "ip": "192.168.1.202" }
离开房间
c → s
{ "type": "leave" }
服务器广播离开信息 s → c
{ "type": "event", "event": "leaveroom", "uid": 1412956275248, "userscount": 1, "loginedcount": 0, "ip": "192.168.1.202" }
3.5 用户列表
获取用户列表
c → s
{ "type": "userlist" }
服务器返回用户列表 s → c
{ "type": "userlist", "users": [ { "uid": "1412956275248", "ip": "192.168.1.202", "time": "1717738078", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "userid": "uid31935", "userinfo": "这家伙很懒,什么也没说", "username": "用户31935" }, { "uid": "1412956783616", "ip": "192.168.1.202", "time": "1717738554", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "userid": "uid81779", "userinfo": "这家伙很懒,什么也没说", "username": "用户81779" } ], "count": 2 }
3.6 文字聊天
发送聊天信息
c → s
{ "type": "text", "text": "我要聊天" }
未登录用户消息广播 s → c
{ "type": "text", "text": "我要聊天", "uid": "1412956275584", "avatar": "", "username": "" }
已登录用户消息广播 s → c
{ "type": "text", "text": "我要聊天", "uid": "1412956275584", "userid": "uid84603", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "username": "用户84603", "userinfo": "这家伙很懒,什么也没说" }
3.7 私密消息
发送私密消息
单个用户 c → s
{ "type": "sendto", "text": "私密消息发送", "touids": "1412956275248" }
多个用户 c → s
{ "type": "sendto", "text": "私密消息发送", "touids": ["1412956275248", "1412956275228"] }
接收私密消息 s → c
{ "type": "sendto", "text": "私密消息发送", "uid": "1412956275584", "userid": "uid55710", "avatar": "https://img1.baidu.com/it/u=2121025603,1672671484&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500", "username": "用户55710", "userinfo": "这家伙很懒,什么也没说" }
3.8 禁词过滤
服务器端可以通过WebSocket设置禁词过滤,禁词过滤应该用后台管理系统设置。
禁词过滤命令以 setbadwords:
字符串开始,后面跟禁词, 为回车换行实际码。
等号 =
分割,=
前为禁词,=
后为要替换的好词,=
后的内容可以没有,=
两边没有空格。
c → s 实例:
setbadwords: 禁词1=好词1 禁词2=好词2 删除1= 删除2=