vin*_*nay 3 dart flutter agora.io
在创建 agora 视频通话应用程序时,我遇到这样的错误
HandshakeException(HandshakeException:客户端握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED:证书已过期(handshake.cc:393)))
这是抛出错误的行
Response _response = await get(Uri.parse(link));
Run Code Online (Sandbox Code Playgroud)
我的代码是
import 'dart:convert';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
class VedioCall extends StatefulWidget {
String channelName = "test";
VedioCall({required this.channelName});
@override
State<VedioCall> createState() => _VedioCallState();
}
class _VedioCallState extends State<VedioCall> {
late final AgoraClient _client;
bool _loading = true;
String tempToken = "";
@override
void initState() {
getToken();
super.initState();
}
Future<void> getToken() async {
String link =
"https://Agora-Node-TokenServer.vinaym4.repl.co/access_token?channelName=${widget.channelName}";
Response _response = await get(Uri.parse(link));
Map data = jsonDecode(_response.body);
setState(() {
tempToken = data["token"];
});
_client = AgoraClient(
agoraConnectionData: AgoraConnectionData(
appId: "5a4c1108a1af4a76924c9461d120dc47",
tempToken: tempToken,
channelName: widget.channelName,
),
enabledPermission: [Permission.camera, Permission.microphone]);
Future.delayed(Duration(seconds: 1)).then(
(value) => setState(() => _loading = false),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: _loading
? Center(
child: CircularProgressIndicator(),
)
: Stack(
children: [
AgoraVideoViewer(
client: _client,
),
AgoraVideoButtons(client: _client)
],
),
),
);
;
}
}
Run Code Online (Sandbox Code Playgroud)
lep*_*sch 10
证书今天刚刚更改。看起来 Android 没有正确读取初始日期作为包含日期。我想如果你明天尝试就会成功。
同时,您可以尝试在另一个正常Windows运行的平台上进行测试。
或者您可以使用以下方法覆盖证书验证:
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}
Run Code Online (Sandbox Code Playgroud)
并HttpOverrides.global在main方法中设置如下:
void main() {
HttpOverrides.global = MyHttpOverrides();
runApp(const MyApp());
}
Run Code Online (Sandbox Code Playgroud)
注意:这是一个安全风险,因为每个无效的证书都会被接受。因此,在生产中请删除此代码。
| 归档时间: |
|
| 查看次数: |
10657 次 |
| 最近记录: |