websocket

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

View Source
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 KaiwotoWebSocketAuthResponse

type KaiwotoWebSocketAuthResponse struct {
	Sid     string `json:"sid,omitempty"`
	Message string `json:"message,omitempty"`
}

type KajiwotoRPCAuthorization added in v0.1.1

type KajiwotoRPCAuthorization struct {
	AuthId    string `json:"auth_id"`
	AuthToken string `json:"auth_token"`
}

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 KajiwotoRPCChatActivityChannelUser

type KajiwotoRPCChatActivityChannelUser struct {
	Id              string   `json:"id"`
	GuestId         string   `json:"guestId"`
	SocketIds       []string `json:"socketIds"`
	Guest           bool     `json:"guest"`
	DisplayName     string   `json:"displayName"`
	Username        string   `json:"username"`
	ProfilePhotoUri *string  `json:"profilePhotoUri"`
}

type KajiwotoRPCChatActivityData

type KajiwotoRPCChatActivityData struct {
	Data KajiwotoRPCChatActivity `json:"data"`
}

type KajiwotoRPCChatActivityInteraction

type KajiwotoRPCChatActivityInteraction struct {
	AFK       bool   `json:"afk"`
	Narration string `json:"narration"`
	ShowScene bool   `json:"showScene"`
	Type      string `json:"type"`
}

type KajiwotoRPCChatActivityMessage

type KajiwotoRPCChatActivityMessage struct {
	ActivityData KajiwotoRPCChatActivityData
}

func (*KajiwotoRPCChatActivityMessage) FromRPCBaseMessage

func (k *KajiwotoRPCChatActivityMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool

func (*KajiwotoRPCChatActivityMessage) ToRPCBaseMessage

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 KajiwotoRPCChatActivitySubActivity

type KajiwotoRPCChatActivitySubActivity struct {
	Type        string `json:"type"`
	UserId      string `json:"userId"`
	DisplayName string `json:"displayName"`
	ActivityAt  uint64 `json:"activityAt"`
}

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 KajiwotoRPCChatMessage struct {
	CreatedAt uint64 `json:"createdAt"`
	Message   string `json:"message"`
}

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 KajiwotoRPCChatMessageCreateData

type KajiwotoRPCChatMessageCreateData struct {
	Id            string  `json:"id"`
	ChatRoomId    string  `json:"chatRoomId"`
	HumanChat     bool    `json:"humanChat"`
	UserID        string  `json:"userId"`
	Message       string  `json:"message"`
	AttachmentUri *string `json:"attachmentUri"`
}

type KajiwotoRPCChatRespondData added in v0.1.1

type KajiwotoRPCChatRespondData struct {
	ChatRoomId  string `json:"chatRoomId"`
	MentionedAI bool   `json:"mentionedAI"`
	Message     string `json:"message"`
	Platform    string `json:"platform"`
}

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

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 KajiwotoRPCChatUserRole struct {
	Creator   bool `json:"creator"`
	Guest     bool `json:"guest"`
	Host      bool `json:"host"`
	Moderator bool `json:"moderator"`
	Owner     bool `json:"owner"`
}

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 KajiwotoRPCStatusUserData

type KajiwotoRPCStatusUserData struct {
	DisplayName     string  `json:"displayName"`
	Guest           bool    `json:"guest"`
	ProfilePhotoUri *string `json:"profilePhotoUri"`
	UserID          string  `json:"userId"`
	Username        string  `json:"username"`
	Status          string  `json:"status"`
}

type KajiwotoRPCSubscribeArgs

type KajiwotoRPCSubscribeArgs struct {
	ChatRoomIds []string `json:"chatRoomIds"`
	KajiId      *string  `json:"kajiId"`
}

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 KajiwotoRPCUserStatus struct {
	FriendIDs []string `json:"friendIds,omitempty"`
	Status    string   `json:"status"`
}

type KajiwotoRPCUserStatusClientMessage

type KajiwotoRPCUserStatusClientMessage struct {
	UserData      KajiwotoRPCUserData
	UserStatus    KajiwotoRPCUserStatus
	Authorization KajiwotoRPCAuthorization
}

func (*KajiwotoRPCUserStatusClientMessage) FromRPCBaseMessage

func (k *KajiwotoRPCUserStatusClientMessage) FromRPCBaseMessage(message *KaiwotoRPCBaseMessage) bool

func (*KajiwotoRPCUserStatusClientMessage) ToRPCBaseMessage

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

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 (*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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL