connection.dart 620 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'package:fis_common/event/event_type.dart';
  2. enum ConnectionStatus {
  3. connecting,
  4. connected,
  5. connectFailed,
  6. connectedClosed,
  7. }
  8. abstract class IConnection {
  9. /// 连接状态
  10. ConnectionStatus get status;
  11. /// 是否已连接
  12. bool get isConnected;
  13. /// 是否保活
  14. bool get isKeepAlive;
  15. /// 接收消息事件
  16. late FEventHandler<dynamic> messageReceived;
  17. /// 发送异常事件
  18. FEventHandler<Exception>? exceptionOccurred;
  19. /// 状态变更事件
  20. FEventHandler<ConnectionStatus>? statusChanged;
  21. /// 连接
  22. Future<bool> connect();
  23. /// 关闭连接
  24. Future<bool> close();
  25. }