【问题标题】:Flutter Pusher Private Channel Notification ProblemFlutter Pusher 私有通道通知问题
【发布时间】:2022-11-03 11:51:10
【问题描述】:

我在我的颤振应用程序中使用pusher-channels-flutter 包,后端是 Laravel。 当我连接到 Pusher 时,它给了我这个错误。

[  +65 ms] I/PusherChannelsFlutter(20214): Start com.pusher.client.Pusher@4083fc0
[ +102 ms] I/flutter (20214): LOG: Connection: CONNECTING
[+1566 ms] I/flutter (20214): LOG: Connection: CONNECTED
[+1566 ms] I/flutter (20214): LOG: onSubscriptionError: Unable to parse response from Authorizer: null Exception: com.pusher.client.AuthorizationFailureException: Unable to parse
response from Authorizer: null

这是推送器初始化功能。

void onConnect() async {
    if (!_channelFormKey.currentState!.validate()) {
      return;
    }

    try {
      await pusher.init(
        apiKey: _apiKey,
        cluster: _cluster,
        onConnectionStateChange: onConnectionStateChange,
        onError: onError,
        onSubscriptionSucceeded: onSubscriptionSucceeded,
        onEvent: onEvent,
        onSubscriptionError: onSubscriptionError,
        onDecryptionFailure: onDecryptionFailure,
        onMemberAdded: onMemberAdded,
        onMemberRemoved: onMemberRemoved,
        //authEndpoint: "https://my-website.com/broadcasting/auth",
        onAuthorizer: onAuthorizer,
      );
      await pusher.subscribe(channelName: _channelName.text);
      await pusher.connect();
    } catch (e) {
      print("$e");
      log("ERROR: $e");
    }
  }

这是onAuthorizer 函数

 dynamic onAuthorizer(
      String channelName, String socketId, dynamic options) async {
    var authUrl = "https://my-website.com/broadcasting/auth";
    var result = await http.post(
      Uri.parse(authUrl),
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Bearer ${token}',
      },
      body: 'socket_id=' + socketId + '&channel_name=' + channelName,
    );
    return jsonDecode(result.body);
  }

似乎要求authUrl = "https://my-website.com/broadcasting/auth" retun null,我尝试将Content-Type 作为json 但返回相同的结果。

  headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ${token}',
      }

如果有人将推送器与颤振集成,请分享您的经验。

【问题讨论】:

    标签: laravel flutter notifications pusher


    【解决方案1】:

    如果您解决了这个问题,请告诉我。 我也有私人频道订阅。

    【讨论】:

      猜你喜欢
      • 2023-01-15
      • 2020-11-22
      • 2020-06-29
      • 2022-06-15
      • 2020-01-07
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      相关资源
      最近更新 更多