@qy_better_lib/hooks 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DOCUMENTATION.md CHANGED
@@ -623,56 +623,7 @@ emitter.on('test', (data) => {
623
623
  emitter.off('test', listener);
624
624
  ```
625
625
 
626
- ### 10. use-websocket - WebSocket功能
627
626
 
628
- #### 功能描述
629
- 适用于需要在前端实现WebSocket通信的场景,支持自动重连、心跳检测、消息队列等功能。
630
-
631
- #### 参数
632
- - `options: WebSocketOptions` - WebSocket配置选项
633
-
634
- #### 返回值
635
- - **ws**: `WebSocket | undefined` - WebSocket实例
636
- - **create**: `() => void` - 创建连接
637
- - **close**: `() => void` - 关闭连接
638
- - **send_message**: `(msg: any) => boolean` - 发送消息
639
- - **get_status**: `() => WebSocketStatus` - 获取连接状态
640
- - **reconnect**: `() => void` - 重连
641
- - **start_heartbeat**: `() => void` - 启动心跳检测
642
- - **stop_heartbeat**: `() => void` - 停止心跳检测
643
-
644
- #### 示例
645
- ```typescript
646
- import { use_web_socket } from '@qy_better_lib/hooks';
647
-
648
- const { create, close, send_message, get_status } = use_web_socket({
649
- server: 'ws://localhost:8080',
650
- receive: (event) => {
651
- console.log('收到消息:', event.data);
652
- },
653
- on_open: () => {
654
- console.log('连接成功');
655
- },
656
- on_error: (error) => {
657
- console.error('连接错误:', error);
658
- },
659
- on_close: () => {
660
- console.log('连接关闭');
661
- },
662
- auto_reconnect: true,
663
- heartbeat_interval: 30000
664
- });
665
-
666
- // 发送消息
667
- send_message('Hello WebSocket');
668
-
669
- // 获取连接状态
670
- const status = get_status();
671
- console.log(status);
672
-
673
- // 关闭连接
674
- close();
675
- ```
676
627
 
677
628
  ## 注意事项
678
629