mirror of
https://github.com/wyb10a10/cocos_creator_framework.git
synced 2026-06-06 09:09:39 +08:00
调整接口
This commit is contained in:
@@ -21,13 +21,13 @@ export interface RequestObject {
|
||||
rspObject: CallbackObject, // 等待响应的回调对象
|
||||
}
|
||||
|
||||
// 协议对象
|
||||
// 协议辅助接口
|
||||
export interface IProtocolHelper {
|
||||
getHeadlen(): number; // 返回包头长度
|
||||
getHearbeat(): NetData; // 返回一个心跳包
|
||||
getPackageLen(msg: NetData): number; // 返回整个包的长度
|
||||
checkHead(msg: NetData): boolean; // 检查数据头部是否合法
|
||||
checkCmd(msg: NetData): number; // 获取协议类型或id
|
||||
checkPackage(msg: NetData): boolean; // 检查包数据是否合法
|
||||
getPackageId(msg: NetData): number; // 返回包的id或协议类型
|
||||
}
|
||||
|
||||
// 默认字符串协议对象
|
||||
@@ -42,26 +42,27 @@ export class DefStringProtocol implements IProtocolHelper {
|
||||
{
|
||||
return msg.toString().length;
|
||||
}
|
||||
checkHead(msg: NetData): boolean {
|
||||
checkPackage(msg: NetData): boolean {
|
||||
return true;
|
||||
}
|
||||
checkCmd(msg: NetData): number {
|
||||
getPackageId(msg: NetData): number {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Socket对象
|
||||
// Socket接口
|
||||
export interface ISocket {
|
||||
onConnected: (event) => void;
|
||||
onMessage: (msg: NetData) => void;
|
||||
onError: (event) => void;
|
||||
onClosed: (event) => void;
|
||||
connect(options: any): boolean;
|
||||
send(buffer: NetData): boolean;
|
||||
close(code?: number, reason?: string);
|
||||
onConnected: (event) => void; // 连接回调
|
||||
onMessage: (msg: NetData) => void; // 消息回调
|
||||
onError: (event) => void; // 错误回调
|
||||
onClosed: (event) => void; // 关闭回调
|
||||
|
||||
connect(options: any); // 连接接口
|
||||
send(buffer: NetData); // 数据发送接口
|
||||
close(code?: number, reason?: string); // 关闭接口
|
||||
}
|
||||
|
||||
// 网络提示对象
|
||||
// 网络提示接口
|
||||
export interface INetworkTips {
|
||||
connectTips(isShow: boolean): void;
|
||||
reconnectTips(isShow: boolean): void;
|
||||
|
||||
Reference in New Issue
Block a user