请注意,您必须在服务器端指定 type 属性,否则将收到错误消息-Type ... not found on message。 如果您不想把type的属性名作为键名,可以在调用 forRoot 时指定自己的属性名称:
In order to kick off our websockets we have to dispatch the ConnectWebSocket action. This will typically happen at startup or if you need to authenticate before, after authentication is done. You can optionally pass the URL here.
In summary - your server-side sockets should send objects that have a type property (or another key that you can provide in the typeKey property when calling forRoot). This plugin will receive a message from the server and dispatch the message as an action with the corresponding type value. If the type property doesn't match any client-side @Action methods (with an Action with the corresponding static type property value) then no State will respond to the message. 总而言之——您的服务器端套接字应发送具有type属性(或在调用forRoot 时可以在typeKey属性中提供的另一个键名)的对象。 该插件将从服务器接收一条消息,并使用相应的 type 值将该消息作为动作进行调度。如果 type 属性与任何客户端 @Action 方法都不匹配(带有具有相应 static type 属性值的动作),则没有状态会响应该消息。