github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/websocket_actions.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package fftypes 18 19 // WSClientPayloadType actions go from client->server 20 type WSClientPayloadType = LowerCasedType 21 22 const ( 23 // WSClientActionStart is a request to the server to start delivering messages to the client 24 WSClientActionStart WSClientPayloadType = "start" 25 // WSClientActionAck acknowledges an event that was delivered, allowing further messages to be sent 26 WSClientActionAck WSClientPayloadType = "ack" 27 28 // WSProtocolErrorEventType is a special event "type" field for server to send the client, if it performs a ProtocolError 29 WSProtocolErrorEventType WSClientPayloadType = "protocol_error" 30 ) 31 32 // WSClientActionBase is the base fields of all client actions sent on the websocket 33 type WSClientActionBase struct { 34 Type WSClientPayloadType `json:"type,omitempty"` 35 } 36 37 // WSClientActionStartPayload starts a subscription on this socket - either an existing one, or creating an ephemeral one 38 type WSClientActionStartPayload struct { 39 WSClientActionBase 40 41 AutoAck *bool `json:"autoack"` 42 Namespace string `json:"namespace"` 43 Name string `json:"name"` 44 Ephemeral bool `json:"ephemeral"` 45 Filter SubscriptionFilter `json:"filter"` 46 Options SubscriptionOptions `json:"options"` 47 } 48 49 // WSClientActionAckPayload acknowldges a received event (not applicable in AutoAck mode) 50 type WSClientActionAckPayload struct { 51 WSClientActionBase 52 53 ID *UUID `json:"id,omitempty"` 54 Subscription *SubscriptionRef `json:"subscription,omitempty"` 55 } 56 57 // WSProtocolErrorPayload is sent to the client by the server in the case of a protocol error 58 type WSProtocolErrorPayload struct { 59 Type WSClientPayloadType `json:"type"` 60 Error string `json:"error"` 61 }