• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15import { AsyncCallback, Callback } from './../basic';
16
17declare namespace napitest {
18    interface ModelEvent{
19        topic: string;
20        message: string;
21    }
22
23    function on(type: string, callback: Callback<number>): void;
24    function off(type: string, callback?: Callback<number>): void;
25    function on(type: string, callback: Callback<ModelEvent>): void; // Callback为interface
26    function off(type: string, callback?: Callback<ModelEvent>): void;
27    function on(type: string, callback: Callback<{topic:string,message:string}>): void; // Callback为匿名interface
28    function off(type: string, callback?: Callback<{topic:string,message:string}>): void;
29    // function on(type: string, callback: Callback<string>): void; // Callback为string
30    function on(type: 'onEvents', callback: (wid: number) => void): void; // 箭头函数支持
31    function off(type: 'onEvents', callback?: (wid: number) => void): void;
32    function on(type: 'onEventFunc', callback: (wid: number, mol: ModelEvent) => void): void; // 箭头函数支持
33    function off(type: 'onEventFunc', callback?: (wid: number, mol: ModelEvent) => void): void;
34
35    interface TestClass1 {
36        on(type: string, callback: Callback<boolean>): void;
37        off(type: string, callback?: Callback<boolean>): void;
38    }
39
40    interface TestClass2 {
41        on(type: string, callback: Callback<ModelEvent>): void; // Callback为interface
42        off(type: string, callback?: Callback<ModelEvent>): void;
43    }
44
45    interface TestClass3 {
46        on(type: string, callback: Callback<{topic:string,message:string}>): void; // Callback为匿名interface
47        off(type: string, callback?: Callback<{topic:string,message:string}>): void;
48    }
49
50    interface TestClass4 {
51        on(type: 'heartbeat', callback: (wid: boolean) => void): void; // 箭头函数支持
52        off(type: 'heartbeat', callback?: (wid: boolean) => void): void; // 固定事件,去注册事件
53    }
54
55    interface TestClass5 {
56        on(type: 'inputStart', callback: (wid: boolean, modeEv: ModelEvent) => void): void; // 回调函数参数个数大于1,支持
57        off(type: 'inputStart', callback?: (wid: boolean, modeEv: ModelEvent) => void): void;
58    }
59
60    interface TestClass6 {
61        on(type: string, asyncCallback: AsyncCallback<boolean>): void;
62        off(type: string, asyncCallback?: AsyncCallback<boolean>): void;
63    }
64
65    interface TestClass7 {
66        on(type: string, asyncCallback: AsyncCallback<ModelEvent>): void; // Callback为interface
67        off(type: string, asyncCallback?: AsyncCallback<ModelEvent>): void;
68    }
69
70    interface TestClass10 {
71        on(type: "heartbeat", callback: Callback<boolean>): void; // 固定事件,回调参数为boolean支持
72        off(type: "hearbeat", callback?: Callback<boolean>): void;
73        on(type: "enableChange", callback: Callback<ModelEvent>): void; // 固定事件,回调参数为ModelEvent支持
74        off(type: "enableChange", callback?: Callback<ModelEvent>): void;
75        on(type: string, asyncCallback: AsyncCallback<string>): void;
76        off(type: string, asyncCallback?: AsyncCallback<string>): void;
77        on(type: string, callback: (wid: number) => void): void; // 箭头函数支持
78        off(type: string, callback?: (wid: number) => void): void;
79        // on(type: string, callback: (wid: boolean) => string): void; // 返回值待支持
80        on(type: "inputStart", callback: (wid: boolean, modeEv: ModelEvent) => void): void; // 回调函数参数个数大于1,支持
81        off(type: "inputStart", callback?: (wid: boolean, modeEv: ModelEvent) => void): void;
82    }
83
84    interface TestClass11 {
85        registerTestfunc11(cb: Function);
86        unRegisterTestfunc11(cb: Function);
87
88        registerTestfunc12(cb : (wid: number) => string);
89        unRegisterTestfunc12(cb : (wid: number) => string);
90
91        registerTestfunc13(cb : Callback<boolean>);
92        unRegisterTestfunc13(cb : Callback<boolean>);
93    }
94    function registerNamespacefunc20(cb: Function);
95    function unRegisterNamespacefunc20(cb: Function);
96
97    function registerNamespacefunc21(cb : (wid: number) => string);
98    function unRegisterNamespacefunc21(cb : (wid: number) => string);
99
100    function registerNamespacefunc22(cb : Callback<boolean>);
101
102    function unRegisterNamespacefunc22(cb : Callback<boolean>);
103
104    function registerNamespacefunc24(cb : (wid: ModelEvent) => string);
105    function unRegisterNamespacefunc24(cb : (wid: ModelEvent) => string);
106
107    export class NodeISayHello
108    {
109        addSayHelloListener(listener: NodeISayHelloListener);
110        sayHello(from: string, to: string, sayType: SayType);
111        removeSayHelloListener(listener: NodeISayHelloListener);
112    }
113
114    export class NodeISayHelloListener
115    {
116        onSayHelloStart(info: SayInfo);
117        onSayHelloEnd(info: SayInfo);
118    }
119
120    export enum SayType
121    {
122        /** 0  主动说话 */
123        kInitiative,
124        /** 1  回应对方 */
125        kResponse,
126    }
127
128    interface TestClass12 {
129        registerTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void);
130        unRegisterTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void);
131    }
132    function registerNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void);
133    function unRegisterNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void);
134
135    export type SayInfo =
136    {
137        from: string;
138        fromId?: number;
139        content: string;
140        saidTime?: string;
141        isEnd?: boolean;
142    }
143
144    export interface TestOptional
145    {
146        v1: string;
147        v2?: boolean;
148        v3: number;
149        v4?: string;
150        v5?: number;
151    }
152}
153
154export default napitest;
155