Skip to content

Commit 91d9912

Browse files
authored
Merge pull request #279 from HuolalaTech/fix/event-stream
Fill 'id' in EventStream
2 parents 6f38a59 + d86915c commit 91d9912

File tree

5 files changed

+66
-46
lines changed

5 files changed

+66
-46
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
},
5050
"dependencies": {
5151
"@ant-design/icons": "^4.7.0",
52-
"@huolala-tech/page-spy-browser": "^1.9.13",
53-
"@huolala-tech/page-spy-plugin-data-harbor": "^1.3.11",
54-
"@huolala-tech/page-spy-plugin-rrweb": "^1.2.7",
55-
"@huolala-tech/page-spy-plugin-whole-bundle": "^0.0.9",
52+
"@huolala-tech/page-spy-browser": "^1.9.14",
53+
"@huolala-tech/page-spy-plugin-data-harbor": "^1.3.12",
54+
"@huolala-tech/page-spy-plugin-rrweb": "^1.2.8",
55+
"@huolala-tech/page-spy-plugin-whole-bundle": "^0.0.10",
5656
"@huolala-tech/page-spy-types": "^1.9.6",
5757
"@huolala-tech/react-json-view": "^1.2.5",
5858
"@huolala-tech/request": "^1.1.2",

src/components/NetworkTable/ResponseBody/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const MediaWidget = ({ dataUrl }: MediaWidgetProps) => {
120120
};
121121

122122
interface EventData {
123+
id: string;
123124
time: number;
124125
data: string;
125126
}
@@ -138,7 +139,7 @@ const EventStream = ({ data }: { data: EventData[] }) => {
138139
<tbody>
139140
{data.map((item, index) => (
140141
<tr key={index}>
141-
<td>--</td>
142+
<td>{item.id}</td>
142143
<td>message</td>
143144
<td>
144145
<ReactJsonView source={item.data} />

src/store/socket-message/index.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { produce } from 'immer';
44
import { CUSTOM_EVENT, SocketStore } from './socket';
55
import {
66
SpyConsole,
7-
SpyNetwork,
87
SpySystem,
98
SpyPage,
109
SpyStorage,
@@ -18,6 +17,7 @@ import { getFixedPageMsg, processMPNetworkMsg } from './utils';
1817
import { isArray, isEqual, isString, omit } from 'lodash-es';
1918
import { parseClientInfo, ParsedClientInfo } from '@/utils/brand';
2019
import { StorageType } from '../platform-config';
20+
import type { RequestItem } from '@huolala-tech/page-spy-base';
2121

2222
const USER_ID = 'Debugger';
2323

@@ -107,7 +107,7 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
107107
}),
108108
);
109109
});
110-
socket.addListener('network', (data: SpyNetwork.RequestInfo) => {
110+
socket.addListener('network', (data: RequestItem) => {
111111
const { name, pathname, getData } = resolveUrlInfo(data.url);
112112

113113
const newData: ResolvedNetworkInfo = {
@@ -125,41 +125,46 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
125125
if (browserType.startsWith('mp-') || sdk === 'uniapp' || sdk === 'taro') {
126126
processMPNetworkMsg(newData);
127127
}
128-
const cache = get().networkMsg;
129128
// 整理 xhr 的消息
130129
const { id } = newData;
130+
const cache = get().networkMsg;
131131
const index = cache.findIndex((item) => item.id === id);
132132
if (index !== -1) {
133-
const { requestType, response = '', status, endTime } = newData;
133+
const {
134+
requestType,
135+
response = '',
136+
status,
137+
endTime,
138+
lastEventId,
139+
} = newData;
134140
// eventsource 需要合并 response
135141
// eventsource 的 'open / error' 事件都没有 response,'message' 事件可能会带着 response
136142
// status === 200 是在 SDK 中硬编码的,和 'message' 事件对应
137143
if (requestType === 'eventsource' && status === 200) {
138-
const { response: cacheData, endTime: cacheTime } = cache[index];
139-
if (!cacheData) {
140-
newData.response = [
141-
{
142-
time: endTime,
143-
data: response,
144-
},
145-
];
146-
}
144+
const {
145+
response: cacheData,
146+
endTime: cacheTime,
147+
lastEventId: cacheId,
148+
} = cache[index];
147149
if (isString(cacheData)) {
148150
newData.response = [
149151
{
152+
id: cacheId,
150153
time: cacheTime,
151154
data: cacheData,
152155
},
153156
{
157+
id: lastEventId,
154158
time: endTime,
155159
data: response,
156160
},
157161
];
158162
}
159-
if (isArray(cache[index].response)) {
163+
if (isArray(cacheData)) {
160164
newData.response = [
161-
...cache[index].response,
165+
...cacheData,
162166
{
167+
id: lastEventId,
163168
time: endTime,
164169
data: response,
165170
},

src/utils/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SpyNetwork } from '@huolala-tech/page-spy-types';
1+
import type { RequestItem } from '@huolala-tech/page-spy-base';
22
import {
33
EventType,
44
eventWithTime,
@@ -98,7 +98,7 @@ export function resolveUrlInfo(url: string): ResolvedUrlInfo {
9898
}
9999
}
100100

101-
export type ResolvedNetworkInfo = SpyNetwork.RequestInfo & ResolvedUrlInfo;
101+
export type ResolvedNetworkInfo = RequestItem & ResolvedUrlInfo;
102102

103103
interface RRWebClickEvent {
104104
type: EventType.IncrementalSnapshot;

yarn.lock

+38-24
Original file line numberDiff line numberDiff line change
@@ -742,43 +742,50 @@
742742
dependencies:
743743
"@huolala-tech/page-spy-types" "^1.9.6"
744744

745-
"@huolala-tech/page-spy-browser@^1.9.13":
746-
version "1.9.13"
747-
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-browser/-/page-spy-browser-1.9.13.tgz#33975e10716590b99cfe6074ebc00ca5e6e227ab"
748-
integrity sha512-Bb6Vz3lZaaH9Ko36xm9jxKCdPHysk27k2uL+5jlqZ/x03ecqTAcrpHfKt7oBqbUXYLLaWyYydXr8OQ6s8rtvvg==
745+
"@huolala-tech/page-spy-base@^1.0.7":
746+
version "1.0.7"
747+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-base/-/page-spy-base-1.0.7.tgz#8fdabfd24a05607192c94cc36bdff6b92c1e389f"
748+
integrity sha512-4t3xqbE8p8PPbrY8Wrzg6KTkQ/9k0UYPo02AjotV9mejRcvzkYU8E/I8EbBYTfqXCo02ObuVeJK9/o2vQs1uxA==
749+
dependencies:
750+
"@huolala-tech/page-spy-types" "^1.9.7"
751+
752+
"@huolala-tech/page-spy-browser@^1.9.14":
753+
version "1.9.14"
754+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-browser/-/page-spy-browser-1.9.14.tgz#d400bdab9523978a21fa7d8c350c529f51b57dea"
755+
integrity sha512-QNtxAnkVLlDu0Z3QTWzy0EXCEiUeSAWKht+EgC0pClU6X87Ss3aMbIgzRSBhIW/8rG0bVaKRY1TG+nrb+qPYMQ==
749756
dependencies:
750757
"@babel/runtime" "^7.13.0"
751-
"@huolala-tech/page-spy-base" "^1.0.6"
752-
"@huolala-tech/page-spy-types" "^1.9.6"
758+
"@huolala-tech/page-spy-base" "^1.0.7"
759+
"@huolala-tech/page-spy-types" "^1.9.7"
753760
copy-to-clipboard "^3.3.1"
754761

755-
"@huolala-tech/page-spy-plugin-data-harbor@^1.3.11":
756-
version "1.3.11"
757-
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-data-harbor/-/page-spy-plugin-data-harbor-1.3.11.tgz#9745e0a5b278fffd4f1929a3dbbfa84ff17f589a"
758-
integrity sha512-O8+MsV13QA+poKxUas/YQNFI9nImEKE6yCrQAqclq+qs/GkQaZluYpiEEkbONSQ8Umxq8ERW1Pxh81aCOcouWw==
762+
"@huolala-tech/page-spy-plugin-data-harbor@^1.3.12":
763+
version "1.3.12"
764+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-data-harbor/-/page-spy-plugin-data-harbor-1.3.12.tgz#e0ebc0c9174edb4bfab415c68f65f49629963572"
765+
integrity sha512-awkm9yKyEPmII74UtPTzYRwPSX3xrFmE4qHFMUQKM1RT15u85zGzPbOiU5pkJ+B1OTBlIUlmvd76T3XIZrDHmg==
759766
dependencies:
760767
"@babel/runtime" "^7.13.0"
761-
"@huolala-tech/page-spy-base" "^1.0.6"
768+
"@huolala-tech/page-spy-base" "^1.0.7"
762769
fflate "^0.8.1"
763770

764-
"@huolala-tech/page-spy-plugin-rrweb@^1.2.7":
765-
version "1.2.7"
766-
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-rrweb/-/page-spy-plugin-rrweb-1.2.7.tgz#ee46416a1ca72c3c94b2a35c7989ccf5ddaad8d7"
767-
integrity sha512-TPuQfKep0hR33aaSnM8NoKTClYDjKcrovjn51G3r5P+E4JOSHyMJZx4q+Z1t4kkKcRr260vJNlcpi7C8CpbISg==
771+
"@huolala-tech/page-spy-plugin-rrweb@^1.2.8":
772+
version "1.2.8"
773+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-rrweb/-/page-spy-plugin-rrweb-1.2.8.tgz#9cc7e2969df8d06f810d5049ba104c7f27cbfc30"
774+
integrity sha512-uuOEnMbyZiKv/3gAm86FEmQ04BH1Uipx5teZTJ5XCX7ocGZ144yI/3o/cavnIwqMIT//tkEmUjZUjhTf+XlX3w==
768775
dependencies:
769776
"@babel/runtime" "^7.13.0"
770-
"@huolala-tech/page-spy-base" "^1.0.6"
771-
"@huolala-tech/page-spy-types" "^1.9.6"
777+
"@huolala-tech/page-spy-base" "^1.0.7"
778+
"@huolala-tech/page-spy-types" "^1.9.7"
772779
rrweb "^2.0.0-alpha.4"
773780

774-
"@huolala-tech/page-spy-plugin-whole-bundle@^0.0.9":
775-
version "0.0.9"
776-
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-whole-bundle/-/page-spy-plugin-whole-bundle-0.0.9.tgz#c2137b06dc236c082a825835054f6e4dcb53c404"
777-
integrity sha512-rZFVf1gTwgSLUHmbX6DmukGPHS0Vz+CiCe4bs2rSdl1qC94wfoGKhGLEtWfi3hQdZqkub9+4EJVdyKlDu3S8/A==
781+
"@huolala-tech/page-spy-plugin-whole-bundle@^0.0.10":
782+
version "0.0.10"
783+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-plugin-whole-bundle/-/page-spy-plugin-whole-bundle-0.0.10.tgz#03beb851e3812843ef6a5167f2173a971d464ab0"
784+
integrity sha512-4vfGPkG7IpMYIgYrlQP/iOCvnnS440W4YMWA+HDG/Lmulzshhb2cTyZNPYx01F95uHt8E3Bo21j/48GPAART0g==
778785
dependencies:
779-
"@huolala-tech/page-spy-browser" "^1.9.13"
780-
"@huolala-tech/page-spy-plugin-data-harbor" "^1.3.11"
781-
"@huolala-tech/page-spy-plugin-rrweb" "^1.2.7"
786+
"@huolala-tech/page-spy-browser" "^1.9.14"
787+
"@huolala-tech/page-spy-plugin-data-harbor" "^1.3.12"
788+
"@huolala-tech/page-spy-plugin-rrweb" "^1.2.8"
782789

783790
"@huolala-tech/page-spy-types@^1.9.6":
784791
version "1.9.6"
@@ -787,6 +794,13 @@
787794
dependencies:
788795
"@huolala-tech/page-spy-base" "^1.0.6"
789796

797+
"@huolala-tech/page-spy-types@^1.9.7":
798+
version "1.9.7"
799+
resolved "https://registry.yarnpkg.com/@huolala-tech/page-spy-types/-/page-spy-types-1.9.7.tgz#7d8eb3d76497088de814396c3cf6a77260c73514"
800+
integrity sha512-ZxarPu4rPCOGoiv7SCxijSlXE3AK8QZY8Gd/mJvUb2lQ2A1z+AoaU9wwc00aucHms17ndTWwBgjv8t1pzS7y1g==
801+
dependencies:
802+
"@huolala-tech/page-spy-base" "^1.0.7"
803+
790804
"@huolala-tech/react-json-view@^1.2.5":
791805
version "1.2.5"
792806
resolved "https://registry.yarnpkg.com/@huolala-tech/react-json-view/-/react-json-view-1.2.5.tgz#fa593f8bff9ac30a4c21f7f9cd5987d7f9ed3199"

0 commit comments

Comments
 (0)