发布1.0.27版本

This commit is contained in:
宫欣海 2025-04-06 21:25:34 +08:00
parent 06d15e541b
commit be0c5aa0d5
5 changed files with 51 additions and 4 deletions

View File

@ -1,3 +1,5 @@
## 1.0.25
- 添加Time时间工具支持同步服务器时间提供一系列时间格式化方法
## 1.0.27
- 添加socket网络模块支持所有平台抹平微信、支付宝、抖音小游戏和web以及原生平台的使用差异

View File

@ -25,7 +25,7 @@ npm install kunpocc
12. [屏幕尺寸](./docs/Screen.md)
13. [小工具](./docs/Tools.md)
14. [时间](./docs/Time.md)
15. [socket网络模块](./docs/Socket.md)
## 类型支持
该库完全使用 TypeScript 编写,提供完整的类型定义文件。

45
docs/Socket.md Normal file
View File

@ -0,0 +1,45 @@
## socket网络模块
* 目的抹平小游戏平台和原生平台的使用差异
`各个小游戏平台都是自己封装的socket 和 浏览器标准的websocket在用法上有一定的差异`
#### 使用
```typescript
import { Socket } from "kunpocc";
// 创建一个连接
let url = "wss:xxxxxxxx"
let socket = new Socket(url, { binaryType: "arraybuffer" });
// 监听连接open事件
socket.onopen = () => {
log("连接成功");
}
// 监听收到服务端的消息
socket.onmessage = (data: string | ArrayBuffer) => {
log("收到消息", data);
}
// 监听连接关闭的事件
socket.onclose = (code: number, reason: string) => {
log("连接关闭", code, reason);
socket = null;
}
// 发送字符串消息
socket.send("发送给服务端的消息");
// 发送二进制数据 一般都是使用ProtoBuf具体使用可参考Demo
socket.sendBuffer(buffer);
// 主动断开连接
socket.close(3001, "主动断开连接");
```

View File

@ -1,6 +1,6 @@
{
"name": "kunpocc",
"version": "1.0.26",
"version": "1.0.27",
"description": "基于creator3.0+的kunpocc库",
"main": "./dist/kunpocc.cjs",
"module": "./dist/kunpocc.mjs",

View File

@ -271,7 +271,7 @@ export class Socket {
*
* @param data -
*/
public onmessage: (data: any) => void;
public onmessage: (data: string | ArrayBuffer) => void;
/**
*