gpt4 book ai didi

javascript - WebSync Publish ClientId 变为零

转载 作者:行者123 更新时间:2023-11-28 03:46:27 34 4
gpt4 key购买 nike

当我在 Websync publish 中传递 Client.clientId 时出现问题方法中,当被 OnReceive 捕获时,clientId 有时会变成全零。来自客户端的事件。

我可以知道为什么有时 clientId 值会通过 channel 成功发送,但大多数情况下 clientId 值会以某种方式变为全零,例如 00000000-0000-0000-0000-000000000000。

下面是我的代码

订阅

var client = new fm.websync.client('http://localhost:12345/websync');

client.connect
({
onSuccess: function (e) {
$('#connectionStat').val('Successfully connected');
},
onFailure: function (e) {
$('#connectionStat').val('Failed to be connected');
},
onStreamFailure: function (e) {
$('#connectionStat').val('Failed to be connected on stream');
}
});

client.subscribe({
channel: '/testService/clientId',
onSuccess: function (e) {

},
onFailure: function (e) {

},
onReceive: function (e) {
alert(e.getData());
}
});

发布

Client client = new Client("http://localhost:12345/websync");
client.Connect(new ConnectArgs
{
OnSuccess = (e) =>
{
Debug.WriteLine("Successfully connected [OnSuccess]");
},
OnFailure = (e) =>
{
Debug.WriteLine("Failed in connected [OnFailure]");
},
OnComplete = (e) =>
{
Debug.WriteLine("Successfully connected [OnComplete]");
},
OnStreamFailure = (e) =>
{
Debug.WriteLine("Failed connected [OnStreamFailure]");
}
});

client.Publish(new PublishArgs("/testService/clientId", Json.Serialize(client.ClientId))
{
OnSuccess = (e) =>
{
Debug.WriteLine("Successfully published client id [OnSuccess] = " + client.ClientId.ToString());
},
OnComplete = (e) =>
{
Debug.WriteLine("Successfully published [OnComplete]");
},
OnFailure = (e) =>
{
Debug.WriteLine("Failed to publish [OnFailure]");
},
});

最佳答案

等待发布,直到连接成功完成。客户端的 ID 由服务器生成,当调用 Publish 时,Connect 操作可能尚未完成。

最简单的方法是将 Publish 调用移至 ConnectOnSuccess 回调中。

关于javascript - WebSync Publish ClientId 变为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48438036/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com