Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
df6dc76d
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
df6dc76d
编写于
5月 29, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 29, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8790 【OpenHarmony 4.0.7.3】【Master】【ARKUI子系统】【TOD】【rk3568】【必现】api接口,属性覆盖JsMessageType,WebMessageExt
Merge pull request !8790 from 边鑫博/master
上级
333449b4
a9f16b74
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
720 addition
and
4 deletion
+720
-4
arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/web.ets
...eb_dev_three/entry/src/main/ets/MainAbility/pages/web.ets
+377
-2
arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets
...dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets
+1
-0
arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets
..._web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets
+156
-2
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.html
...web_dev_three/entry/src/main/resources/rawfile/index.html
+19
-0
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.js
...s_web_dev_three/entry/src/main/resources/rawfile/index.js
+150
-0
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/webMessageExt.html
...three/entry/src/main/resources/rawfile/webMessageExt.html
+17
-0
未找到文件。
arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/web.ets
浏览文件 @
df6dc76d
...
...
@@ -33,6 +33,8 @@ struct Index {
scheme2: web_webview.WebCustomScheme = {schemeName: "name2", isSupportCORS: true, isSupportFetch: true}
scheme3: web_webview.WebCustomScheme = {schemeName: "name3", isSupportCORS: true, isSupportFetch: true}
responseweb: WebResourceResponse = new WebResourceResponse()
@State str:string="emitLoadUrl"
@State text:boolean=false
@State num:number=0
...
...
@@ -40,11 +42,21 @@ struct Index {
@State mode1: WebDarkMode = WebDarkMode.On
@State mode2: WebDarkMode = WebDarkMode.Auto
@State enterPageEnd: boolean = false
@State getString:boolean =false
@State getNum:boolean =false
@State getBoo:boolean =false
@State getArrayBuffer:boolean =false
@State getArray:boolean =false
@State msg1:string=""
@State type:number=0
ports: web_webview.WebMessagePort[];
message: web_webview.WebMessageExt = new web_webview.WebMessageExt();
ports: web_webview.WebMessagePort[] = null;
nativePort: web_webview.WebMessagePort = null;
@State webMessResult:string =""
testObj = {
testOne: (data) => {
Utils.emitEvent(data,13)
...
...
@@ -586,6 +598,230 @@ struct Index {
}
break;
}
case "emitJsMessExtGetString":{
try {
this.getString = true;
this.controller.loadUrl("resource://rawfile/index.html")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitJsMessExtGetNum":{
try {
this.getNum = true;
this.controller.loadUrl("resource://rawfile/index.html")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitJsMessExtGetBoo":{
try {
this.getBoo = true;
this.controller.loadUrl("resource://rawfile/index.html")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitJsMessExtGetArrayBuffer":{
try {
this.getArrayBuffer = true;
this.controller.loadUrl("resource://rawfile/index.html")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitJsMessExtGetArray":{
try {
this.getArray = true;
this.controller.loadUrl("resource://rawfile/index.html")
} catch(error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
break;
}
case "emitWebMessExtSetString":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
console.log("In eTS side send true start");
if (this.nativePort) {
setTimeout(()=>{
this.message.setType(1);
this.message.setString("helloFromEts");
this.nativePort.postMessageEventExt(this.message);
},2000)
}
setTimeout(()=>{
this.controller.runJavaScript("postStringToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetString() return value is: ${result}`);
this.webMessResult = result
Utils.emitEvent(this.webMessResult,506)
})
},3000)
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtGetString":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postStringToApp()",(error, result) => {
console.log(`The emitWebMessExtGetString() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtSetNumber":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
console.log("In eTS side send true start");
if (this.nativePort) {
setTimeout(()=>{
this.message.setNumber(1);
this.nativePort.postMessageEventExt(this.message);
},2000)
}
setTimeout(()=>{
this.controller.runJavaScript("postNumberToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetNumber() return value is: ${result}`);
Utils.emitEvent(result,507)
})
},3000)
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtGetNumber":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postNumberToApp()",(error, result) => {
console.log(`The emitWebMessExtGetNumber() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtSetBoolean":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
console.log("In eTS side send true start");
if (this.nativePort) {
setTimeout(()=>{
this.message.setBoolean(true);
this.nativePort.postMessageEventExt(this.message);
},2000)
}
setTimeout(()=>{
this.controller.runJavaScript("postBooleanToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetBoolean() return value is: ${result}`);
Utils.emitEvent(result,509)
})
},3000)
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtGetBoolean":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postBooleanToApp()",(error, result) => {
console.log(`The emitWebMessExtGetBoolean() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtSetArray":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
console.log("In eTS side send true start");
if (this.nativePort) {
setTimeout(()=>{
const fruits = [];
fruits.push("apple");
this.message.setArray(fruits);
this.nativePort.postMessageEventExt(this.message);
},2000)
}
setTimeout(()=>{
this.controller.runJavaScript("postArrayToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetArray() return value is: ${result}`);
Utils.emitEvent(result,511)
})
},3000)
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtGetArray":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postArrayToApp()",(error, result) => {
console.log(`The emitWebMessExtGetArray() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtSetArrayBuffer":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
console.log("In eTS side send true start");
if (this.nativePort) {
setTimeout(()=>{
let buffer = new ArrayBuffer(8);
this.message.setArrayBuffer(buffer);
this.nativePort.postMessageEventExt(this.message);
},2000)
}
setTimeout(()=>{
this.controller.runJavaScript("postArrayBufferToHtml()",(error, result) => {
console.log(`The emitWebMessExtSetArrayBuffer() return value is: ${result}`);
Utils.emitEvent(result,513)
})
},3000)
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
case "emitWebMessExtGetArrayBuffer":{
try {
this.controller.loadUrl($rawfile('webMessageExt.html'));
this.controller.runJavaScript("postArrayBufferToApp()",(error, result) => {
console.log(`The emitWebMessExtGetArrayBuffer() return value is: ${result}`);
})
}
catch (error) {
console.log("In eTS side send message catch error:" + error.code + ", msg:" + error.message);
}
break;
}
default:
console.info("can not match case")
}
...
...
@@ -624,6 +860,145 @@ struct Index {
Utils.emitEvent(1,446)
this.enterPageEnd=false
}
if(this.getString){
try {
this.controller.runJavaScriptExt(
'getStringForJs()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
var type = result.getType()
if(web_webview.JsMessageType.STRING == type){
this.msg1 = "result type:" + typeof (result.getString());
Utils.emitEvent(this.msg1,500)
}
});
console.info('urlgetstring: ', event.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
if(this.getNum){
try {
this.controller.runJavaScriptExt(
'getNumForJs()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
var type = result.getType()
if(web_webview.JsMessageType.NUMBER == type){
this.msg1 = "result type:" + typeof (result.getNumber());
Utils.emitEvent(this.msg1,501)
}
});
console.info('urlgetstring: ', event.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
if(this.getBoo){
try {
this.controller.runJavaScriptExt(
'getBooForJs()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
var type = result.getType()
if(web_webview.JsMessageType.BOOLEAN == type){
this.msg1 = "result type:" + typeof (result.getBoolean());
Utils.emitEvent(this.msg1,502)
}
});
console.info('urlgetstring: ', event.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
if(this.getArrayBuffer){
try {
this.controller.runJavaScriptExt(
'getArrayBufferForJs()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
var type = result.getType()
if(web_webview.JsMessageType.ARRAY_BUFFER== type){
this.msg1 = "result type:" + typeof (result.getArrayBuffer());
Utils.emitEvent(this.msg1,503)
}
});
console.info('urlgetstring: ', event.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
if(this.getArray){
try {
this.controller.runJavaScriptExt(
'getArrayForJs()',
(error, result) => {
if (error) {
console.info(`run JavaScript error: ` + JSON.stringify(error))
return;
}
var type = result.getType()
if(web_webview.JsMessageType.ARRAY== type){
this.msg1 = "result type:" + typeof (result.getArray());
Utils.emitEvent(this.msg1+web_webview.JsMessageType.NOT_SUPPORT,504)
}
});
console.info('urlgetstring: ', event.url);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
}
this.getString=false
this.getNum=false
this.getBoo=false
this.getArrayBuffer=false
this.getArray=false
this.ports = this.controller.createWebMessagePorts(true);
this.controller.postMessage("init_web_messageport", [this.ports[1]], "*");
this.nativePort = this.ports[0];
this.nativePort.onMessageEventExt((result) => {
console.log("In eTS side got message");
try {
this.type =result.getType();
if(this.type == web_webview.WebMessageType.STRING){
this.msg1 = "result type:" + typeof (result.getString());
Utils.emitEvent(this.msg1,505)
}
if(this.type == web_webview.WebMessageType.NUMBER){
this.msg1 = "result type:" + typeof (result.getNumber());
Utils.emitEvent(this.msg1+web_webview.WebMessageType.NOT_SUPPORT,508)
}
if(this.type == web_webview.WebMessageType.BOOLEAN){
this.msg1 = "result type:" + typeof (result.getBoolean());
Utils.emitEvent(this.msg1,510)
}
if(this.type == web_webview.WebMessageType.ARRAY){
this.msg1 = "result type:" + typeof (result.getArray());
Utils.emitEvent(this.msg1,512)
}
if(this.type == web_webview.WebMessageType.ARRAY_BUFFER){
this.msg1 = "result getArrayBuffer byteLength:" + ((result.getArrayBuffer().byteLength));
Utils.emitEvent(this.msg1,514)
}
}
catch (resError) {
console.log(`log error code: ${resError.code}, Message: ${resError.message}`);
}
})
console.log('url:' + event.url)
})
.darkMode(this.mode)
...
...
arkui/ace_ets_web_dev_three/entry/src/main/ets/MainAbility/pages/webTwo.ets
浏览文件 @
df6dc76d
...
...
@@ -101,6 +101,7 @@ struct indexTwo {
},3000)
break;
}
default:
console.info("can not match case")
}
...
...
arkui/ace_ets_web_dev_three/entry/src/main/ets/test/WebJsunit.test.ets
浏览文件 @
df6dc76d
...
...
@@ -426,10 +426,164 @@ export default function webJsunit() {
*tc.desic Save current page
*/
it('GetAccessibleGeolocation',0,async function(done){
emitKey="emit
GetAccessibleGeolocation
";
emitKey="emit
JsMessExtGetString
";
Utils.registerEvent("GetAccessibleGeolocation",true,451,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_039
*tc.name JsMessExtGetString
*tc.desic Save current page
*/
it('JsMessExtGetString',0,async function(done){
emitKey="emitJsMessExtGetNum";
Utils.registerEvent("JsMessExtGetString","result type:string",500,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_040
*tc.name JsMessExtGetNum
*tc.desic Save current page
*/
it('JsMessExtGetNum',0,async function(done){
emitKey="emitJsMessExtGetBoo";
Utils.registerEvent("JsMessExtGetNum","result type:number",501,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_041
*tc.name JsMessExtGetBoo
*tc.desic Save current page
*/
it('JsMessExtGetBoo',0,async function(done){
emitKey="emitJsMessExtGetArrayBuffer";
Utils.registerEvent("JsMessExtGetBoo","result type:boolean",502,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_042
*tc.name JsMessExtGetArrayBuffer
*tc.desic Save current page
*/
it('JsMessExtGetArrayBuffer',0,async function(done){
emitKey="emitJsMessExtGetArray";
Utils.registerEvent("JsMessExtGetArrayBuffer","result type:object",503,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_043
*tc.name JsMessExtGetArray
*tc.desic Save current page
*/
it('JsMessExtGetArray',0,async function(done){
emitKey="emitWebMessExtSetString";
Utils.registerEvent("JsMessExtGetArray","result type:object0",504,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_044
*tc.name WebMessExtSetString
*tc.desic Save current page
*/
it('WebMessExtSetString',0,async function(done){
emitKey="emitWebMessExtGetString";
var result="String:helloFromEts"
Utils.registerEvent("WebMessExtSetString",JSON.stringify(result),506,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_045
*tc.name WebMessExtGetString
*tc.desic Save current page
*/
it('WebMessExtGetString',0,async function(done){
emitKey="emitWebMessExtSetNumber";
Utils.registerEvent("WebMessExtGetString","result type:string",505,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_046
*tc.name WebMessExtSetNumber
*tc.desic Save current page
*/
it('WebMessExtSetNumber',0,async function(done){
emitKey="emitWebMessExtGetNumber";
var result="Number:1"
Utils.registerEvent("WebMessExtSetNumber",JSON.stringify(result),507,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_047
*tc.name WebMessExtGetNumber
*tc.desic Save current page
*/
it('WebMessExtGetNumber',0,async function(done){
emitKey="emitWebMessExtSetBoolean";
Utils.registerEvent("WebMessExtGetNumber","result type:number0",508,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_048
*tc.name WebMessExtSetBoolean
*tc.desic Save current page
*/
it('WebMessExtSetBoolean',0,async function(done){
emitKey="emitWebMessExtGetBoolean";
var result="Boolean:true"
Utils.registerEvent("WebMessExtSetBoolean",JSON.stringify(result),509,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_049
*tc.name WebMessExtGetBoolean
*tc.desic Save current page
*/
it('WebMessExtGetBoolean',0,async function(done){
emitKey="emitWebMessExtSetArray";
Utils.registerEvent("WebMessExtGetBoolean","result type:boolean",510,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_050
*tc.name WebMessExtSetArray
*tc.desic Save current page
*/
it('WebMessExtSetArray',0,async function(done){
emitKey="emitWebMessExtGetArray";
var result="Array len:1, value:apple"
Utils.registerEvent("WebMessExtSetArray",JSON.stringify(result),511,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_051
*tc.name WebMessExtGetArray
*tc.desic Save current page
*/
it('WebMessExtGetArray',0,async function(done){
emitKey="emitWebMessExtSetArrayBuffer";
Utils.registerEvent("WebMessExtGetArray","result type:object",512,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_052
*tc.name WebMessExtSetArrayBuffer
*tc.desic Save current page
*/
it('WebMessExtSetArrayBuffer',0,async function(done){
emitKey="emitWebMessExtGetArrayBuffer";
var result="ArrayBuffer:8"
Utils.registerEvent("WebMessExtSetArrayBuffer",JSON.stringify(result),513,done);
sendEventByKey('webcomponent',10,'');
})
/*
*tc.number SUB_ACE_BASIC_ETS_API_053
*tc.name WebMessExtGetArrayBuffer
*tc.desic Save current page
*/
it('WebMessExtGetArrayBuffer',0,async function(done){
emitKey="emitWebMessExtGetArrayBuffer";
Utils.registerEvent("WebMessExtGetArrayBuffer","result getArrayBuffer byteLength:8",514,done);
sendEventByKey('webcomponent',10,'');
})
})
}
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.html
浏览文件 @
df6dc76d
...
...
@@ -70,5 +70,24 @@
let
str
=
objName
.
testOne
(
'
Web
'
)
return
str
}
function
getStringForJs
()
{
return
"
hello, world
"
;
}
function
getNumForJs
()
{
return
1
;
}
function
getBooForJs
()
{
return
true
;
}
function
getArrayBufferForJs
()
{
const
buffer
=
new
ArrayBuffer
(
8
);
const
view
=
new
Int32Array
(
buffer
);
return
view
;
}
function
getArrayForJs
()
{
const
fruits
=
[];
fruits
.
push
(
"
banana
"
,
"
apple
"
,
"
peach
"
);
return
fruits
;
}
</script>
</html>
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/index.js
0 → 100644
浏览文件 @
df6dc76d
/*
* Copyright (C) 2021 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.
*/
var
h5Port
;
window
.
addEventListener
(
'
message
'
,
function
(
event
)
{
console
.
info
(
"
htmlSSSSS
"
)
if
(
event
.
data
==
'
init_web_messageport
'
)
{
if
(
event
.
ports
[
0
]
!=
null
)
{
h5Port
=
event
.
ports
[
0
];
// 1. 保存从ets侧发送过来的端口
h5Port
.
onmessage
=
function
(
event
)
{
console
.
info
(
"
hwd In html got message
"
);
// 2. 接收ets侧发送过来的消息.
var
result
=
event
.
data
;
console
.
info
(
"
In html got message, typeof:
"
,
typeof
(
result
));
console
.
info
(
"
In html got message, result:
"
,
(
result
));
if
(
typeof
(
result
)
==
"
string
"
)
{
console
.
log
(
"
In html got message, String:
"
,
result
);
document
.
getElementById
(
"
msg
"
).
innerHTML
=
"
String:
"
+
result
;
}
else
if
(
typeof
(
result
)
==
"
number
"
)
{
console
.
log
(
"
In html side got message, number:
"
,
result
);
document
.
getElementById
(
"
msg
"
).
innerHTML
=
"
Number:
"
+
result
;
}
else
if
(
typeof
(
result
)
==
"
boolean
"
)
{
console
.
log
(
"
In html side got message, boolean:
"
,
result
);
document
.
getElementById
(
"
msg
"
).
innerHTML
=
"
Boolean:
"
+
result
;
}
else
if
(
typeof
(
result
)
==
"
object
"
)
{
if
(
result
instanceof
ArrayBuffer
)
{
document
.
getElementById
(
"
msg2
"
).
innerHTML
=
"
ArrayBuffer:
"
+
result
.
byteLength
;
console
.
log
(
"
In html got message, byteLength:
"
,
result
.
byteLength
);
}
else
if
(
result
instanceof
Error
)
{
console
.
log
(
"
In html error message, err:
"
+
(
result
));
console
.
log
(
"
In html error message, typeof err:
"
+
typeof
(
result
));
document
.
getElementById
(
"
msg2
"
).
innerHTML
=
"
Error:
"
+
result
.
name
+
"
, msg:
"
+
result
.
message
;
}
else
if
(
result
instanceof
Array
)
{
console
.
log
(
"
In html got message, Array
"
);
console
.
log
(
"
In html got message, Array length:
"
+
result
.
length
);
console
.
log
(
"
In html got message, Array[0]:
"
+
(
result
[
0
]));
console
.
log
(
"
In html got message, typeof Array[0]:
"
+
typeof
(
result
[
0
]));
document
.
getElementById
(
"
msg2
"
).
innerHTML
=
"
Array len:
"
+
result
.
length
+
"
, value:
"
+
result
;
}
else
{
console
.
log
(
"
In html got message, not any instance of support type
"
);
document
.
getElementById
(
"
msg
"
).
innerHTML
=
"
not any instance of support type
"
;
}
}
else
{
console
.
log
(
"
In html got message, not support type
"
);
document
.
getElementById
(
"
msg
"
).
innerHTML
=
"
not support type
"
;
}
}
h5Port
.
onmessageerror
=
(
event
)
=>
{
console
.
error
(
`hwd In html Error receiving message:
${
event
}
`
);
};
}
}
})
// 使用h5Port往ets侧发送String类型的消息.
function
postStringToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send string message
"
);
h5Port
.
postMessage
(
"
hello
"
);
console
.
log
(
"
In html send string message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postNumberToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send Number message
"
);
h5Port
.
postMessage
(
1
);
console
.
log
(
"
In html send Number message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postBooleanToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send Boolean message
"
);
h5Port
.
postMessage
(
true
);
console
.
log
(
"
In html send Boolean message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postArrayToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send Array message
"
);
const
fruits
=
[];
fruits
.
push
(
"
apple
"
);
h5Port
.
postMessage
(
fruits
);
console
.
log
(
"
In html send Array message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postArrayBufferToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send Buffer message
"
);
let
buffer
=
new
ArrayBuffer
(
8
);
h5Port
.
postMessage
(
buffer
);
console
.
log
(
"
In html send Buffer message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postErrorToApp
()
{
if
(
h5Port
)
{
console
.
log
(
"
In html send error message
"
);
let
err
=
{
name
:
"
cuowu
"
,
message
:
"
cuowu
"
};
h5Port
.
postMessage
(
err
);
console
.
log
(
"
In html send error message end
"
);
}
else
{
console
.
error
(
"
In html h5port is null, please init first
"
);
}
}
function
postStringToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg
"
).
innerText
return
a
}
function
postNumberToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg
"
).
innerText
return
a
}
function
postBooleanToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg
"
).
innerText
return
a
}
function
postArrayToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg2
"
).
innerText
return
a
}
function
postArrayBufferToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg2
"
).
innerText
return
a
}
function
postErrorToHtml
()
{
var
a
=
document
.
getElementById
(
"
msg2
"
).
innerText
return
a
}
\ No newline at end of file
arkui/ace_ets_web_dev_three/entry/src/main/resources/rawfile/webMessageExt.html
0 → 100644
浏览文件 @
df6dc76d
<!--index.html-->
<!DOCTYPE html>
<html
lang=
"en-gb"
>
<head>
<title>
WebView MessagePort Demo
</title>
</head>
<body>
<h1>
Html5 Send and Receive Message
</h1>
<h3
id=
"msg"
>
Receive string:
</h3>
<h3
id=
"msg2"
>
Receive arraybuffer:
</h3>
<div
style=
"font-size: 10pt; text-align: center;"
>
<input
type=
"button"
value=
"Send String"
onclick=
"postStringToApp();"
/><br/>
</div>
</body>
<script
src=
"index.js"
></script>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录