【发布时间】:2020-12-09 08:53:32
【问题描述】:
我正在尝试使用 Flutter 连接到 stomp WebSocket。 我正在使用 stomp_dart_client 0.3.8 库。 这是我的代码(我遵循了他们 GIT 上的文档):
void onConnectcallback(StompClient client, StompFrame connectFrame) {
client.subscribe(
destination: '/notification/app/test',
headers: {' Auth-Token': Statics.accessToken},
callback: ( StompFrame connectFrame ) {
List<dynamic> result = json.decode(connectFrame.body);
print(connectFrame.body);
print(result);
print('it worked');
}
);
print("i think i work");
}
testconnection() {
final stompClient= StompClient(config: StompConfig(
url:' ws://messagerie-rcc.be-idys.com',
onWebSocketError: (dynamic error) => print(error.toString()),
onStompError:(dynamic error) => print(error.toString()),
onConnect: onConnectcallback,
stompConnectHeaders: {' Auth-Token': Statics.accessToken},
webSocketConnectHeaders: {' Auth-Token':Statics.accessToken},));
stompClient.activate();
print('I think its workinf');
}
然后我调用 testconnection()。 当我调试时它正在跳过:
onConnect: onConnectcallback,
我尝试添加参数并制作它
onConnect: onConnectcallback(client, connectFrame),
我明白了:
The method 'subscribe' was called on null.
Receiver: null
Tried calling: subscribe(callback: Closure: (StompFrame) => Null, destination: "/notification/app/test", headers: _LinkedHashMap len:1)
【问题讨论】:
-
是否可以使用普通身份验证代替令牌?