From c17a2cd9a089415dac3c968f5adb0d5ae6b84d48 Mon Sep 17 00:00:00 2001 From: frankyu130 Date: Wed, 1 Apr 2026 15:51:54 +0800 Subject: [PATCH] Add minimal OpenIM web test clients --- scripts/debug_msggateway_ws.sh | 33 ++ test/e2e/web/Readme.md | 47 ++ test/e2e/web/chat.html | 732 +++++++++++++++++++++++++++++++ test/e2e/web/index.html | 515 ++++++++++++++++++++++ test/e2e/web/ws-demo.html | 757 +++++++++++++++++++++++++++++++++ 5 files changed, 2084 insertions(+) create mode 100755 scripts/debug_msggateway_ws.sh create mode 100644 test/e2e/web/chat.html create mode 100644 test/e2e/web/index.html create mode 100644 test/e2e/web/ws-demo.html diff --git a/scripts/debug_msggateway_ws.sh b/scripts/debug_msggateway_ws.sh new file mode 100755 index 000000000..ffa596768 --- /dev/null +++ b/scripts/debug_msggateway_ws.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +MODE="${1:-before-rpc}" + +case "$MODE" in + gateway) + export OPENIM_WS_BREAK_ON_SEND=1 + ;; + before-rpc) + export OPENIM_WS_BREAK_BEFORE_SENDMSG_RPC=1 + ;; + after-rpc) + export OPENIM_WS_BREAK_AFTER_SENDMSG_RPC=1 + ;; + *) + echo "usage: $0 [gateway|before-rpc|after-rpc]" >&2 + exit 1 + ;; +esac + +if [ -d /opt/homebrew/opt/openjdk ]; then + export JAVA_HOME=/opt/homebrew/opt/openjdk + export PATH="/opt/homebrew/bin:$JAVA_HOME/bin:$PATH" +fi + +export PATH="$HOME/go/bin:$PATH" + +cd "$ROOT_DIR" + +exec dlv debug ./cmd -- -c ./config diff --git a/test/e2e/web/Readme.md b/test/e2e/web/Readme.md index 741ca51d5..5421c2eaa 100644 --- a/test/e2e/web/Readme.md +++ b/test/e2e/web/Readme.md @@ -1,2 +1,49 @@ # OpenIM Web E2E +Minimal local web page for exercising OpenIM HTTP message APIs from a browser. + +Usage: + +```bash +cd /Users/ren_yu/open-source/open-im-server/test/e2e/web +python3 -m http.server 18080 +``` + +Open [http://127.0.0.1:18080](http://127.0.0.1:18080) after the OpenIM server is running. + +Pages: + +- `http://127.0.0.1:18080/` - token and message API tester +- `http://127.0.0.1:18080/chat.html` - simplest dev chat client +- `http://127.0.0.1:18080/ws-demo.html` - simplest native browser OpenIM WS client + +Default local endpoints: + +- API: `http://127.0.0.1:10002` +- WebSocket gateway: `ws://127.0.0.1:10001` + +Defaults from this repo: + +- admin user ID: `imAdmin` +- secret: `openIM123` + +Notes: + +- `/auth/get_admin_token` requires the admin user to already exist. +- `/msg/send_msg` requires an admin token in the `token` header. +- The included page currently sends plain text messages through `/msg/send_msg`. +- `chat.html` is a development-only client: it uses admin-backed APIs to send and search messages between two users. +- `ws-demo.html` performs a real browser WebSocket handshake and sends OpenIM WS envelopes over binary frames. +- The WS gateway in this repo currently expects `isBackground=false` in the query string; omitting it causes the handshake to fail before upgrade. + +Debugging: + +```bash +cd /Users/ren_yu/open-source/open-im-server +./scripts/debug_msggateway_ws.sh before-rpc +``` + +- `gateway` stops at the WS gateway after the envelope is decoded. +- `before-rpc` stops right before `g.msgClient.MsgClient.SendMsg(...)`. +- `after-rpc` stops right after `g.msgClient.MsgClient.SendMsg(...)` returns. +- These breakpoints only apply to `ws-demo.html`, not `chat.html` or `/msg/send_msg`. diff --git a/test/e2e/web/chat.html b/test/e2e/web/chat.html new file mode 100644 index 000000000..868af0131 --- /dev/null +++ b/test/e2e/web/chat.html @@ -0,0 +1,732 @@ + + + + + + OpenIM Simple Chat Client + + + +
+
+

OpenIM Simple Chat Client

+

+ 这是一个最小开发态聊天客户端。它用 admin token 代发消息、用搜索接口轮询消息列表, + 目的是让你先在本地把“能聊起来”这件事跑通。它不等价于正式客户端,不做权限隔离。 +

+
+ +
+ + +
+
+
+
双人单聊
+
未连接
+
+
轮询中
+
+ +
+ + +
+ +
+
+ 还没有消息。先点左侧“连接并初始化”,然后选择发送者发第一条消息。 +
+
+ +
+ + +
+
+
+
+ + + + diff --git a/test/e2e/web/index.html b/test/e2e/web/index.html new file mode 100644 index 000000000..213c5a4f7 --- /dev/null +++ b/test/e2e/web/index.html @@ -0,0 +1,515 @@ + + + + + + OpenIM Local Message Tester + + + +
+

OpenIM Local Message Tester

+

+ 这个页面只依赖浏览器和本地 OpenIM HTTP API。默认对接 + http://127.0.0.1:10002,用于快速拿 token、发文本消息、查看原始响应。 +

+ +
+
+

连接配置

+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ 当前页面实际调用的是 HTTP API。WebSocket 地址先展示出来,后续如果你要测推送回包,可以直接在这个页面上扩展。 +
+
+ +
+

管理员 Token

+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ 这里命中 /auth/get_admin_token。注意: + imAdmin 必须已经在你的本地环境里存在。 +
+
+ +
+

用户 Token

+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ 这里命中 /auth/get_user_token,请求头使用上面的 admin token。 + 页面发消息本身不依赖 user token。 +
+
+ +
+

发送文本消息

+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+ 这里命中 /msg/send_msg,当前只封装最简单的文本消息格式: + {"content":{"content":"..."}}。 +
+
+ +
+

状态

+
Ready.
+
+ +
+

最后一次请求

+
{}
+
+ +
+

最后一次响应

+
{}
+
+
+
+ + + + diff --git a/test/e2e/web/ws-demo.html b/test/e2e/web/ws-demo.html new file mode 100644 index 000000000..04fe7f5a0 --- /dev/null +++ b/test/e2e/web/ws-demo.html @@ -0,0 +1,757 @@ + + + + + + OpenIM WS Demo + + + + +
+

OpenIM WS Demo

+

+ 这个页面是真正走 WebSocket 的最小 OpenIM 浏览器客户端。它使用浏览器原生 + new WebSocket(url) 握手,再用 OpenIM 的 JSON envelope + + protobuf 数据体发二进制帧。 +

+ +
+ + +
+
+
+ 连接状态 +
未连接
+
+
msgIncr=0
+
+ +
+

Last URL

+
尚未构造
+
+ +
+

Raw Envelope

+
尚未发送
+
+ +
+
+
+
+ + + +