connect method

void connect()

Implementation

void connect() async {
  if (stompClient != null && stompClient!.connected) {
    debugPrint('already connected');
    return;
  }
  debugPrint('connecting...');
  bytedeskEventBus.fire(
      ConnectionEventBus(BytedeskConstants.CONNECTION_STATUS_CONNECTING));
  messageProvider = MessageProvider();
  orgUid = SpUtil.getString(BytedeskConstants.VISITOR_ORGUID);

  // 初始化StompClient对象
  subscribedTopics = [];
  stompClient = StompClient(
    config: StompConfig(
      url: BytedeskConstants.stompWsUrl,
      onConnect: onConnect,
      beforeConnect: () async {
        // await Future.delayed(const Duration(milliseconds: 200));
        debugPrint('before connecting...');
      },
      onWebSocketError: (dynamic error) => debugPrint(error.toString()),
      stompConnectHeaders: {'Authorization': 'Bearer yourToken'},
      webSocketConnectHeaders: {'Authorization': 'Bearer yourToken'},
    ),
  );
  stompClient?.activate();
}