//
//  RCWSClient.h
//  Demo
//
//  Created by 余衡武 on 2024/10/10.
//

#import <Foundation/Foundation.h>

/*
 * author 孔凡列
 *
 * gitHub https://github.com/gitkong
 * cocoaChina http://code.cocoachina.com/user/
 * 简书 http://www.jianshu.com/users/fe5700cfb223/latest_articles
 * QQ 279761135
 * 喜欢就给个like 和 star 喔~
 */
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"


#import <Foundation/Foundation.h>

/**
 *  @author 孔凡列
 *
 *  socket状态
 */
typedef NS_ENUM(NSInteger,RCSocketStatus) {
    RCSocketStatusConnected,// 已连接
    RCSocketStatusFailed,// 失败
    RCSocketStatusClosedByServer,// 系统关闭
    RCSocketStatusClosedByUser,// 用户关闭
    RCSocketStatusReceived// 接收消息
};
/**
 *  @author 孔凡列
 *
 *  消息类型
 */
typedef NS_ENUM(NSInteger,RCSocketReceiveType) {
    RCSocketReceiveTypeForMessage,
    RCSocketReceiveTypeForPing,
    RCSocketReceiveTypeForPong
};
/**
 *  @author 孔凡列
 *
 *  连接成功回调
 */
typedef void(^RCSocketDidConnectBlock)();
/**
 *  @author 孔凡列
 *
 *  失败回调
 */
typedef void(^RCSocketDidFailBlock)(NSError *error);
/**
 *  @author 孔凡列
 *
 *  关闭回调
 */
typedef void(^RCSocketDidCloseBlock)(NSInteger code,NSString *reason,BOOL wasClean);
/**
 *  @author 孔凡列
 *
 *  消息接收回调
 */
typedef void(^RCSocketDidReceiveBlock)(id message ,RCSocketReceiveType type);

@interface RCWSClient : NSObject
/**
 *  @author 孔凡列
 *
 *  连接回调
 */
@property (nonatomic,copy)RCSocketDidConnectBlock connect;
/**
 *  @author 孔凡列
 *
 *  接收消息回调
 */
@property (nonatomic,copy)RCSocketDidReceiveBlock receive;
/**
 *  @author 孔凡列
 *
 *  失败回调
 */
@property (nonatomic,copy)RCSocketDidFailBlock failure;
/**
 *  @author 孔凡列
 *
 *  关闭回调
 */
@property (nonatomic,copy)RCSocketDidCloseBlock close;
@property (nonatomic,copy)RCSocketDidCloseBlock closeCallBack;
/**
 *  @author 孔凡列
 *
 *  当前的socket状态
 */
@property (nonatomic,assign,readonly)RCSocketStatus fl_socketStatus;
/**
 *  @author 孔凡列
 *
 *  超时重连时间，默认1秒
 */
@property (nonatomic,assign)NSTimeInterval overtime;
/**
 *  @author Clarence
 *
 *  重连次数,默认5次
 */
@property (nonatomic, assign)NSUInteger reconnectCount;
/**
 *  @author 孔凡列
 *
 *  连接地址：urlString
 */
@property (nonatomic,copy,readonly)NSString *urlString;
/**
 *  @author 孔凡列
 *
 *  连接地址：当前连接时 token值已改变
 */
@property (nonatomic,copy)NSString *currentToken;
/**
 *  @author 余衡武
 *
 *  同步指令 成功次数
 */
@property (nonatomic, assign)NSUInteger syscSuccess;

/**
 *  @author 余衡武
 *
 *  同步指令 失败次数
 */
@property (nonatomic, assign)NSUInteger syscFail;

/**
 *  @author 孔凡列
 *
 *  开启socket
 *
 *  @param urlStr  服务器地址
 *  @param connect 连接成功回调
 *  @param receive 接收消息回调
 *  @param failure 失败回调
 */
- (void)fl_open:(NSString *)urlStr connect:(RCSocketDidConnectBlock)connect receive:(RCSocketDidReceiveBlock)receive failure:(RCSocketDidFailBlock)failure;
/**
 *  @author 孔凡列
 *
 *  关闭socket
 *
 *  @param close 关闭回调
 */
- (void)fl_close:(RCSocketDidCloseBlock)close;
/**
 *  @author 孔凡列
 *
 *  发送消息，NSString 或者 NSData
 *
 *  @param data Send a UTF8 String or Data.
 */
- (void)fl_send:(id)data;

/**
 * Ping-Pong 心跳机制
 */
- (void)fl_sendPong:(id)data;

/**
 * Ping-Pong 心跳机制
 */
- (void)fl_sendPing:(id)data;

@end

#pragma clang diagnostic pop

