Skip to content

Commit

Permalink
[harmony] add Client.getName() instead of combineName()
Browse files Browse the repository at this point in the history
  • Loading branch information
wqcstrong committed Aug 28, 2024
1 parent 49b1599 commit e18819b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 52 deletions.
4 changes: 2 additions & 2 deletions packages/page-spy-harmony/library/src/main/ets/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import url from '@ohos.url';
import http from '@ohos.net.http';
import { InitConfig } from '../types';
import { getRandomId } from '../utils';
import Client, { combineName } from '../utils/client';
import Client from '../utils/client';

interface TResponse<T> {
code: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class Request {
const scheme = this.getScheme();
const query = joinQuery({
// TODO
name: combineName(Client.info),
name: Client.getName(),
group: project,
title,
});
Expand Down
34 changes: 0 additions & 34 deletions packages/page-spy-harmony/library/src/main/ets/helpers/socket.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import webSocket from '@ohos.net.webSocket';
import { InitConfig } from '../types';
import { psLog, stringifyData } from '../utils';
import Client, { combineName } from '../utils/client';
import { UPDATE_ROOM_INFO } from '../utils/message/server-type';
import {
SocketStoreBase,
SocketState,
Expand Down Expand Up @@ -59,37 +56,6 @@ export class OHSocketWrapper extends SocketWrapper {
export class OHSocketStore extends SocketStoreBase {
protected socketWrapper: OHSocketWrapper = new OHSocketWrapper();

public getPageSpyConfig: (() => Required<InitConfig>) | null = null;

updateRoomInfo() {
if (this.getPageSpyConfig) {
const { project, title } = this.getPageSpyConfig();
const name = combineName(Client.info);

this.send(
{
type: UPDATE_ROOM_INFO,
content: {
info: {
name,
group: project,
tags: {
title,
name,
group: project,
},
},
},
},
true,
);
}
}

public getSocket() {
return this.socketWrapper;
}

onOffline(): void {
// AppStorage.delete(ROOM_SESSION_KEY);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import socketStore from '../helpers/socket';
import { InitConfig, OnInitParams, PageSpyPlugin, SpySystem } from '../types';
import Client, { combineName } from '../utils/client';
import Client from '../utils/client';
import { makeMessage } from '../utils/message';

export default class SystemPlugin implements PageSpyPlugin {
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class SystemPlugin implements PageSpyPlugin {
public static getSystemInfo() {
return {
system: {
ua: combineName(Client.info),
ua: Client.getName(),
},
features: {},
};
Expand Down
27 changes: 15 additions & 12 deletions packages/page-spy-harmony/library/src/main/ets/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ import { SpyClient } from '../types';
import deviceInfo from '@ohos.deviceInfo';
import { DEVICE_INFO } from './constants';

export const combineName = ({
osType,
osVersion,
browserType,
browserVersion,
}: SpyClient.ClientInfo) => {
// return `${osType}/${osVersion} ${browserType}/${browserVersion}`;
return DEVICE_INFO;
};

export default class Client {
static info: SpyClient.ClientInfo = {
// 硬编码 ua
ua: DEVICE_INFO,
osType: 'harmony',
osVersion: deviceInfo.osFullName,
browserType: 'harmony',
Expand All @@ -26,13 +18,24 @@ export default class Client {
static plugins: string[] = [];

static makeClientInfoMsg() {
const ua = Client.info.ua || combineName(Client.info);
const msg: SpyClient.DataItem = {
sdk: Client.info.sdk,
isDevTools: Client.info.isDevTools,
ua,
ua: Client.getName(),
plugins: Client.plugins,
};
return msg;
}

private static _name: string;

static getName() {
if (!Client._name) {
const { ua, osType, osVersion, browserType, browserVersion } =
Client.info;
Client._name =
ua || `${osType}/${osVersion} ${browserType}/${browserVersion}`;
}
return Client._name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './message';
import * as SERVER_MESSAGE_TYPE from './message/server-type';
import atom from './atom';
import { SpyBase, SpyMessage, SpySocket } from '../types';
import { InitConfig, SpyBase, SpyMessage, SpySocket } from '../types';
import { PackedEvent } from '../types/lib/socket-event';
import Client from './client';

Expand Down Expand Up @@ -109,7 +109,9 @@ export abstract class SocketWrapper {
export abstract class SocketStoreBase {
protected abstract socketWrapper: SocketWrapper;

protected abstract updateRoomInfo(): void;
public getSocket() {
return this.socketWrapper;
}

public socketUrl: string = '';

Expand Down Expand Up @@ -155,6 +157,33 @@ export abstract class SocketStoreBase {

connectable = true;

public getPageSpyConfig: (() => Required<InitConfig>) | null = null;

updateRoomInfo() {
if (this.getPageSpyConfig) {
const { project, title } = this.getPageSpyConfig();
const name = Client.getName();

this.send(
{
type: SERVER_MESSAGE_TYPE.UPDATE_ROOM_INFO,
content: {
info: {
name,
group: project,
tags: {
title,
name,
group: project,
},
},
},
},
true,
);
}
}

// response message filters, to handle some wired messages
public static messageFilters: ((data: any) => any)[] = [];

Expand Down

0 comments on commit e18819b

Please sign in to comment.