OpenIM Simple Chat Client
++ 这是一个最小开发态聊天客户端。它用 admin token 代发消息、用搜索接口轮询消息列表, + 目的是让你先在本地把“能聊起来”这件事跑通。它不等价于正式客户端,不做权限隔离。 +
+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 @@ + + +
+ + ++ 这是一个最小开发态聊天客户端。它用 admin token 代发消息、用搜索接口轮询消息列表, + 目的是让你先在本地把“能聊起来”这件事跑通。它不等价于正式客户端,不做权限隔离。 +
+
+ 这个页面只依赖浏览器和本地 OpenIM HTTP API。默认对接
+ http://127.0.0.1:10002,用于快速拿 token、发文本消息、查看原始响应。
+
/auth/get_admin_token。注意:
+ imAdmin 必须已经在你的本地环境里存在。
+ /auth/get_user_token,请求头使用上面的 admin token。
+ 页面发消息本身不依赖 user token。
+ /msg/send_msg,当前只封装最简单的文本消息格式:
+ {"content":{"content":"..."}}。
+ Ready.
{}
+ {}
+
+ 这个页面是真正走 WebSocket 的最小 OpenIM 浏览器客户端。它使用浏览器原生
+ new WebSocket(url) 握手,再用 OpenIM 的 JSON envelope +
+ protobuf 数据体发二进制帧。
+