diff --git a/ETSUI/PatternLock/.gitignore b/ETSUI/PatternLock/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4222b99195171f6433f7abe1fecaf4121895cce4 --- /dev/null +++ b/ETSUI/PatternLock/.gitignore @@ -0,0 +1,8 @@ +/node_modules +/local.properties +/.idea +**/build +/.hvigor +/build-profile.json5 +/package-lock.json +/entry/package-lock.json \ No newline at end of file diff --git a/ETSUI/PatternLock/AppScope/app.json5 b/ETSUI/PatternLock/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ef734f3931509ec2b3b8eba0f330993f823bfc46 --- /dev/null +++ b/ETSUI/PatternLock/AppScope/app.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "ohos.samples.patternlock", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/ETSUI/PatternLock/AppScope/resources/base/element/string.json b/ETSUI/PatternLock/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ad78a51cebaf4e5fcf17f3a1a24315ee9accf432 --- /dev/null +++ b/ETSUI/PatternLock/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "PatternLock" + } + ] +} diff --git a/ETSUI/PatternLock/AppScope/resources/base/media/app_icon.png b/ETSUI/PatternLock/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/PatternLock/AppScope/resources/base/media/app_icon.png differ diff --git a/ETSUI/PatternLock/README_zh.md b/ETSUI/PatternLock/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..cfbac40d17c6bf7af23d455cd5198d4f9cc36f6a --- /dev/null +++ b/ETSUI/PatternLock/README_zh.md @@ -0,0 +1,35 @@ +# 图案密码锁组件 + +### 介绍 + +本示例展示了图案密码锁组件的使用,实现了密码设置、验证和重置功能。 + +1.首次进入时需要设置密码,需要两次输入密码相同后点击**设置密码**进行设置,如果第二次输入密码和第一次输入密码不不同,会提示重新输入。 + +2.设置密码后,需要输入密码解锁,退出应用后重新进入应用,需要再次输入密码验证,密码验证成功进入主页。 + +3.设置密码后,在输入密码界面有**重置密码**按钮,点击后需要输入旧密码,旧密码验证成功后开始设置新的密码。 + + +### 效果预览 + +-![home](screenshots/device/home.png) ![play1](screenshots/device/input.png) ![play2](screenshots/device/set_password.png) + + +### 相关权限 + +不涉及。 + + +### 依赖 + +不涉及。 + + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例仅支持API version 9版本SDK,版本号:3.2.7.5。 + +3.本示例需要使用DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022)才可编译运行。 \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/build-profile.json5 b/ETSUI/PatternLock/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7c2d349aef78d1076bf104b48de3eda6db86f54e --- /dev/null +++ b/ETSUI/PatternLock/entry/build-profile.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} diff --git a/ETSUI/PatternLock/entry/hvigorfile.js b/ETSUI/PatternLock/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/ETSUI/PatternLock/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/ETSUI/PatternLock/entry/package.json b/ETSUI/PatternLock/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..29732ffea047ab4e9d897d4cc7092f5e7fe3493f --- /dev/null +++ b/ETSUI/PatternLock/entry/package.json @@ -0,0 +1,14 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/ETSUI/PatternLock/entry/src/main/ets/Application/AbilityStage.ts b/ETSUI/PatternLock/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..307ab7ceefc0479e48b696024e1d9e6c6e2feda7 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" +import Logger from '../model/Logger' + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + Logger.info('[MyAbilityStage]', 'onCreate') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/MainAbility/MainAbility.ts b/ETSUI/PatternLock/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..b911bec7361d8490c9b14a37156699e00bb93d8d --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' +import Logger from '../model/Logger' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + Logger.info('[MainAbility]', 'onCreate') + } + + onDestroy() { + Logger.info('[MainAbility]', 'onDestroy') + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + Logger.info('[MainAbility]', 'onWindowStageCreate') + + windowStage.setUIContent(this.context, "pages/Index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('[MainAbility]', 'onWindowStageDestroy') + } + + onForeground() { + // Ability has brought to foreground + Logger.info('[MainAbility]', 'onForeground') + } + + onBackground() { + // Ability has back to background + Logger.info('[MainAbility]', 'onBackground') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/common/TitleBar.ets b/ETSUI/PatternLock/entry/src/main/ets/common/TitleBar.ets new file mode 100644 index 0000000000000000000000000000000000000000..a828c7fa159d50cbd9aa6e4492a1d9a61c645e5c --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/common/TitleBar.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export default struct TitleBar { + private title: Resource = $r('app.string.MainAbility_label') + + build() { + Row() { + Text(this.title) + .fontColor(Color.White) + .fontSize(28) + } + .width('100%') + .height('8%') + .constraintSize({ minHeight: 70 }) + .padding({ left: 10, right: 10 }) + .backgroundColor('#0D9FFB') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/model/Logger.ts b/ETSUI/PatternLock/entry/src/main/ets/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae3f957e1507ee792dc3bf89c552eccfae406f8f --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/model/Logger.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog' + +class Logger { + private domain: number + private prefix: string + private format: string = '%{public}s, %{public}s' + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + } + + debug(...args: any[]) { + hilog.debug(this.domain, this.prefix, this.format, args) + } + + info(...args: any[]) { + hilog.info(this.domain, this.prefix, this.format, args) + } + + warn(...args: any[]) { + hilog.warn(this.domain, this.prefix, this.format, args) + } + + error(...args: any[]) { + hilog.error(this.domain, this.prefix, this.format, args) + } +} + +export default new Logger('[PatternLock]') \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/model/PreferencesUtils.ts b/ETSUI/PatternLock/entry/src/main/ets/model/PreferencesUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b648875b80458b39f48ed05dd43aa8163f6c6f6 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/model/PreferencesUtils.ts @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import preferences from '@ohos.data.preferences' +import Logger from '../model/Logger' + +const TAG: string = '[PreferencesUtils]' +const PREFERENCES_NAME: string = 'myPreferences' +const PASSWORD_KEY: string = 'password' + +class PreferencesUtils { + private mPreferences: preferences.Preferences | undefined = undefined + + async getPassword(context: any) { + Logger.info(TAG, `get passworld`) + if (this.mPreferences === undefined) { + this.mPreferences = await preferences.getPreferences(context, PREFERENCES_NAME) + } + return await this.mPreferences.get(PASSWORD_KEY, 'null') + } + + async setPassword(passWorld: string, context: any) { + Logger.info(TAG, `set passworld`) + if (this.mPreferences === undefined) { + this.mPreferences = await preferences.getPreferences(context, PREFERENCES_NAME) + } + await this.mPreferences.put(PASSWORD_KEY, passWorld) + await this.mPreferences.flush() + Logger.debug(TAG, `setPassword end`) + } +} +export default new PreferencesUtils() \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/pages/Home.ets b/ETSUI/PatternLock/entry/src/main/ets/pages/Home.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb844086ee6bc9339cacb974df42d4a07d2ac7ec --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/pages/Home.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TitleBar from '../common/TitleBar' + +@Entry +@Component +struct Home { + build() { + Column() { + TitleBar() + Stack() { + Image($r('app.media.home')) + .width('100%') + .height('100%') + .objectFit(ImageFit.Fill) + .opacity(0.3) + Text($r('app.string.message_unlock')) + .fontSize(35) + .fontWeight(FontWeight.Bold) + .padding(20) + .alignSelf(ItemAlign.Center) + } + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + .backgroundColor('#F0F0F0') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/ets/pages/Index.ets b/ETSUI/PatternLock/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..938f47d56323e616df7b718167ecea0e491ecc86 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router' +import Logger from '../model/Logger' +import PreferencesUtils from '../model/PreferencesUtils' +import TitleBar from '../common/TitleBar' + +const TAG: string = 'Index' + +@Entry +@Component +struct Index { + private defaultPassword: string = '' + private patternLockController: PatternLockController = new PatternLockController() + @State message: Resource = $r('app.string.message_input') + @State isReset: boolean = false + @State password: Array = [] + @State isHasPass: boolean = true + @State isShowSetting: boolean = false + + build() { + Column() { + TitleBar() + Column() { + if (this.isHasPass && !this.isReset) { + Text($r('app.string.reset_password')) + .fontSize(25) + .fontWeight(FontWeight.Bold) + .padding(20) + .width('100%') + .fontColor(Color.Blue) + .onClick(() => { + this.isReset = true + this.message = $r('app.string.message_input_old') + this.password = [] + this.patternLockController.reset() + }) + } + Text(this.message) + .textAlign(TextAlign.Center) + .fontSize(30) + .width('90%') + .padding(10) + PatternLock(this.patternLockController) + .sideLength(300) + .circleRadius(15) + .pathStrokeWidth(15) + .autoReset(true) + .margin({ top: 30, bottom: 50 }) + .onPatternComplete((input: Array) => { + if (input === null || input === undefined || input.length < 5) { + this.message = $r('app.string.message_password_length_insufficient') + return + } + if (this.isHasPass) { + if (this.defaultPassword === input.toString()) { + if (this.isReset) { + this.message = $r('app.string.message_input_new') + this.defaultPassword = 'null' + this.patternLockController.reset() + this.password = [] + this.isHasPass = false + return + } + router.replace({ + url: 'pages/Home' + }) + } else { + this.message = $r('app.string.message_incorrect') + this.password = [] + return + } + } + if (this.password.length > 0) { + if (this.password.toString() === input.toString()) { + this.password = input + this.message = $r('app.string.message_correct') + this.isShowSetting = true + } else { + this.message = $r('app.string.message_not_match') + this.patternLockController.reset() + } + } else { + this.password = input + this.message = $r('app.string.message_input_again') + this.patternLockController.reset() + } + }) + if (this.isShowSetting) { + Button($r('app.string.message_set_password')) + .key('setPassword') + .margin(30) + .width('60%') + .onClick(() => { + this.setPassword() + }) + } + } + .layoutWeight(1) + .justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + .backgroundImage($r('app.media.bg')) + .backgroundImageSize(ImageSize.Cover) + .opacity(0.7) + } + + async aboutToAppear() { + this.password = [] + this.defaultPassword = await PreferencesUtils.getPassword(getContext(this)) + if (this.defaultPassword === 'null') { + this.isHasPass = false + } else { + this.isHasPass = true + } + } + + async setPassword() { + this.defaultPassword = this.password.toString() + await PreferencesUtils.setPassword(this.defaultPassword, getContext(this)) + this.message = $r('app.string.message_set_success') + this.isShowSetting = false + this.isHasPass = true + this.password = [] + this.patternLockController.reset() + this.isReset = false + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/module.json5 b/ETSUI/PatternLock/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..00a68bdcdd63d40c5d5917117f1adc9d0f450b3b --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/module.json5 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "launchType": "singleton", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/element/color.json b/ETSUI/PatternLock/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/element/string.json b/ETSUI/PatternLock/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..68e07aea8ef7dd29b978ad48e3c3051a22f25a5a --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/resources/base/element/string.json @@ -0,0 +1,64 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "PatternLock" + }, + { + "name": "MainAbility_desc", + "value": "PatternLock" + }, + { + "name": "MainAbility_label", + "value": "PatternLock" + }, + { + "name": "message_input", + "value": "Please input password" + }, + { + "name": "message_input_old", + "value": "Please input old password" + }, + { + "name": "message_input_new", + "value": "Correct password,Please input new password" + }, + { + "name": "message_password_length_insufficient", + "value": "The password length needs to be greater than 5" + }, + { + "name": "message_input_again", + "value": "Input password again" + }, + { + "name": "message_not_match", + "value": "The password does not match the last time, please re-enter" + }, + { + "name": "message_correct", + "value": "Correct password,click \"Set password\"" + }, + { + "name": "message_incorrect", + "value": "Incorrect password" + }, + { + "name": "message_set_password", + "value": "Set password" + }, + { + "name": "message_set_success", + "value": "The password is set successfully, enter the password again to unlock" + }, + { + "name": "message_unlock", + "value": "Unlock successfully, welcome to the home page" + }, + { + "name": "reset_password", + "value": "Reset password" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/media/bg.png b/ETSUI/PatternLock/entry/src/main/resources/base/media/bg.png new file mode 100644 index 0000000000000000000000000000000000000000..00cc73f4cc0331b59682045f4137d8f168aec8f5 Binary files /dev/null and b/ETSUI/PatternLock/entry/src/main/resources/base/media/bg.png differ diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/media/home.png b/ETSUI/PatternLock/entry/src/main/resources/base/media/home.png new file mode 100644 index 0000000000000000000000000000000000000000..48d48a42818b15ac3b8233ddb96c6146a8ed765d Binary files /dev/null and b/ETSUI/PatternLock/entry/src/main/resources/base/media/home.png differ diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/media/ic_back.png b/ETSUI/PatternLock/entry/src/main/resources/base/media/ic_back.png new file mode 100644 index 0000000000000000000000000000000000000000..9f793557fd1ba7a4941e2ba4dea6fc2316eb5f24 Binary files /dev/null and b/ETSUI/PatternLock/entry/src/main/resources/base/media/ic_back.png differ diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/media/icon.png b/ETSUI/PatternLock/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/PatternLock/entry/src/main/resources/base/media/icon.png differ diff --git a/ETSUI/PatternLock/entry/src/main/resources/base/profile/main_pages.json b/ETSUI/PatternLock/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..a8ae5784105280a37d41acb5a8f3453abb9fa736 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/Index", + "pages/Home" + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/resources/en/element/string.json b/ETSUI/PatternLock/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..22e23961e5ea9a4d16f9a04d1b1034f9a12316f9 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/resources/en/element/string.json @@ -0,0 +1,63 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "PatternLock" + }, + { + "name": "MainAbility_desc", + "value": "PatternLock" + }, + { + "name": "MainAbility_label", + "value": "PatternLock" + }, + { + "name": "message_input", + "value": "Please input password" + }, + { + "name": "message_input_old", + "value": "Please input old password" + }, + { + "name": "message_input_new", + "value": "Correct password,Please input new password" + }, + { + "name": "message_password_length_insufficient", + "value": "The password length needs to be greater than 5" + }, + { + "name": "message_input_again", + "value": "Input password again" + }, + { + "name": "message_not_match", + "value": "The password does not match the last time, please re-enter" + }, + { + "name": "message_correct", + "value": "Correct password,click \"Set password\"" + }, + { + "name": "message_incorrect", + "value": "Incorrect password" + }, + { + "name": "message_set_password", + "value": "Set password" + }, + { + "name": "message_set_success", + "value": "The password is set successfully, enter the password again to unlock" + }, + { + "name": "message_unlock", + "value": "Unlock successfully, welcome to the home page" + }, { + "name": "reset_password", + "value": "Reset password" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/main/resources/zh/element/string.json b/ETSUI/PatternLock/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1af4176b0afcc01dca0e231833671feb8756dc1d --- /dev/null +++ b/ETSUI/PatternLock/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,64 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "图案密码锁" + }, + { + "name": "MainAbility_desc", + "value": "图案密码锁" + }, + { + "name": "MainAbility_label", + "value": "图案密码锁" + }, + { + "name": "message_input", + "value": "请输入密码" + }, + { + "name": "message_input_old", + "value": "请输入旧密码" + }, + { + "name": "message_input_new", + "value": "密码正确,请出入新的密码" + }, + { + "name": "message_password_length_insufficient", + "value": "密码长度需要大于5" + }, + { + "name": "message_input_again", + "value": "再次输入密码" + }, + { + "name": "message_not_match", + "value": "密码与上一次不一致,请重新输入" + }, + { + "name": "message_correct", + "value": "密码正确,点击\"设置密码\"" + }, + { + "name": "message_incorrect", + "value": "密码错误" + }, + { + "name": "message_set_password", + "value": "设置密码" + }, + { + "name": "message_set_success", + "value": "密码设置成功,再次输入密码解锁" + }, + { + "name": "message_unlock", + "value": "解锁成功,欢迎进入主页" + }, + { + "name": "reset_password", + "value": "重置密码" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/ETSUI/PatternLock/entry/src/ohosTest/ets/Application/TestAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..87cde7ba9135814090a1b5f14b0fa9b39b8d8c22 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/Application/TestAbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..f7e64aca859f8e2b41b8a94bc937d602244597e9 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)) + return + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }) + + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d93696fbcc27bfa21f70894e650da12023734ca --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router' + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..7b0f409c3e76cdbfac374a5fed8463a5d6ec9834 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = '' + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback") +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + } + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') { + cmd += ' -D' + } + console.info('cmd : ' + cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)) + console.info('executeShellCommand : data : ' + d.stdResult) + console.info('executeShellCommand : data : ' + d.exitCode) + }) + console.info('OpenHarmonyTestRunner onRun end') + } +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/test/List.test.ets b/ETSUI/PatternLock/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7a71bf395c801c8818b06f2a486660ed9f25eee --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import appTest from './app.test' + +export default function testsuite() { + appTest() +} diff --git a/ETSUI/PatternLock/entry/src/ohosTest/ets/test/app.test.ets b/ETSUI/PatternLock/entry/src/ohosTest/ets/test/app.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..598b3ee84b51d97e10073788350742fdf4f19cf7 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/ets/test/app.test.ets @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import featureAbility from '@ohos.ability.featureAbility' +import hilog from '@ohos.hilog' + +const TAG = '[Sample_PatternLock_]' +const DOMAIN = 0xF811 +const BUNDLE = 'PatternLock__' + +export default function appTest() { + describe('appTest', function () { + it(BUNDLE + 'StartAbility_001', 0, async function (done) { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin') + let want = { + bundleName: "ohos.samples.patternlock", + abilityName: "MainAbility" + } + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + await abilityDelegator.startAbility(want, (err, data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code) + expect(0).assertEqual(err.code) + done() + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') + }) + }) + + /** + * 进入页面 + */ + it(BUNDLE + 'CreateFunction_001', 0, async function () { + hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 begin') + let driver = await UiDriver.create() + await driver.delayMs(1000) + hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 end') + }) + }) +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/module.json5 b/ETSUI/PatternLock/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a63ae7f49d2053d7220ab8ec46e1c0a04e675db --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/module.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/Application/TestAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/color.json b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/string.json b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..36d4230c53e9f5a07ae343ad8dc9808341975e3b --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ETSUI/PatternLock/entry/src/ohosTest/resources/base/media/icon.png b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ETSUI/PatternLock/entry/src/ohosTest/resources/base/profile/test_pages.json b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/ETSUI/PatternLock/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/ETSUI/PatternLock/hvigorfile.js b/ETSUI/PatternLock/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/ETSUI/PatternLock/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/ETSUI/PatternLock/package.json b/ETSUI/PatternLock/package.json new file mode 100644 index 0000000000000000000000000000000000000000..b2c4dff6065b3a624a1d65480f5190fc363bb5b7 --- /dev/null +++ b/ETSUI/PatternLock/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "patternlock", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.1", + "@ohos/hvigor-ohos-plugin": "1.1.6", + "@ohos/hvigor": "1.1.6" + } +} diff --git a/ETSUI/PatternLock/screenshots/device/home.png b/ETSUI/PatternLock/screenshots/device/home.png new file mode 100644 index 0000000000000000000000000000000000000000..2b6f8fb691f43d1760a60eafddb17cf9ed6e9318 Binary files /dev/null and b/ETSUI/PatternLock/screenshots/device/home.png differ diff --git a/ETSUI/PatternLock/screenshots/device/input.png b/ETSUI/PatternLock/screenshots/device/input.png new file mode 100644 index 0000000000000000000000000000000000000000..76529f39c45171d9aa32b0a40c2dbcb0eefae5fb Binary files /dev/null and b/ETSUI/PatternLock/screenshots/device/input.png differ diff --git a/ETSUI/PatternLock/screenshots/device/set_password.png b/ETSUI/PatternLock/screenshots/device/set_password.png new file mode 100644 index 0000000000000000000000000000000000000000..6a39ec1d473c365c623c36947d46117ffeb41089 Binary files /dev/null and b/ETSUI/PatternLock/screenshots/device/set_password.png differ diff --git a/network/WebSocket/.gitignore b/network/WebSocket/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4222b99195171f6433f7abe1fecaf4121895cce4 --- /dev/null +++ b/network/WebSocket/.gitignore @@ -0,0 +1,8 @@ +/node_modules +/local.properties +/.idea +**/build +/.hvigor +/build-profile.json5 +/package-lock.json +/entry/package-lock.json \ No newline at end of file diff --git a/network/WebSocket/AppScope/app.json5 b/network/WebSocket/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a23e6e01bd9b30107c42c9a12303caa1bd314860 --- /dev/null +++ b/network/WebSocket/AppScope/app.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "ohos.samples.websocket", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/network/WebSocket/AppScope/resources/base/element/string.json b/network/WebSocket/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e3bd0cfa5cb999c4e8817c6b4ba8346a85b36b64 --- /dev/null +++ b/network/WebSocket/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "WebSocket" + } + ] +} diff --git a/network/WebSocket/AppScope/resources/base/media/app_icon.png b/network/WebSocket/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/network/WebSocket/AppScope/resources/base/media/app_icon.png differ diff --git a/network/WebSocket/README_zh.md b/network/WebSocket/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..b23987fd5e815f04b27b8380aafb0923fdd72a66 --- /dev/null +++ b/network/WebSocket/README_zh.md @@ -0,0 +1,40 @@ +# WebSocket + +### 介绍 + +本示例展示了WebSocket的使用,包括客户端与服务端的连接和断开以及客户端数据的接收和发送。 + +WebSocket连接:使用WebSocket建立服务器与客户端的双向连接,需要先通过createWebSocket方法创建WebSocket对象,然后通过connect方法连接到服务器。 +当连接成功后,客户端会收到open事件的回调,之后客户端就可以通过send方法与服务器进行通信。 当服务器发信息给客户端时,客户端会收到message事件的回调。 +当客户端不要此连接时,可以通过调用close方法主动断开连接,之后客户端会收到close事件的回调。 + +使用方法: + +1.输入服务器IP地址,点击**绑定服务器IP地址**按钮,即可绑定该IP并退出弹框,如果要解绑IP,重启应用即可。 + +2.点击顶部栏的**连接**按钮,按钮颜色从灰色变为绿色,即可与服务器建立WebSocket连接,并开始监听服务器发来的消息。 + +3.在底部消息输入框输入消息,点击**发送**按钮,即可收到来自服务端的消息回馈。 + +4.再次点击顶部栏的**连接**按钮,按钮颜色从绿色重新变成灰色,即可与服务器断开连接,接收不到服务器发来的消息。 + +### 效果预览 + +![](screenshots/device/disconnect.png) + +### 相关权限 + +网络使用权限:ohos.permission.INTERNET + +### 依赖 +依赖于[WebSocketServer](https://gitee.com/adslk/application_server/tree/master/WebSocketServer)服务器才能实现相关功能。 + +### 约束与限制 + +1.本示例仅支持在标准系统上运行。 + +2.本项目仅包含客户端,不包含服务端,当前服务端回复客服端为固定消息。 + +3.本示例为Stage模型,从API version 9开始支持。 + +4.本示例需要使用DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022)才可编译运行。 diff --git a/network/WebSocket/entry/build-profile.json5 b/network/WebSocket/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5022f93b6d0673db0a31d252a3fc89d5bfd86022 --- /dev/null +++ b/network/WebSocket/entry/build-profile.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} diff --git a/network/WebSocket/entry/hvigorfile.js b/network/WebSocket/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/network/WebSocket/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/network/WebSocket/entry/package.json b/network/WebSocket/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4b27bb09eb4800d346d8c3903f995eb127acc93c --- /dev/null +++ b/network/WebSocket/entry/package.json @@ -0,0 +1,16 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "ohos": { + "org": "huawei", + "directoryLevel": "module", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "nodejs-websocket": "^1.7.2" + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/Application/AbilityStage.ts b/network/WebSocket/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..d1dd504ad15d125023bc71821596d5b961332b11 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Logger from '../model/Logger' +import AbilityStage from '@ohos.application.AbilityStage' + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + Logger.info('[MyAbilityStage]', 'MyAbilityStage onCreate') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/MainAbility/MainAbility.ts b/network/WebSocket/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..213d77435e093c94d8cd410622e3c7e3b31febd3 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Logger from '../model/Logger' +import Ability from '@ohos.application.Ability' + +const TAG: string = '[MainAbility]' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + Logger.info(TAG, 'MainAbility onCreate') + } + + onDestroy() { + Logger.info(TAG, 'MainAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + Logger.info(TAG, 'MainAbility onWindowStageCreate') + + windowStage.setUIContent(this.context, "pages/Chats", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info(TAG, 'MainAbility onWindowStageDestroy') + } + + onForeground() { + // Ability has brought to foreground + Logger.info(TAG, 'MainAbility onForeground') + } + + onBackground() { + // Ability has back to background + Logger.info(TAG, 'MainAbility onBackground') + } +} diff --git a/network/WebSocket/entry/src/main/ets/common/BindServiceIp.ets b/network/WebSocket/entry/src/main/ets/common/BindServiceIp.ets new file mode 100644 index 0000000000000000000000000000000000000000..fdf65775803dfe9c9e32baab3aa7b7f6d8aea26b --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/common/BindServiceIp.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export default struct BindServiceIp { + @Link ipAddress: string + private onBind: () => void + + build() { + Column() { + Text($r('app.string.welcome')) + .fontSize(25) + .margin({ top: 20 }) + .fontWeight(FontWeight.Bold) + TextInput({ placeholder: $r('app.string.ip_placeholder') }) + .height(50) + .fontSize(15) + .width('70%') + .margin({ top: 20 }) + .key('ipInput') + .onChange((value: string) => { + this.ipAddress = `ws://${value}/string` + }) + Button() { + Text($r('app.string.bind_ip')) + .fontSize(20) + .fontColor(Color.White) + } + .margin({ top: 20 }) + .width(200) + .height(50) + .type(ButtonType.Capsule) + .onClick(() => { + this.onBind() + }) + } + .width('100%') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/common/ChatsPage.ets b/network/WebSocket/entry/src/main/ets/common/ChatsPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..2252f4684f2c8b74687f1563d45a621f2291e6c7 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/common/ChatsPage.ets @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ChatData from '../model/ChatData' +import {WebSocketSource} from "../model/DataSource" + +@Component +export default struct ChatsPage { + @Link chats: WebSocketSource + + @Builder + ChatsMessage(name: Resource, message: string, direction: Direction) { + Row() { + Text(name) + .width(40) + .height(40) + .padding(5) + .fontSize(25) + .borderRadius(10) + .margin({ right: 10 }) + .backgroundColor('#e5e5e5') + .textAlign(TextAlign.Center) + Text(message) + .padding(10) + .maxLines(5) + .fontSize(20) + .borderRadius(10) + .margin({ top: 20 }) + .alignSelf(ItemAlign.Start) + .backgroundColor('#ff78dd4d') + } + .width('100%') + .direction(direction) + .margin({ top: 5, bottom: 10 }) + } + + build() { + Column() { + List() { + LazyForEach(this.chats, (item) => { + ListItem() { + if (item.isServer) { + this.ChatsMessage($r('app.string.server'), item.message, Direction.Ltr) + } else { + this.ChatsMessage($r('app.string.me'), item.message, Direction.Rtl) + } + } + .padding(10) + .width('100%') + }, item => item.message) + }.width('100%').height('100%') + } + .width('100%') + .layoutWeight(1) + .backgroundColor(Color.White) + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/common/SendMessage.ets b/network/WebSocket/entry/src/main/ets/common/SendMessage.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbc7b84503ebf9d488817d4be9e38de6a788f444 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/common/SendMessage.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export default struct SendMessage { + @Link message: string + private sendMessage: () => void + + build() { + Row() { + TextArea({ placeholder: this.message, text: this.message }) + .height(50) + .fontSize(25) + .layoutWeight(3) + .backgroundColor(Color.White) + .margin({ left: 2, right: 2 }) + .onChange((value: string) => { + this.message = value + }) + + Button() { + Text($r('app.string.send_message')) + .fontSize(23) + .fontColor(Color.White) + } + .height(50) + .layoutWeight(1) + .borderRadius(10) + .type(ButtonType.Normal) + .backgroundColor('#ffadf58e') + .margin({ left: 2, right: 2 }) + .onClick(() => { + this.sendMessage() + }) + } + .height(70) + .width('100%') + .backgroundColor('#f5f5f5') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/common/TopBar.ets b/network/WebSocket/entry/src/main/ets/common/TopBar.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc6a743075cd1828ac2d823e430f97308f77ad43 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/common/TopBar.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export default struct TopBar { + @Link isConnect: boolean + private connect: () => void + + build() { + Row() { + Text($r('app.string.server')) + .width('20%') + .fontSize(20) + .margin({ left: '40%' }) + .textAlign(TextAlign.Center) + + Button() { + Text($r('app.string.connect')) + .margin(10) + .fontSize(15) + .fontColor(Color.White) + } + .width(70) + .height(40) + .margin({ left: '20%' }) + .type(ButtonType.Capsule) + .backgroundColor(this.isConnect ? Color.Green : Color.Grey) + .onClick(() => { + this.connect() + }) + } + .height(50) + .width('100%') + .backgroundColor('#e5e5e5') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/model/ChatData.ets b/network/WebSocket/entry/src/main/ets/model/ChatData.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f16f6b5edca4ce47b92d40c1e324102a2bc38e0 --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/model/ChatData.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default class ChatData { + public message: string + public isServer: boolean + + constructor(message: string, isServer: boolean) { + this.message = message + this.isServer = isServer + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/model/DataSource.ets b/network/WebSocket/entry/src/main/ets/model/DataSource.ets new file mode 100644 index 0000000000000000000000000000000000000000..06cc60a22521629e65853078d5576611935eab0f --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/model/DataSource.ets @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = [] + + public totalCount(): number { + return 0 + } + + public getData(index: number): any { + return undefined + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + console.info('add listener') + this.listeners.push(listener) + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + console.info('remove listener') + this.listeners.splice(pos, 1) + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded() + }) + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index) + }) + } + + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index) + }) + } + + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index) + }) + } + + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to) + }) + } +} + +export class WebSocketSource extends BasicDataSource { + public chatsData: Array + + constructor(chatsData: Array) { + super() + this.chatsData = chatsData + } + + public totalCount(): number { + return this.chatsData.length + } + + public getData(index: number): any { + return this.chatsData[index] + } + + public addData(index: number, data: any): void { + this.chatsData.splice(index, 0, data) + this.notifyDataAdd(index) + } + + public pushData(data: any): void { + this.chatsData.push(data) + this.notifyDataAdd(this.chatsData.length - 1) + } +} diff --git a/network/WebSocket/entry/src/main/ets/model/Logger.ts b/network/WebSocket/entry/src/main/ets/model/Logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..030de1546118951360d2fd5e9c8068c715521a2c --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/model/Logger.ts @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number + private prefix: string + private format: string = '%{public}s, %{public}s' + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + } + + debug(...args: any[]) { + hilog.debug(this.domain, this.prefix, this.format, args) + } + + info(...args: any[]) { + hilog.info(this.domain, this.prefix, this.format, args) + } + + warn(...args: any[]) { + hilog.warn(this.domain, this.prefix, this.format, args) + } + + error(...args: any[]) { + hilog.error(this.domain, this.prefix, this.format, args) + } +} + +export default new Logger('[WebSocket]') \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/ets/pages/Chats.ets b/network/WebSocket/entry/src/main/ets/pages/Chats.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d5914fd4888c8d61cf0c6902acebfa384c97c7d --- /dev/null +++ b/network/WebSocket/entry/src/main/ets/pages/Chats.ets @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import prompt from '@ohos.prompt' +import webSocket from '@ohos.net.webSocket' +import Logger from '../model/Logger' +import TopBar from '../common/TopBar' +import ChatData from '../model/ChatData' +import ChatsPage from '../common/ChatsPage' +import SendMessage from '../common/SendMessage' +import BindServiceIP from '../common/BindServiceIp' +import {WebSocketSource} from "../model/DataSource" + +const TAG: string = '[Chats]' +let socket: webSocket.WebSocket = webSocket.createWebSocket() + +@CustomDialog +struct BindCustomDialog { + @State ipAddress: string = '' + private controller?: CustomDialogController + onBind: (ipAddress: string) => void + + build() { + Column() { + BindServiceIP({ ipAddress: $ipAddress, onBind: () => { + this.onBind(this.ipAddress) + } }) + } + .width('100%') + .margin({ bottom: 20 }) + } +} + +@Entry +@Component +struct Chats { + @State numberOfPeople: number = 1 + @State message: string = '' + @State chats: WebSocketSource = new WebSocketSource([]) + @State isConnect: boolean = false + @State ipAddress: string = '' + controller: CustomDialogController = new CustomDialogController({ + builder: BindCustomDialog({ onBind: this.onBind.bind(this) }), + autoCancel: false + }) + + aboutToAppear() { + this.controller.open() + } + + onBind(ipAddress: string) { + this.ipAddress = ipAddress + this.controller.close() + } + + onConnect() { + let promise = socket.connect(this.ipAddress) + promise.then((value) => { + Logger.info(TAG, `connect success`) + }).catch((err) => { + Logger.info(TAG, `connect fail, error:${JSON.stringify(err)}`) + }) + socket.on('open', (err, value) => { + // 当收到on('open')事件时,可以通过send()方法与服务器进行通信 + prompt.showToast({ message: '连接成功,可以聊天了!', duration: 1500 }) + }) + socket.on('message', (err, value) => { + Logger.info(TAG, `on message, value = ${value}`) + let receiveMessage = new ChatData(JSON.stringify(value), true) + this.chats.pushData(receiveMessage) + }) + } + + disConnect() { + socket.off('open', (err, value) => { + Logger.info(TAG, `on open, status:${value['status']}, message:${value['message']}`) + }) + socket.off('message') + prompt.showToast({ message: '连接已断开!', duration: 1500 }) + socket.close() + } + + sendMessage() { + let sendMessage = new ChatData(this.message, false) + this.chats.pushData(sendMessage) + let sendResult = socket.send(this.message) + sendResult.then((value) => { + Logger.info(TAG, `[send]send success:${this.message}`) + }).catch((err) => { + Logger.info(TAG, `[send]send fail, err:${JSON.stringify(err)}`) + }) + this.message = '' + } + + build() { + Column() { + Text($r('app.string.MainAbility_label')) + .height(50) + .fontSize(25) + .width('100%') + .padding({ left: 10 }) + .fontColor(Color.White) + .textAlign(TextAlign.Start) + .backgroundColor('#0D9FFB') + .fontWeight(FontWeight.Bold) + TopBar({ isConnect: $isConnect, connect: () => { + this.isConnect = !this.isConnect + if (this.isConnect) { + this.onConnect() + } else { + this.disConnect() + } + } }) + ChatsPage({ chats: $chats }) + SendMessage({ message: $message, sendMessage: () => { + this.sendMessage() + } }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/module.json5 b/network/WebSocket/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b2688affd2c0d99daed17fa1e57f6b29ee7bcb3e --- /dev/null +++ b/network/WebSocket/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "$string:internet_permission", + "usedScene": { + "abilities": [ + "ohos.samples.websocket.MainAbility" + ], + "when": "always" + } + } + ] + } +} diff --git a/network/WebSocket/entry/src/main/resources/base/element/color.json b/network/WebSocket/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/network/WebSocket/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/resources/base/element/string.json b/network/WebSocket/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..150f9f632ae45f339528d73dcdf42b7e7fca7103 --- /dev/null +++ b/network/WebSocket/entry/src/main/resources/base/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "WebSocket" + }, + { + "name": "send_message", + "value": "send message" + }, + { + "name": "server", + "value": "Server" + }, + { + "name": "connect", + "value": "Connect" + }, + { + "name": "me", + "value": "Me" + }, + { + "name": "welcome", + "value": "Welcome to use" + }, + { + "name": "bind_ip", + "value": "Bind Server IP" + }, + { + "name": "internet_permission", + "value": "get internet permission" + }, + { + "name": "ip_placeholder", + "value": "eg:192.168.10.111" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/resources/base/media/icon.png b/network/WebSocket/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/network/WebSocket/entry/src/main/resources/base/media/icon.png differ diff --git a/network/WebSocket/entry/src/main/resources/base/profile/main_pages.json b/network/WebSocket/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c0d65855631c1a51d2debe90e160c0e887398334 --- /dev/null +++ b/network/WebSocket/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Chats" + ] +} diff --git a/network/WebSocket/entry/src/main/resources/en/element/string.json b/network/WebSocket/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..150f9f632ae45f339528d73dcdf42b7e7fca7103 --- /dev/null +++ b/network/WebSocket/entry/src/main/resources/en/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "WebSocket" + }, + { + "name": "send_message", + "value": "send message" + }, + { + "name": "server", + "value": "Server" + }, + { + "name": "connect", + "value": "Connect" + }, + { + "name": "me", + "value": "Me" + }, + { + "name": "welcome", + "value": "Welcome to use" + }, + { + "name": "bind_ip", + "value": "Bind Server IP" + }, + { + "name": "internet_permission", + "value": "get internet permission" + }, + { + "name": "ip_placeholder", + "value": "eg:192.168.10.111" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/main/resources/zh/element/string.json b/network/WebSocket/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e57c239b5d244edcb6c52f9c5c65e36baa0ebdde --- /dev/null +++ b/network/WebSocket/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "WebSocket" + }, + { + "name": "send_message", + "value": "发送" + }, + { + "name": "server", + "value": "服务器" + }, + { + "name": "connect", + "value": "连接" + }, + { + "name": "me", + "value": "我" + }, + { + "name": "welcome", + "value": "欢迎使用" + }, + { + "name": "bind_ip", + "value": "绑定服务器IP地址" + }, + { + "name": "internet_permission", + "value": "获取网络权限" + }, + { + "name": "ip_placeholder", + "value": "例如:192.168.10.111" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/network/WebSocket/entry/src/ohosTest/ets/Application/TestAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ff1cd139f737bb5899c079d8a89e5891a189956 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/Application/TestAbilityStage.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/network/WebSocket/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..cf1c7d81db9ab0618a94439c88fea91d9984dd82 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)) + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }) + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/network/WebSocket/entry/src/ohosTest/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7259f92de3dc962cc5cb622178d8b632c9d7a4d --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/network/WebSocket/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..83ad209eadafca33ed5f401eeb9ff13cb17e9181 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') { + cmd += ' -D' + } + console.info('cmd : ' + cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/test/App.test.ets b/network/WebSocket/entry/src/ohosTest/ets/test/App.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7511da02280fe0d32cbb514e99449accb364d907 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/test/App.test.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import hilog from '@ohos.hilog' + +const BUNDLE = 'WebSocket' +const TAG = '[Sample_WebSocket]' +const DOMAIN = 0xF811 + +export default function appTest() { + describe('appTest', function () { + /** + * 拉起一个Ability + */ + it(BUNDLE + '_startAbility', 0, async function (done) { + hilog.info(DOMAIN, TAG, BUNDLE + '_startAbility start') + hilog.info(DOMAIN, TAG, BUNDLE + '_startAbility start') + let want = { + bundleName: 'ohos.samples.websocket', + abilityName: 'MainAbility' + } + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + await abilityDelegator.startAbility(want, (err, data) => { + hilog.info(DOMAIN, TAG, BUNDLE + '_startAbility get err ' + JSON.stringify(err)) + expect(0).assertEqual(err.code) + done() + hilog.info(DOMAIN, TAG, BUNDLE + '_startAbility end') + }) + }) + /** + * 输入Ip + */ + it(BUNDLE + '_IndexPage_BindIp', 0, async () => { + hilog.info(DOMAIN, TAG, BUNDLE + "_IndexPage_BindIp start") + let driver = await UiDriver.create() + await driver.delayMs(1000) + await driver.assertComponentExist(BY.key('ipInput')) + let ipInput = await driver.findComponent(BY.key('ipInput')) + await ipInput.inputText('192.168.101.41') + hilog.info(DOMAIN, TAG, BUNDLE + "_IndexPage_BindIp end") + }) + }) +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/ets/test/List.test.ets b/network/WebSocket/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f97ef3a5e6dc9ac56e26684ceab17b2a577177e4 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import appTest from './App.test' + +export default function testsuite() { + appTest() +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/module.json5 b/network/WebSocket/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..60a4ec89e07f3f86707ac6c1def79a8930608788 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/module.json5 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/Application/TestAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/network/WebSocket/entry/src/ohosTest/resources/base/element/color.json b/network/WebSocket/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/resources/base/element/string.json b/network/WebSocket/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..36d4230c53e9f5a07ae343ad8dc9808341975e3b --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/network/WebSocket/entry/src/ohosTest/resources/base/media/icon.png b/network/WebSocket/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/network/WebSocket/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/network/WebSocket/entry/src/ohosTest/resources/base/profile/test_pages.json b/network/WebSocket/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/network/WebSocket/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/network/WebSocket/hvigorfile.js b/network/WebSocket/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/network/WebSocket/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/network/WebSocket/package.json b/network/WebSocket/package.json new file mode 100644 index 0000000000000000000000000000000000000000..909251540a2e86bc2d42ae13309417aeed7492d9 --- /dev/null +++ b/network/WebSocket/package.json @@ -0,0 +1,18 @@ +{ + "license": "ISC", + "devDependencies": {}, + "name": "websocket", + "ohos": { + "org": "huawei", + "directoryLevel": "project", + "buildTool": "hvigor" + }, + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "@ohos/hypium": "1.0.1", + "@ohos/hvigor-ohos-plugin": "1.1.6", + "@ohos/hvigor": "1.1.6" + } +} diff --git a/network/WebSocket/screenshots/device/bindService.png b/network/WebSocket/screenshots/device/bindService.png new file mode 100644 index 0000000000000000000000000000000000000000..958cbb81e3fe4f30ec475f0c26c7286a99d863e2 Binary files /dev/null and b/network/WebSocket/screenshots/device/bindService.png differ diff --git a/network/WebSocket/screenshots/device/connect.png b/network/WebSocket/screenshots/device/connect.png new file mode 100644 index 0000000000000000000000000000000000000000..fc87fd0ed6277e784712720fbea0c4a5cc70e2b0 Binary files /dev/null and b/network/WebSocket/screenshots/device/connect.png differ diff --git a/network/WebSocket/screenshots/device/disconnect.png b/network/WebSocket/screenshots/device/disconnect.png new file mode 100644 index 0000000000000000000000000000000000000000..746ab5c7163c59cc70bfedeac001b6122ce76421 Binary files /dev/null and b/network/WebSocket/screenshots/device/disconnect.png differ diff --git a/network/WebSocket/screenshots/device/disconnect1.png b/network/WebSocket/screenshots/device/disconnect1.png new file mode 100644 index 0000000000000000000000000000000000000000..84a7dae513e78ba092fe40796c1b0d36d034670e Binary files /dev/null and b/network/WebSocket/screenshots/device/disconnect1.png differ diff --git a/network/WebSocket/screenshots/device/server.png b/network/WebSocket/screenshots/device/server.png new file mode 100644 index 0000000000000000000000000000000000000000..23ccfcb11e632ad31bfd2c44b1bb5a19b272a578 Binary files /dev/null and b/network/WebSocket/screenshots/device/server.png differ