-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGOBERTS.d.ts
466 lines (411 loc) · 11.1 KB
/
GOBERTS.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/**
* Copyright 2024. Huawei Technologies Co., Ltd. All rights reserved.
*
* 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 declare interface ActionArgs {
sender: string;
gameData: string;
roomId: string;
SDK: {
/**
* 请求补帧
* @param beginFrameId - 起始帧号
* @param size - 请求帧数量
*/
requestFrame: (beginFrameId: number, size: number) => Promise<void>;
sendData: (data: string, players?: string[]) => Promise<void>;
setCache: (key: string, value: string, expireTime: number) => Promise<void>;
getCache: (key: string) => Promise<CacheValue>;
deleteCache: (key: string) => Promise<void>;
setCacheIfNotExist: (key: string, value: string, expireTime: number) => Promise<void>;
getRoomInfo: () => Promise<RoomInfo>;
log: {
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
};
updateRoomProperties: (updateRoomInfo: UpdateRoomInfo) => Promise<void>;
removePlayer: (playerId: string) => Promise<void>;
dismiss: () => Promise<void>;
getAutoFrame: () => boolean;
getFrameRate: () => number;
};
}
declare interface ArgsConfig {
sender: string;
roomId: string;
appId: string;
ticket: string;
domain: string;
projectId: string;
gameData?: string;
autoFrame: boolean;
frameRate: number;
frameRequesting: boolean;
frameRequestSize: number;
logger?: any;
}
declare interface AuthResponse extends BaseResponse {
serviceToken: string;
timeStamp: number;
}
export declare const enum AutoFrame {
AUTO_FRAME_OFF = 0,
AUTO_FRAME_ON = 1
}
declare interface AvailableRoomsResponse extends BaseResponse {
rooms: RoomInfo_2[];
count: number;
offset: string | number;
hasNext: 0 | 1;
}
declare interface BaseResponse {
rtnCode: number;
msg?: string;
ret: {
code: number;
msg?: string;
};
}
export declare interface CacheValue {
value?: string;
}
declare interface CacheValue_2 {
value?: string;
}
export declare type CommonFunc = (args: ActionArgs) => void;
declare interface CreateChannelResponse extends BaseResponse {
data: CreateChannelResponseData;
}
declare interface CreateChannelResponseData {
setupTicket: string;
joinTicket: string;
}
export declare type ErrorFunc = (error: GOBEError, args: ActionArgs) => void;
/**
* 附加信息
* @public
*/
export declare interface FrameExtInfo {
seed: number;
}
/**
* 帧数据信息
* @public
*/
export declare interface FrameInfo extends FramePlayerInfo {
data: string[];
timestamp: number;
}
/**
* 帧数据玩家信息
* @public
*/
export declare interface FramePlayerInfo {
playerId: string;
}
export declare type FramePlayerInfoFunc = (playerInfo: FramePlayerInfo, args: ActionArgs) => void;
/**
* 帧数据玩家信息
* @public
*/
export declare interface FramePlayerPropInfo {
playerId: string;
customProp: string;
}
export declare interface GameServer {
onCreateRoom: CommonFunc;
onConnect?: CommonFunc;
onDisconnect?: CommonFunc;
onRecvFromClient?: CommonFunc;
onDestroyRoom: CommonFunc;
onJoin?: FramePlayerInfoFunc;
onLeave?: FramePlayerInfoFunc;
onStartFrameSync?: CommonFunc;
onStopFrameSync?: CommonFunc;
onRecvFrame?: OnRecvFrameFunc;
onRecvFromClientV2?: OnRecvFromClientFunc;
onRequestFrameError?: ErrorFunc;
onRoomPropertiesChange?: OnRoomPropertiesChangeFunc;
onUpdateCustomProperties?: OnUpdateCustomPropertiesFunc;
onUpdateCustomStatus?: OnUpdateCustomStatusFunc;
onRealTimeServerDisconnected?: CommonFunc;
onRealTimeServerConnected?: CommonFunc;
onRoomPropertiesChangeFailed?: ErrorFunc;
onInstantMessageFailed?: ErrorFunc;
}
declare interface GetCacheResponse extends BaseResponse {
value?: string;
}
declare interface GetRoomInfoResponse extends BaseResponse {
roomInfo: RoomInfo_2;
}
export declare interface gobeDevloperCode {
appId: string;
gameServer: GameServer;
}
/**
* 自定义错误类
* @public
*/
export declare class GOBEError extends Error {
code: number;
msg?: string;
constructor(code: number, message?: string);
}
export declare const enum ImType {
ALL_PLAYERS_EXCEPT_ME = 1,
SPECIFILED_PLAYERS = 2
}
declare interface LocalServerChannelResponse extends BaseResponse {
epAddr: string;
roomId: string;
roomTicket: string;
setupTicket: string;
joinTicket: string;
autoFrame: number;
frameRate: number;
}
declare interface LocalServerMethodRoute {
init: (appId: string, clientId: string, clientSecret: string) => Promise<AuthResponse>;
getRoomList: (roomType: string) => Promise<AvailableRoomsResponse>;
joinRoom: (roomCode: string, roomId: string) => Promise<BaseResponse>;
}
export declare const localServerMethodRoute: LocalServerMethodRoute;
export declare class Logger {
static level: LogLevel;
debug(debugInfo: string): void;
info(info: string): void;
warn(info: string): void;
error(errInfo: string): void;
}
export declare enum LogLevel {
DEBUG = 1,
INFO = 2,
ERROR = 3,
OFF = 4
}
/**
* 云侧sdk接口定义文档
*/
declare interface MethodRoute {
createRoom: (request: ServerLessMethodRequest) => void;
}
export declare const myHandler: (event: serverInterface.ServerLessEvent, context: serverInterface.ServerLessContext, callback: (res: any) => void, logger: any) => void;
export declare type OnRecvFrameFunc = (msg: RecvFrameMessage | RecvFrameMessage[], args: ActionArgs) => void;
export declare type OnRecvFromClientFunc = (msg: RecvFromClientInfo, args: ActionArgs) => void;
export declare type OnRoomPropertiesChangeFunc = (msg: UpdateRoomInfo, args: ActionArgs) => void;
export declare type OnUpdateCustomPropertiesFunc = (player: FramePlayerPropInfo, args: ActionArgs) => void;
export declare type OnUpdateCustomStatusFunc = (msg: PlayerStatusInfo, args: ActionArgs) => void;
export declare interface PlayerInfo {
playerId: string;
status?: number;
customPlayerStatus?: number;
customPlayerProperties?: string;
teamId?: string;
isRobot?: number;
robotName?: string;
matchParams?: Record<string, string>;
}
declare interface PlayerInfo_2 {
playerId: string;
status?: number;
customPlayerStatus?: number;
customPlayerProperties?: string;
teamId?: string;
isRobot?: number;
robotName?: string;
matchParams?: Record<string, string>;
}
/**
* 帧数据玩家信息
* @public
*/
export declare interface PlayerStatusInfo {
playerId: string;
customStatus: number;
}
/**
* 帧广播消息
* @public
*/
export declare interface RecvFrameMessage extends ServerFrameMessage {
isReplay: boolean;
time: number;
}
/**
* 房间消息广播回调参数
* @param roomId - 房间ID
* @param sendPlayerId - 发送者playerId
* @param msg - 消息内容
* @public
*/
export declare interface RecvFromClientInfo {
srcPlayer: string;
msg: string;
}
export declare interface RoomInfo {
appId: string;
roomId: string;
roomType: string;
roomCode: string;
roomName: string;
roomStatus: number;
customRoomProperties: string;
ownerId: string;
maxPlayers: number;
players: PlayerInfo[];
router: RouterInfo;
isPrivate: number;
isLock: number;
createTime: number;
}
declare interface RoomInfo_2 {
appId: string;
roomId: string;
roomType: string;
roomCode: string;
roomName: string;
roomStatus: number;
customRoomProperties: string;
ownerId: string;
maxPlayers: number;
players: PlayerInfo_2[];
router: RouterInfo_2;
isPrivate: number;
isLock: number;
createTime: number;
}
export declare interface RouterInfo {
routerId: number;
routerType: number;
routerAddr: string;
}
declare interface RouterInfo_2 {
routerId: number;
routerType: number;
routerAddr: string;
}
/**
* 服务端 ACK 消息
*/
declare interface ServerAckMessage {
rtnCode: number;
msg: string;
}
/**
* 服务端推送消息
* @public
*/
export declare interface ServerFrameMessage {
currentRoomFrameId: number;
frameInfo: FrameInfo[];
ext: FrameExtInfo;
}
/**
* 服务端返回帧数据玩家信息
* @public
*/
export declare interface ServerFramePlayerInfo extends FramePlayerInfo {
extraInfo?: string;
}
declare namespace serverInterface {
export {
MethodRoute,
ServerLessEvent,
ServerLessEventBody,
ServerLessEventBodyRequest,
ServerLessContext,
ServerLessMethodRequest,
ArgsConfig,
ServerAckMessage,
BaseResponse,
AuthResponse,
AvailableRoomsResponse,
GetRoomInfoResponse,
CreateChannelResponse,
LocalServerChannelResponse,
GetCacheResponse,
CreateChannelResponseData,
RoomInfo_2 as RoomInfo,
PlayerInfo_2 as PlayerInfo,
RouterInfo_2 as RouterInfo,
CacheValue_2 as CacheValue,
LocalServerMethodRoute
}
}
declare interface ServerLessContext {
env: {
GOBE_EDGE_DOMAIN: string;
DEVELOPER_PROJECT_ID: string;
DEVELOPER_APP_ID: string;
WS_HEARTBEAT_CYCLE: string;
};
}
declare interface ServerLessEvent {
body: string;
headers: {
ticket: string;
};
}
declare interface ServerLessEventBody {
method: keyof MethodRoute;
request: string;
data: string;
setupTicket: string;
joinTicket: string;
}
declare interface ServerLessEventBodyRequest {
roomId: string;
operator?: string;
epAddress: string;
autoFrame: string;
frameRate: string;
}
declare interface ServerLessMethodRequest {
roomId: string;
operator?: string;
ticket: string;
domain: string;
data: string;
projectId: string;
logger: any;
appId: string;
epAddress: string;
setupTicket: string;
joinTicket: string;
autoFrame: string;
frameRate: string;
wsHeartbeatCycle: string;
}
/**
* 可以更新的房间信息属性
* @public
* @param roomName - 房间名称
* @param customRoomProperties - 房间自定义属性
* @param ownerId - 房主ID
* @param isPrivate - 是否私有
* @param isLock - 是否锁定房间 0:非锁定(允许加入房间),1:锁定(不允许加入房间)
* @param roomType - 房间类型
*/
export declare interface UpdateRoomInfo {
roomName?: string;
customRoomProperties?: string;
ownerId?: string;
isPrivate?: number;
isLock?: number;
roomType?: string;
}
export { }
export as namespace GOBERTS