小编Abd*_*her的帖子

如何在Flutter中使用Pusher的私有通道

我正在使用Pusher_channels_flutter来获取实时通知。

我想在Flutter中使用Pusher的Private通道。

await pusher.subscribe(channelName: "private-chat.5");

但我得到了这个错误:

日志:错误:PlatformException(错误,无法订阅私有或存在通道,因为尚未设置授权者。在连接到 Pusher 之前调用 PusherOptions.setAuthorizer(),null,java.lang.IllegalStateException:无法订阅私有或存在通道因为还没有设置Authorizer,在连接Pusher之前调用PusherOptions.setAuthorizer()

当我添加onAuthorizer功能时,我是这样添加的:

dynamic onAuthorizer(String channelName, String socketId, dynamic options) async {
    return {
     "auth": "foo:bar",
    "channel_data": '{"user_id": 1}',
    "shared_secret": "foobar"
    };
  }
Run Code Online (Sandbox Code Playgroud)

但我得到了这个错误:

日志:onError:订阅身份验证数据中的密钥无效:“令牌”代码:null 异常:null

auth我应该在 onAuthorizer 映射的和channel_data和键的值中放入什么shared_secret

我的完整代码:

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:shared_preferences/shared_preferences.dart';
import 'package:pusher_channels_flutter/pusher_channels_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class …
Run Code Online (Sandbox Code Playgroud)

notifications push-notification dart pusher flutter

0
推荐指数
2
解决办法
3556
查看次数

标签 统计

dart ×1

flutter ×1

notifications ×1

push-notification ×1

pusher ×1