你如何在自己创建的UI中连接到Weavy的Websockets?

huangapple go评论56阅读模式
英文:

How can I connect to websockets in Weavy if I am making my own UI?

问题

Websockets在集成Weavy时特别重要,因为它有助于Weavy环境处理实时通信。文档中提供了与Javascript、Javascript与.Net等相关的UI工具包的参考信息。但如果我要使用文档中未提及的技术创建自己的UI,那么在集成Weavy时如何连接到websockets呢?

我尝试在文档中查找有关如何在自定义UI中连接websockets的信息,但没有找到任何合适的答案或相关的常见问题解答。

英文:

Websockets are particularly important when it comes to integrating Weavy because it helps the Weavy environment in handling realtime communications. In the documentation, there are references given for UI kits related to Javascript, Javascript with .Net, etc. But if I am making my own UI with technologies other than the ones mentioned in the documentation, then what is the way to connect to websockets while integrating Weavy?

I tried finding about connecting websockets with custom UI in the documentation but didn't get any proper answer or any FAQ related to it.

答案1

得分: 2

I'll provide a translation of the text you shared:

"目前还没有开放的 API 可以连接到 Weavy 实时服务器。这是我们将来会创建的东西。但如果你想查看它是如何完成的,例如在 React UI 套件中,你可以查看 WeavyClient 如何连接到实时 hub。

https://github.com/weavy/weavy-uikit-react/blob/a65e66a10e1e8d7483f45b431275248c28f15a17/src/client/WeavyClient.ts#L23

当连接建立后,你需要订阅来自 Weavy 服务器的特定事件。

Subscribe 服务器方法需要一个特定格式的组名。正如我所说,这尚未有文档记录。但作为示例,如果你想监听特定应用程序中创建的消息,你需要使用以下格式:

a[应用程序 ID]:[事件]

示例:

a13:message_created

a 表示这是一个应用程序,数字 13 是应用程序的 ID,message_created 是你想订阅的事件。

这是 React UI Kit 中一个组件的示例:

https://github.com/weavy/weavy-uikit-react/blob/a65e66a10e1e8d7483f45b431275248c28f15a17/src/components/Messages.tsx#L68

总结一下... 目前还没有开放的 API。以上所示的内容可能看起来有点复杂,因为它是内部逻辑,不是预期公开的。"

I've provided the translated content as requested.

英文:

At the moment, there is no open api to connect to the Weavy realtime server. This is something that we will create in the future. But if you want to take a look at how it's done, for example in the React UI kit, you can check out how the WeavyClient connects to the realtime hub.

https://github.com/weavy/weavy-uikit-react/blob/a65e66a10e1e8d7483f45b431275248c28f15a17/src/client/WeavyClient.ts#L23

When a connection is established, you have to susbscribe to specific events from the Weavy server.

The Subscribe server method expects a group name which is in a specific format. This is as I said not documented yet. But as an example, if you want to listen to created messages in a specific app, you have to use the format:

a[app id]:[event]

Example:

a13:message_created

The a means it's an app, the number 13 is the id of the app, and message_created is the event you want to subscribe to.

Here is an example from a component in the React UI Kit:

https://github.com/weavy/weavy-uikit-react/blob/a65e66a10e1e8d7483f45b431275248c28f15a17/src/components/Messages.tsx#L68

To summarize... No open api yet. It might seem a bit complicated since what I showed above is internal logic and not what is expected to be exposed.

huangapple
  • 本文由 发表于 2023年4月6日 22:08:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950468.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定