Skip to content

内容与SDK消息交互

支持消息类型(int: type)

  • 100:runscript,自定义消息,一般用于内容(js)与APP的消息交互
  • 101:退出AR内容
  • 108:跳转外部链接
  • 110:截屏(共有三种形式,尤其注意下文中的方法3的使用说明)
  • 111:分享,支持分享文字、图片、音频、视频、链接
  • 112:录屏消息类,开始录屏
  • 113:录屏消息类,结束录屏
  • 115:数据埋点
  • 10005:Naitve弹窗
  • 10007:手机震动
  • 10008:进入子事件
  • 10009:退出子事件
  • 10010: 退出导航
  • 10011: 设置地图可见性

1.请求方法

js
//说明
//identity: int,唯一标志,用于区分不同的事件,用于扩展,暂无实用
//version:  int,版本判断,用于扩展,暂无实用
//type:     int,100
//desc:     string,参数,用于实际交互所需
Insight.Event.Happen(int identity, int version, int type, string desc)

//消息回调
//参考消息100示例
Insight.Event.HappenCallback(this, function name);

2.请求示例

js
//type = 101
Insight.Event.Happen ( 1, 1 , 101, "" );
//type = 112
Insight.Event.Happen ( 1, 1 , 112, "" );
//type = 113
Insight.Event.Happen ( 1, 1 , 113, "" );
js
//type = 115,埋点数据需要和后台同步,埋点参数的键值对可以自定义
this.paramTable = {
    actionID: "enter"
};
this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 115, this.encodedJson  )
js
//type = 108
this.paramTable = {
    url: "https://ai.163.com/#/m/overview",
    type: {
        urlType: 1,
        title: "NeteaseAR",
        param1: "showBrandInfo"
    }
};
this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 108 , this.encodedJson  )

110 截屏参数说明

参数类型说明备注
cameranamestring指定相机截图非必填
rawimagenamestring保存截图至指定名称的rawimage非必填
exposedAppbool暴露给App,true暴露,否则不暴露非必填
xdouble截图起始x,从左下角起非必填
ydouble截图起始y,从左下角起非必填
widthdouble截图宽度非必填
heightdouble截图高度非必填
js
//type = 110
//方法1.获取主相机截图
Insight.Event.Happen ( 1, 1 , 110 , ""  );

//方法2.获取指定相机的截图
this.paramTable = {
    cameraname:"captureCamera",
};
this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 110 , this.encodedJson  )

//方法3.获取指定相机的截图并渲染到指定的rawimage上
//update by 20220322
//方法3可通过注册HappenCallback的回调,获取到图片的本地临时路径,用于在内容层实现图片保存
//内容层保存图片接口为Insight.Event.SaveImageFile(path)
this.paramTable = {
    cameraname:"Main Camera",
    rawimagename:"captureRawImage",
};
this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 110 , this.encodedJson  )

//方法4.获取指定尺寸的截图并渲染到指定的rawimage上
//update by 20220411
//图片截图参数的x,y截图从左下角起
this.paramTable = {
    cameraname:"Main Camera",
    rawimagename:"captureRawImage",
    x:10,
    y:10,
    width:512,
    height:512
};
this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 110 , this.encodedJson  )
js
//type = 111
this.paramTable = {
    type: 1,
    title: "洞见AR",
    desc: "易现先进copyright",
    identity: "",
    url: "https://ai.163.com/#/m/overview",
    music: "",
    video: "",
    screenshot: "",
        //拼接图片的二维码图图片,分辨率1080*300,可无
    image: "/ShareLogo/ShareLogo.png",
    imagepath: "",
    imageformat: 0
};
//分享文字,取desc
//this.paramTable["type"] =  1;
//分享图片format=1,截屏分享,如下图所示
//-- 1:分享图片-加框-加码
//-- 2:分享图片-不加框-加码
//-- 3:分享图片-内嵌码
//-- 0:分享图片-不处理
//this.paramTable["type"] =  2;
//this.paramTable["imageformat"] =  1;
//分享图片format=2,截屏分享
//this.paramTable["type"] =  2;
//this.paramTable["imageformat"] =  2;
//分享图片format=3,截屏分享
//this.paramTable["type"] =  2;
//this.paramTable["imageformat"] =  3;
//分享图片format=0,截屏分享
//this.paramTable["type"] =  2;
//this.paramTable["imageformat"] =  0;
//分享音频
//this.paramTable["type"] =  3;
//分享视频
//this.paramTable["type"] =  4;
//分享链接,取url
this.paramTable["type"] =  5;

this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 111 , this.encodedJson  )

js
//type = 10005
var paramTable = {command:"1",time : 3,progress : "0",text : "do enter success"};
var jsonStr = JSON.stringify(paramTable);
Insight.Event.Happen( 1 , 1 , 10005 , jsonStr);
js
//type = 10007
//milliseconds:单位是毫秒
var paramTable = { milliseconds: 1000, repeatcount: 3};
var jsonStr = JSON.stringify(paramTable);
Insight.Event.Happen( 1 , 1 , 10007 , jsonStr);
js
//type = 10008
//activetype: 0,下载子事件;1,下载并进入子事件
var paramTable = { cid: 1112, sid: 313, activetype: 0};
var jsonStr = JSON.stringify(paramTable);
Insight.Event.Happen( 1 , 1 , 10008 , jsonStr);

//type = 10009
var paramTable = { cid: 1112, sid: 313, activetype: 0};
var jsonStr = JSON.stringify(paramTable);
Insight.Event.Happen( 1 , 1 , 10009 , jsonStr);
js
//type = 100, actionid = mediaPreview
this.paramTable = 
{
    script:"mediaPreview"// actionId:"mediaPreview",// 当前使用"script"
    type: 1, // 媒体文件类型
    url: "https://ai.163.com/#/m/overview", // 媒体文件路径
    identity: "mediaCapture", // 内容层的唯一标识
    json: "", // 预留
    title: "洞见AR",
    desc: "易现先进copyright",
};
//分享文字,取desc
//this.paramTable["type"] =  1;
//分享图片format=1,截屏分享
//this.paramTable["type"] =  2;
//分享音频
//this.paramTable["type"] =  3;
//分享视频
//this.paramTable["type"] =  4;
//分享链接,取url
this.paramTable["type"] =  5;

this.encodedJson = JSON.stringify( this.paramTable );
Insight.Debug.Log("[js share encode] " + this.encodedJson);
Insight.Event.Happen ( 1, 1 , 100 , this.encodedJson  )

3.自定义消息的回调方式

需要和APP开发者协商需要回调的方法,内容侧实现方式如下:

js
//1.将回调方法注册到event的HappenCallback方法
function DoScriptHappen(gameObject) {
    this.transform = gameObject.transform;
    this.gameObject = gameObject;
}
//Write prototype function here
DoScriptHappen.prototype = Object.assign(Object.create(Object.prototype), {
    // Start is called before the first frame update
    Start: function () {
        // register event callback 
        Insight.Event.HappenCallback(this, this.MyHappenCallback);
    },
        // Button click happen
    OnPointerUp: function () {
        this.EventHappen();
    },
    // event happen
    EventHappen: function () {
        // event happen(int identity, int version, int type, stirng script)
        // type must be 100! 
        // json string or empty is OK
        // if json, must contains "identity","type","script"
        Insight.Event.Happen(1, 1, 100, "{\"identity\":\"A\",\"json\":\"B\",\"script\":\"0\"}");
        Insight.Debug.Log("js event Happen ");
    },
    // event callback
    MyHappenCallback: function (script) {
        Insight.Debug.Log("js event MyHappenCallback " + script);
        //todo    
    }
});
//Return the script module
DoScriptHappen