回退 avseession修改stage模型

Signed-off-by: guoke <guoke8@huawei.com>
This commit is contained in:
guoke 2024-02-20 10:11:36 +08:00
parent 17440cd893
commit 9677b3ef6e
26 changed files with 528 additions and 405 deletions

View File

@ -18,8 +18,8 @@ import deviceManager from '@ohos.distributedDeviceManager';
import featureAbility from '@ohos.ability.featureAbility';
var results;
var bundleName = "com.acts.avsessionserver";
var abilityName = "com.acts.avsessionserver.ServiceAbility";
var bundleName = "com.example.myapplication";
var abilityName = "com.example.myapplication.ServiceAbility";
var deviceList;
var dmInstance;

View File

@ -1,20 +0,0 @@
{
"app": {
"bundleName": "com.acts.avsessionserver",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"debug": false,
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": true
}
}
}

View File

@ -1,8 +0,0 @@
{
"string": [
{
"name": "app_name",
"value": "AVSessionServer"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -13,32 +13,22 @@
import("//test/xts/tools/build/suite.gni")
ohos_hap_assist_suite("DctsAVSessionServerTest") {
hap_profile = "entry/src/main/module.json"
hap_name = "DctsAVSessionServerTest"
testonly = true
hap_profile = "./src/main/config.json"
deps = [
":avsession_js_assets",
":avsession_js_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "DctsAVSessionServerTest"
subsystem_name = "multimedia"
part_name = "av_session"
}
ohos_app_scope("avsessionserver_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("avsession_js_assets") {
source_dir = "entry/src/main/ets"
source_dir = "./src/main/js"
hap_profile = "./src/main/config.json"
}
ohos_resources("avsession_js_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":avsessionserver_app_profile" ]
hap_profile = "entry/src/main/module.json"
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}

View File

@ -0,0 +1,20 @@
{
"description": "Configuration for avsession server",
"driver": {
"type": "JSUnitServer",
"test-timeout": "900000",
"package": "com.example.myapplication",
"abilityName": ".MainAbility",
"shell-timeout": "900000"
},
"kits": [
{
"test-file-name": [
"DctsAVSessionServerTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2024 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.app.ability.UIAbility'
import AcCtrl from '@ohos.abilityAccessCtrl'
let AcManager = AcCtrl.createAtManager()
export default class MainAbility3 extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
AcManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser')
})
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
windowStage.setUIContent(this.context, "MainAbility/pages/MainAbility_pages", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};

View File

@ -1,68 +0,0 @@
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:module_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"continuable":true,
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "com.acts.avsessionserver.ServiceAbility",
"srcEntrance": "./ets/serviceability/ServiceAbility.ts",
"type": "service",
"visible": true,
"description": "service"
}
],
"requestPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
},
{
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.MANAGE_MEDIA_RESOURCES"
},
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING"
}
]
}
}

View File

@ -1,8 +0,0 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}

View File

@ -1,16 +0,0 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "AVSessionServer"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,5 +0,0 @@
{
"src": [
"pages/Index"
]
}

View File

@ -0,0 +1,100 @@
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 8,
"target": 9
}
},
"deviceConfig": {},
"module": {
"reqPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
},
{
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.MANAGE_MEDIA_RESOURCES"
},
{
"name": "ohos.permission.ACCESS_SERVICE_DM"
},
{
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING"
}
],
"package": "com.example.myapplication",
"name": ".MyApplication",
"mainAbility": "com.example.myapplication.MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "js",
"icon": "$media:icon",
"description": "$string:mainability_description",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"srcPath": "ServiceAbility",
"name": ".ServiceAbility",
"icon": "$media:icon",
"srcLanguage": "js",
"description": "$string:serviceability_description",
"type": "service",
"visible": true,
"formsEnabled": false
}
],
"js": [
{
"pages": [
"pages/index/index",
"pages/second/second"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -1,31 +1,23 @@
/*
* Copyright (c) 2024 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.
*/
@Entry
@Component
struct Index {
@State message: string = 'MainAbility';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
/*
* Copyright (c) 2021-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 {
onCreate() {
console.info("Application onCreate");
},
onDestroy() {
console.info("Application onDestroy");
}
};

View File

@ -0,0 +1,11 @@
{
"strings": {
"hello": "Hello",
"world": "World",
"page": "Second Page",
"next": "Next Page",
"back": "Back"
},
"Files": {
}
}

View File

@ -0,0 +1,11 @@
{
"strings": {
"hello": "您好",
"world": "世界",
"page": "第二页",
"next": "下一页",
"back": "返回"
},
"Files": {
}
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2021-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.
*/
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
.btn {
width: 50%;
height: 100px;
font-size: 40px;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2021-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.
*/
<div class="container" onswipe="touchMove">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
<input class="btn" type="button" value="{{ $t('strings.next') }}" onclick="onclick"></input>
</div>

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2021-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 '@system.router'
import featureAbility from '@ohos.ability.featureAbility';
export default {
data: {
title: ""
},
onInit() {
this.grantPermission();
},
onclick: function () {
router.replace({
uri: "pages/second/second"
})
},
grantPermission() {
console.info('Calc[IndexPage] grantPermission')
let context = featureAbility.getContext()
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
})
},
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2021-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.
*/
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
.btn {
width: 50%;
height: 100px;
font-size: 40px;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2021-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.
*/
<div class="container">
<text class="title">
{{ $t('strings.page') }}
</text>
<input class="btn" type="button" value="{{ $t('strings.back') }}" onclick="onclick"></input>
</div>

View File

@ -1,24 +1,27 @@
/*
* Copyright (c) 2024 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.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
onCreate(): void {
// 应用的HAP在首次加载的时为该Module初始化操作
console.info("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
/*
* Copyright (c) 2021-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 '@system.router'
export default {
data: {
title: 'World'
},
onclick: function () {
router.replace({
uri: "pages/index/index"
})
}
}

View File

@ -1,154 +1,149 @@
/*
* Copyright (c) 2021-2024 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 ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
import rpc from "@ohos.rpc"
import avSession from '@ohos.multimedia.avsession';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent';
function startContinuousTask() {
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.ServiceAbility"
}
],
operationType: wantAgent.OperationType.START_SERVICE,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try {
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.MULTI_DEVICE_CONNECTION, wantAgentObj).then(() => {
console.info(`Operation startBackgroundRunning succeeded`);
}).catch((error) => {
console.error(`Operation startBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
});
} catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
}
});
}
function stopContinuousTask() {
try {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info(`Operation stopBackgroundRunning success`);
}) .catch((error) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
})
} catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
}
}
export default class ServiceAbility extends ServiceExtension {
onCreate(want) {
console.info('AVSessionServer: onStart');
startContinuousTask();
console.info('AVSessionServer: startContinuousTask');
}
onConnect(want) {
console.info('AVSessionServer: service onConnect called.')
return new Stub("rpcTestAbility")
}
onDisconnect(want) {
console.info('AVSessionServer: service onDisConnect called.')
}
onReconnect(want) {
console.info('AVSessionServer: service onReConnect called.')
}
onRequest(want, startId){
console.info('AVSessionServer: onCommand, want: ' + JSON.stringify(want) + ', startId: ' + startId)
}
onDestroy() {
console.info('AVSessionServer: onStop');
stopContinuousTask();
console.info('AVSessionServer: stopContinuousTask');
}
};
const CODE_CAST_AUDIO = 1;
let descriptor;
let controller;
class Stub extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
async onRemoteMessageRequest(code, data, reply, option) {
try {
console.info(`AVSessionServer: onRemoteRequest: ${code}`);
switch (code) {
case CODE_CAST_AUDIO:
{
console.info('AVSessionServer:case CODE_CAST_AUDIO');
await avSession.getAllSessionDescriptors().then((descriptors) => {
console.info(`${descriptors.length}`);
console.info('AVSessionServer: Get descriptors Successfully');
if (descriptors.length === 0) {
console.info('AVSessionServer: Get descriptors : Fail');
}
descriptor = descriptors[0];
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
await avSession.createController(descriptor.sessionId).then((data) => {
console.info('AVSessionServer: Create controller Successfully');
controller = data;
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
await controller.getAVMetadata().then((data) => {
console.info(data.assetId);
console.info(data.artist);
console.info('AVSessionServer: Get Metadata');
if (data.assetId === '121278' && data.artist === 'Eminem') {
console.info(`AVSessionServer: Get Metadata is ${data}`);
let writeResult = reply.writeString('case 1 get successfully');
console.info(`AVSessionServer writeString result is ${writeResult}`);
return true;
}
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
}
default:
console.error(`AVSessionServer: default case code is ${code}`);
return super.onRemoteMessageRequest(code, data, reply, option);
}
} catch (error) {
console.info(`AVSessionServer: onRemoteRequest: ${error.message}`);
}
return false;
}
/*
* Copyright (c) 2021-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 rpc from "@ohos.rpc"
import avSession from '@ohos.multimedia.avsession';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
import wantAgent from '@ohos.wantAgent';
function startContinuousTask() {
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.ServiceAbility"
}
],
operationType: wantAgent.OperationType.START_SERVICE,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
try {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.MULTI_DEVICE_CONNECTION, wantAgentObj).then(() => {
console.info(`Operation startBackgroundRunning succeeded`);
}).catch((error) => {
console.error(`Operation startBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
});
} catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
}
});
}
function stopContinuousTask() {
try {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info(`Operation stopBackgroundRunning failed cause: ${err}`);
}) .catch((error) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
})
} catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code}, message is ${error.message}`);
}
}
export default {
onStart() {
console.info('AVSessionServer: onStart');
startContinuousTask();
console.info('AVSessionServer: startContinuousTask');
},
onStop() {
console.info('AVSessionServer: onStop');
stopContinuousTask();
console.info('AVSessionServer: stopContinuousTask');
},
onCommand(want, startId) {
console.info('AVSessionServer: onCommand, want: ' + JSON.stringify(want) + ', startId: ' + startId)
},
onConnect(want) {
console.info('AVSessionServer: service onConnect called.')
return new Stub("rpcTestAbility")
},
onDisconnect(want) {
console.info('AVSessionServer: service onDisConnect called.')
},
onReconnect(want) {
console.info('AVSessionServer: service onReConnect called.')
}
}
const CODE_CAST_AUDIO = 1;
let descriptor;
let controller;
class Stub extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
async onRemoteMessageRequest(code, data, reply, option) {
try {
console.info(`AVSessionServer: onRemoteRequest: ${code}`);
switch (code) {
case CODE_CAST_AUDIO:
{
console.info('AVSessionServer:case CODE_CAST_AUDIO');
await avSession.getAllSessionDescriptors().then((descriptors) => {
console.info(descriptors.length);
console.info('AVSessionServer: Get descriptors Successfully');
if (descriptors.length === 0) {
console.info('AVSessionServer: Get descriptors : Fail');
}
descriptor = descriptors[0];
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
await avSession.createController(descriptor.sessionId).then((data) => {
console.info('AVSessionServer: Create controller Successfully');
controller = data;
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
await controller.getAVMetadata().then((data) => {
console.info(data.assetId);
console.info(data.artist);
console.info('AVSessionServer: Get Metadata');
if (data.assetId === '121278' && data.artist === 'Eminem') {
console.info(`AVSessionServer: Get Metadata is ${data}`);
let writeResult = reply.writeString('case 1 get successfully');
console.info(`AVSessionServer writeString result is ${writeResult}`);
return true;
}
}).catch((err) => {
console.info(`AVSessionServer: ${err.message}`);
return false;
});
}
default:
console.error(`AVSessionServer: default case code is ${code}`);
return super.onRemoteMessageRequest(code, data, reply, option);
}
} catch (error) {
console.info(`AVSessionServer: onRemoteRequest: ${error.message}`);
}
return false;
}
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "entry_MainAbility",
"value": "avsessionServer"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
},
{
"name": "serviceability_description",
"value": "hap sample empty service"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB