RCSocketManagerForCloudPhone.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. *
  3. */
  4. #import <Foundation/Foundation.h>
  5. /**
  6. *
  7. *
  8. * socket状态
  9. */
  10. typedef NS_ENUM(NSInteger, RCSocketCloudPhoneStatus){
  11. RCSocketCloudPhoneStatusConnected,// 已连接
  12. RCSocketCloudPhoneStatusFailed,// 失败
  13. RCSocketCloudPhoneStatusClosedByServer,// 系统关闭
  14. RCSocketCloudPhoneStatusClosedByUser,// 用户关闭
  15. RCSocketCloudPhoneStatusReceived// 接收消息
  16. };
  17. /**
  18. *
  19. *
  20. * 消息类型
  21. */
  22. typedef NS_ENUM(NSInteger,FLSocketCloudPhoneReceiveType){
  23. RCSocketCloudPhoneReceiveTypeForMessage,
  24. RCSocketCloudPhoneReceiveTypeForPong
  25. };
  26. /**
  27. *
  28. *
  29. * 连接成功回调
  30. */
  31. typedef void(^RCSocketCloudPhoneDidConnectBlock)(void);
  32. /**
  33. *
  34. *
  35. * 失败回调
  36. */
  37. typedef void(^RCSocketCloudPhoneDidFailBlock)(NSError *error);
  38. /**
  39. *
  40. *
  41. * 关闭回调
  42. */
  43. typedef void(^RCSocketCloudPhoneDidCloseBlock)(NSInteger code,NSString *reason,BOOL wasClean);
  44. /**
  45. *
  46. *
  47. * 消息接收回调
  48. */
  49. typedef void(^RCSocketCloudPhoneDidReceiveBlock)(id message ,FLSocketCloudPhoneReceiveType type);
  50. @interface RCSocketManagerForCloudPhone : NSObject
  51. /**
  52. *
  53. *
  54. * 连接回调
  55. */
  56. @property (nonatomic, copy) RCSocketCloudPhoneDidConnectBlock connect;
  57. /**
  58. *
  59. *
  60. * 接收消息回调
  61. */
  62. @property (nonatomic, copy) RCSocketCloudPhoneDidReceiveBlock receive;
  63. /**
  64. *
  65. *
  66. * 失败回调
  67. */
  68. @property (nonatomic, copy) RCSocketCloudPhoneDidFailBlock failure;
  69. /**
  70. *
  71. *
  72. * 关闭回调
  73. */
  74. @property (nonatomic, copy) RCSocketCloudPhoneDidCloseBlock close;
  75. /**
  76. *
  77. *
  78. * 当前的socket状态
  79. */
  80. @property (nonatomic, assign, readonly) RCSocketCloudPhoneStatus fl_socketStatus;
  81. /**
  82. * @author Clarence
  83. *
  84. * 重连次数,默认5次
  85. */
  86. @property (nonatomic, assign) NSUInteger reconnectCount;
  87. /**
  88. *
  89. *
  90. * 单例调用
  91. */
  92. //+ (instancetype)shareManager;
  93. /**
  94. *
  95. *
  96. * 开启socket
  97. *
  98. * @param urlStr 服务器地址
  99. * @param connect 连接成功回调
  100. * @param receive 接收消息回调
  101. * @param failure 失败回调
  102. */
  103. - (void)fl_open:(NSString *)urlStr
  104. connect:(RCSocketCloudPhoneDidConnectBlock)connect
  105. receive:(RCSocketCloudPhoneDidReceiveBlock)receive
  106. failure:(RCSocketCloudPhoneDidFailBlock)failure;
  107. /**
  108. *
  109. *
  110. * 关闭socket
  111. *
  112. * @param close 关闭回调
  113. */
  114. - (void)fl_close:(RCSocketCloudPhoneDidCloseBlock)close;
  115. /**
  116. *
  117. *
  118. * 发送消息,NSString 或者 NSData
  119. *
  120. * @param data Send a UTF8 String or Data.
  121. */
  122. - (void)fl_send:(id)data;
  123. @end