Documentation ¶
Overview ¶
Package websocket
Copyright © 2023 runtimeracer@gmail.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package websocket ¶
Copyright © 2023 runtimeracer@gmail.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package websocket ¶
Copyright © 2023 runtimeracer@gmail.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- type KaiwotoRPCBaseMessage
- func (k *KaiwotoRPCBaseMessage) Deserialize(messageData interface{}) error
- func (k *KaiwotoRPCBaseMessage) DeserializeFromBytes(messageBytes []byte) ([]interface{}, error)
- func (k *KaiwotoRPCBaseMessage) FetchDataFromPayload(output interface{}, ignoreUnset bool) bool
- func (k *KaiwotoRPCBaseMessage) Serialize() []interface{}
- type KaiwotoWebSocketAuthRequest
- type KaiwotoWebSocketAuthResponse
- type KajiwotoRPCAuthorization
- type KajiwotoRPCChatActivity
- type KajiwotoRPCChatActivityChannel
- type KajiwotoRPCChatActivityChannelUser
- type KajiwotoRPCChatActivityData
- type KajiwotoRPCChatActivityInteraction
- type KajiwotoRPCChatActivityMessage
- type KajiwotoRPCChatActivityPetData
- type KajiwotoRPCChatActivitySubActivity
- type KajiwotoRPCChatActivitySubMessage
- type KajiwotoRPCChatEnterMessage
- type KajiwotoRPCChatLeaveMessage
- type KajiwotoRPCChatMessage
- type KajiwotoRPCChatMessageCreate
- type KajiwotoRPCChatMessageCreateData
- type KajiwotoRPCChatRespondData
- type KajiwotoRPCChatRespondMessage
- type KajiwotoRPCChatRoomData
- type KajiwotoRPCChatRoomId
- type KajiwotoRPCChatSendMessage
- type KajiwotoRPCChatUserRole
- type KajiwotoRPCEmptyObject
- type KajiwotoRPCLiveSubMessage
- type KajiwotoRPCLoginMessage
- type KajiwotoRPCMessage
- type KajiwotoRPCStatusUserData
- type KajiwotoRPCSubscribeArgs
- type KajiwotoRPCSubscribeMessage
- type KajiwotoRPCTypingMessage
- type KajiwotoRPCUserData
- type KajiwotoRPCUserStatus
- type KajiwotoRPCUserStatusClientMessage
- type KajiwotoRPCUserStatusData
- type KajiwotoRPCUserStatusServerMessage
- type KajiwotoWebSocketClient
- func (c *KajiwotoWebSocketClient) AddDefaultHandlers()
- func (c *KajiwotoWebSocketClient) AddMessageHandler(handleFunc MessageHandlerFunc, removeOnSuccess bool) (handlerKey string)
- func (c *KajiwotoWebSocketClient) BuildLocalUserTime() int
- func (c *KajiwotoWebSocketClient) Connect() error
- func (c *KajiwotoWebSocketClient) Disconnect() error
- func (c *KajiwotoWebSocketClient) GetMessageAuthorization() KajiwotoRPCAuthorization
- func (c *KajiwotoWebSocketClient) GetSocketId() string
- func (c *KajiwotoWebSocketClient) IsConnected() bool
- func (c *KajiwotoWebSocketClient) ReadMessage(ctx context.Context) (*KajiwotoWebSocketMessage, error)
- func (c *KajiwotoWebSocketClient) RemoveAllMessageHandlers()
- func (c *KajiwotoWebSocketClient) RemoveMessageHandler(handlerKey string)
- func (c *KajiwotoWebSocketClient) SendMessage(message *KajiwotoWebSocketMessage) error
- func (c *KajiwotoWebSocketClient) StartListeningToMessages()
- func (c *KajiwotoWebSocketClient) StopListeningToMessages()
- type KajiwotoWebSocketMessage
- type MessageHandler
- type MessageHandlerFunc
Constants ¶
const ( // Data Frames - see: https://www.rfc-editor.org/rfc/rfc6455#section-5.6 DataFrameText = "1" DataFrameBinary = "2" // WS Codes - see: https://stackoverflow.com/questions/24564877/what-do-these-numbers-mean-in-socket-io-payload // Basic codes SocketCodeOpen = "0" SocketCodeClose = "1" SocketCodePing = "2" SocketCodePong = "3" // Complex Codes SocketCodeMessageConnect = "40" SocketCodeMessageDisconnect = "41" SocketCodeMessageEvent = "42" SocketCodeMessageAck = "43" SocketCodeMessageError = "44" // RPC Message Types RPCMessageChatActivity = "chatActivity" RPCMessageChatEnter = "chatEnter" RPCMessageChatLeave = "chatLeave" RPCMessageChatScene = "chatScene" RPCMessageChatMessage = "chatMessage" RPCMessageChatRespond = "chatRespond" RPCMessageLiveSub = "liveSub" RPCMessageLogin = "login" RPCMessageSubscribe = "subscribe" RPCMessageUserStatus = "userStatus" RPCMessageTyping = "typing" // RPC Message Subtypes ChatActivitySubActivity = "activity" ChatActivityMessage = "message" ChatActivityMessageConfirm = "messageConfirm" ChatActivityPetMessage = "petMessage" ChatActivityJoinRoom = "join-room" )
Variables ¶
var (
ErrUnableToHandleMessage = errors.New("unable to handle message")
)
Functions ¶
This section is empty.
Types ¶
type KaiwotoRPCBaseMessage ¶
type KaiwotoRPCBaseMessage struct { Action string Payload []interface{} }
func (*KaiwotoRPCBaseMessage) Deserialize ¶
func (k *KaiwotoRPCBaseMessage) Deserialize(messageData interface{}) error
func (*KaiwotoRPCBaseMessage) DeserializeFromBytes ¶
func (k *KaiwotoRPCBaseMessage) DeserializeFromBytes(messageBytes []byte) ([]interface{}, error)
func (*KaiwotoRPCBaseMessage) FetchDataFromPayload ¶
func (k *KaiwotoRPCBaseMessage) FetchDataFromPayload(output interface{}, ignoreUnset bool) bool
func (*KaiwotoRPCBaseMessage) Serialize ¶
func (k *KaiwotoRPCBaseMessage) Serialize() []interface{}
type KaiwotoWebSocketAuthRequest ¶
type KaiwotoWebSocketAuthRequest struct {
ApiKey string `json:"api_key"`
}
WebSocket Message Content types
type KajiwotoRPCAuthorization ¶ added in v0.1.1
type KajiwotoRPCChatActivity ¶
type KajiwotoRPCChatActivity struct { Action string `json:"action"` ChatRoomId string `json:"chatRoomId"` EventType *string `json:"eventType,omitempty"` Message *KajiwotoRPCChatActivitySubMessage `json:"message,omitempty"` Activity *KajiwotoRPCChatActivitySubActivity `json:"activity,omitempty"` PetData *KajiwotoRPCChatActivityPetData `json:"petData,omitempty"` Channel *KajiwotoRPCChatActivityChannel `json:"channel,omitempty"` Interaction *KajiwotoRPCChatActivityInteraction `json:"interaction,omitempty"` SocketIds []string `json:"socketIds,omitempty"` }
type KajiwotoRPCChatActivityChannel ¶
type KajiwotoRPCChatActivityChannel struct { V uint64 `json:"v"` // Channel version List []KajiwotoRPCChatActivityChannelUser `json:"list,omitempty"` // Channel user list }
type KajiwotoRPCChatActivityData ¶
type KajiwotoRPCChatActivityData struct {
Data KajiwotoRPCChatActivity `json:"data"`
}
type KajiwotoRPCChatActivityMessage ¶
type KajiwotoRPCChatActivityMessage struct {
ActivityData KajiwotoRPCChatActivityData
}
func (*KajiwotoRPCChatActivityMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCChatActivityMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCChatActivityMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCChatActivityMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCChatActivityPetData ¶
type KajiwotoRPCChatActivityPetData struct { Id string `json:"id"` ChatRoomId string `json:"chatRoomId"` PetSpeciesId string `json:"petSpeciesId"` KajiId string `json:"kajiId"` OwnerId string `json:"ownerId"` OwnerDisplayName string `json:"ownerDisplayName"` OwnerProfilePhotoUri *string `json:"ownerProfilePhotoUri"` Name string `json:"name"` KajiName string `json:"kajiName"` Gender string `json:"gender"` Persona string `json:"persona"` Stage *string `json:"stage"` State string `json:"state"` Mood string `json:"mood"` StatusPhotoUri *string `json:"statusPhotoUri"` DominantColors []string `json:"dominantColors"` StatusMessage string `json:"statusMessage"` }
type KajiwotoRPCChatActivitySubMessage ¶
type KajiwotoRPCChatActivitySubMessage struct { ClientId string `json:"clientId,omitempty"` ChatRoomId string `json:"chatRoomId"` KajiwotoPetId string `json:"kajiwotoPetId,omitempty"` Message string `json:"message"` AttachmentUri *string `json:"attachmentUri"` Id string `json:"id"` UserId string `json:"userId,omitempty"` UserName string `json:"username,omitempty"` DisplayName string `json:"displayName,omitempty"` ProfilePhotoUri *string `json:"profilePhotoUri,omitempty"` CreatedAt uint64 `json:"createdAt"` }
type KajiwotoRPCChatEnterMessage ¶
type KajiwotoRPCChatEnterMessage struct { UserData KajiwotoRPCUserData ChatroomData KajiwotoRPCChatRoomData Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCChatEnterMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCChatEnterMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCChatEnterMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCChatEnterMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCChatLeaveMessage ¶
type KajiwotoRPCChatLeaveMessage struct { Field1 KajiwotoRPCEmptyObject ChatRoom KajiwotoRPCChatRoomId Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCChatLeaveMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCChatLeaveMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCChatLeaveMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCChatLeaveMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCChatMessage ¶
type KajiwotoRPCChatMessageCreate ¶
type KajiwotoRPCChatMessageCreate struct { IsLive bool `json:"isLive""` Message KajiwotoRPCChatMessageCreateData `json:"message"` Platform string `json:"platform"` Role KajiwotoRPCChatUserRole `json:"role"` RoomVersionNumber int64 `json:"roomVersionNumber"` RoomSocketIds []string `json:"roomSocketIds,omitempty"` }
type KajiwotoRPCChatRespondData ¶ added in v0.1.1
type KajiwotoRPCChatRespondMessage ¶ added in v0.1.1
type KajiwotoRPCChatRespondMessage struct { UserData KajiwotoRPCUserData ChatRespondData KajiwotoRPCChatRespondData Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCChatRespondMessage) FromRPCBaseMessage ¶ added in v0.1.1
func (k *KajiwotoRPCChatRespondMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCChatRespondMessage) ToRPCBaseMessage ¶ added in v0.1.1
func (k *KajiwotoRPCChatRespondMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCChatRoomData ¶
type KajiwotoRPCChatRoomData struct { ChatRoomId string `json:"chatRoomId"` LastMessages []KajiwotoRPCChatMessage `json:"lastMessages"` IsPreviewRoom bool `json:"isPreviewRoom"` }
type KajiwotoRPCChatRoomId ¶
type KajiwotoRPCChatRoomId struct {
ChatRoomId string `json:"chatRoomId"`
}
type KajiwotoRPCChatSendMessage ¶
type KajiwotoRPCChatSendMessage struct { UserData KajiwotoRPCUserData ChatMessageData KajiwotoRPCChatMessageCreate Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCChatSendMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCChatSendMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCChatSendMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCChatSendMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCChatUserRole ¶ added in v0.1.1
type KajiwotoRPCEmptyObject ¶
type KajiwotoRPCEmptyObject struct { }
type KajiwotoRPCLiveSubMessage ¶
type KajiwotoRPCLiveSubMessage struct { Field1 KajiwotoRPCEmptyObject // No idea what these do yet, but they're always empty on initial call Field2 KajiwotoRPCEmptyObject // No idea what these do yet, but they're always empty on initial call Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCLiveSubMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCLiveSubMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCLiveSubMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCLiveSubMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCLoginMessage ¶
type KajiwotoRPCLoginMessage struct { UserData KajiwotoRPCUserData UserStatus KajiwotoRPCUserStatus Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCLoginMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCLoginMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCLoginMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCLoginMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCMessage ¶
type KajiwotoRPCMessage interface { ToRPCBaseMessage() *KaiwotoRPCBaseMessage FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool }
Basic RPC message handling types
type KajiwotoRPCSubscribeMessage ¶
type KajiwotoRPCSubscribeMessage struct { UserData KajiwotoRPCUserData SubscribeArgs KajiwotoRPCSubscribeArgs Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCSubscribeMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCSubscribeMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCSubscribeMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCSubscribeMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCTypingMessage ¶
type KajiwotoRPCTypingMessage struct { UserData KajiwotoRPCUserData ChatRoomId KajiwotoRPCChatRoomId Authorization KajiwotoRPCAuthorization }
RPC Message Types
func (*KajiwotoRPCTypingMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCTypingMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCTypingMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCTypingMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCUserData ¶
type KajiwotoRPCUserData struct { DisplayName string `json:"displayName"` Guest bool `json:"guest"` ProfilePhotoUri *string `json:"profilePhotoUri"` Time int `json:"time"` UserID string `json:"userId"` Username string `json:"username"` }
RPC Message Content types
type KajiwotoRPCUserStatus ¶
type KajiwotoRPCUserStatusClientMessage ¶
type KajiwotoRPCUserStatusClientMessage struct { UserData KajiwotoRPCUserData UserStatus KajiwotoRPCUserStatus Authorization KajiwotoRPCAuthorization }
func (*KajiwotoRPCUserStatusClientMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCUserStatusClientMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCUserStatusClientMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCUserStatusClientMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoRPCUserStatusData ¶
type KajiwotoRPCUserStatusData struct {
Data KajiwotoRPCStatusUserData `json:"data"`
}
type KajiwotoRPCUserStatusServerMessage ¶
type KajiwotoRPCUserStatusServerMessage struct {
StatusData KajiwotoRPCUserStatusData
}
func (*KajiwotoRPCUserStatusServerMessage) FromRPCBaseMessage ¶
func (k *KajiwotoRPCUserStatusServerMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool
func (*KajiwotoRPCUserStatusServerMessage) ToRPCBaseMessage ¶
func (k *KajiwotoRPCUserStatusServerMessage) ToRPCBaseMessage() *KaiwotoRPCBaseMessage
type KajiwotoWebSocketClient ¶
type KajiwotoWebSocketClient struct {
// contains filtered or unexported fields
}
KajiwotoWebSocketClient is a custom websocket client for kajiwoto reqeusts using the websocket API
func NewKajiwotoWebSocketClient ¶ added in v0.1.1
func NewKajiwotoWebSocketClient(endpoint, apiKey, authId, authToken string) *KajiwotoWebSocketClient
func (*KajiwotoWebSocketClient) AddDefaultHandlers ¶
func (c *KajiwotoWebSocketClient) AddDefaultHandlers()
AddDefaultHandlers ensures all basic handlers required to operate the WebSocket Client long term are set up and added to the client.
func (*KajiwotoWebSocketClient) AddMessageHandler ¶
func (c *KajiwotoWebSocketClient) AddMessageHandler(handleFunc MessageHandlerFunc, removeOnSuccess bool) (handlerKey string)
func (*KajiwotoWebSocketClient) BuildLocalUserTime ¶
func (c *KajiwotoWebSocketClient) BuildLocalUserTime() int
BuildLocalUserTime is sent whenever the backend needs to know the current time at the location of the user
func (*KajiwotoWebSocketClient) Connect ¶
func (c *KajiwotoWebSocketClient) Connect() error
func (*KajiwotoWebSocketClient) Disconnect ¶ added in v0.1.2
func (c *KajiwotoWebSocketClient) Disconnect() error
func (*KajiwotoWebSocketClient) GetMessageAuthorization ¶ added in v0.1.1
func (c *KajiwotoWebSocketClient) GetMessageAuthorization() KajiwotoRPCAuthorization
func (*KajiwotoWebSocketClient) GetSocketId ¶
func (c *KajiwotoWebSocketClient) GetSocketId() string
func (*KajiwotoWebSocketClient) IsConnected ¶
func (c *KajiwotoWebSocketClient) IsConnected() bool
func (*KajiwotoWebSocketClient) ReadMessage ¶
func (c *KajiwotoWebSocketClient) ReadMessage(ctx context.Context) (*KajiwotoWebSocketMessage, error)
func (*KajiwotoWebSocketClient) RemoveAllMessageHandlers ¶
func (c *KajiwotoWebSocketClient) RemoveAllMessageHandlers()
func (*KajiwotoWebSocketClient) RemoveMessageHandler ¶
func (c *KajiwotoWebSocketClient) RemoveMessageHandler(handlerKey string)
func (*KajiwotoWebSocketClient) SendMessage ¶
func (c *KajiwotoWebSocketClient) SendMessage(message *KajiwotoWebSocketMessage) error
func (*KajiwotoWebSocketClient) StartListeningToMessages ¶
func (c *KajiwotoWebSocketClient) StartListeningToMessages()
func (*KajiwotoWebSocketClient) StopListeningToMessages ¶
func (c *KajiwotoWebSocketClient) StopListeningToMessages()
type KajiwotoWebSocketMessage ¶
type KajiwotoWebSocketMessage struct { MessageCode string MessageContent interface{} }
Basic WebSocket Message Handling types
func CreateKajiwotoWebSocketEventMessage ¶
func CreateKajiwotoWebSocketEventMessage(rpcMessage KajiwotoRPCMessage) *KajiwotoWebSocketMessage
func (*KajiwotoWebSocketMessage) FromBytes ¶
func (k *KajiwotoWebSocketMessage) FromBytes(bytes []byte) error
func (*KajiwotoWebSocketMessage) ToBytes ¶
func (k *KajiwotoWebSocketMessage) ToBytes() ([]byte, error)
type MessageHandler ¶
type MessageHandler struct {
// contains filtered or unexported fields
}
MessageHandler is used to bind handler functions to the websocket client
type MessageHandlerFunc ¶
type MessageHandlerFunc func(message *KajiwotoWebSocketMessage) error
MessageHandlerFunc describes a function interface to be bound to the websocket client
func NewKajiwotoWebSocketAuthResponseHandler ¶
func NewKajiwotoWebSocketAuthResponseHandler(c *KajiwotoWebSocketClient, responseChannel chan *KaiwotoWebSocketAuthResponse) MessageHandlerFunc
NewKajiwotoWebSocketAuthResponseHandler is used to handle an auth message response
func NewKajiwotoWebSocketPingHandler ¶
func NewKajiwotoWebSocketPingHandler(c *KajiwotoWebSocketClient) MessageHandlerFunc
NewKajiwotoWebSocketPingHandler is used to handle a ping event from the backend