phxgoclient

package module
v0.0.0-...-f6a90ee Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 10 Imported by: 0

README

phxgoclient

Pheonix Websocket Client in Go

Implementation of Websocket Clients And Pheonix Channels.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	State State
	Topic string

	InitialPayload interface{}

	Client Client

	RefCount int64

	Events     map[Event]ChannelCallbackFunc
	DataBuffer map[string]interface{}
}

func (*Channel) CanPush

func (channel *Channel) CanPush() bool

func (*Channel) ChannelLeave

func (channel *Channel) ChannelLeave() error

func (*Channel) ForceReconnect

func (channel *Channel) ForceReconnect() error

func (*Channel) IsOpen

func (channel *Channel) IsOpen() bool

func (*Channel) Join

func (channel *Channel) Join(payload interface{}) *Channel

func (*Channel) Leave

func (channel *Channel) Leave()

func (*Channel) Observe

func (channel *Channel) Observe() (data interface{}, err error)

Observes all registered events on a channel

func (*Channel) Push

func (channel *Channel) Push(event string, payload interface{}) error

Push event with payload to channel

func (*Channel) RawPush

func (channel *Channel) RawPush(event string, payload interface{})

RawPush, unsafe push that does not check if you can push on a channel

func (*Channel) Read

func (channel *Channel) Read() MessageResponse

func (*Channel) Reconnect

func (channel *Channel) Reconnect()

func (*Channel) Register

func (channel *Channel) Register(event Event, callback ChannelCallbackFunc) error

func (*Channel) UnRegister

func (channel *Channel) UnRegister(event Event) error

type ChannelCallbackFunc

type ChannelCallbackFunc func(response MessageResponse) (data interface{}, err error)

type Client

type Client struct {
	Url    url.URL
	Socket *websocket.Conn
}

func Connect

func Connect(url url.URL) (*Client, error)

func (*Client) Close

func (client *Client) Close() error

func (Client) MakeAndJoinAChannel

func (client Client) MakeAndJoinAChannel(topic string, payload interface{}) Channel

func (Client) MakeChannel

func (client Client) MakeChannel(topic string) Channel

type Event

type Event string
const (
	// MessageEvent represents a regular message on a topic.
	MessageEvent Event = "phx_message"
	// JoinEvent represents a successful join on a channel.
	JoinEvent Event = "phx_join"
	// CloseEvent represents the closing of a channel.
	CloseEvent Event = "phx_close"
	// ErrorEvent represents an error.
	ErrorEvent Event = "phx_error"
	// ReplyEvent represents a reply to a message sent on a topic.
	ReplyEvent Event = "phx_reply"
	// LeaveEvent represents leaving a channel and unsubscribing from a topic.
	LeaveEvent Event = "phx_leave"
)

func ToEvent

func ToEvent(str string) Event

func (Event) EventToString

func (event Event) EventToString() string

type ExecutionAction

type ExecutionAction func()

type Message

type Message struct {
	Topic   string      `json:"topic"`
	Event   string      `json:"event"`
	Payload interface{} `json:"payload"`
	Ref     int64       `json:"ref"`
}

type MessageResponse

type MessageResponse struct {
	Topic   string  `json:"topic"`
	Ref     int     `json:"ref"`
	Payload Payload `json:"payload"`
	Event   string  `json:"event"`
}

type Payload

type Payload struct {
	Status   string      `json:"status"`
	Response interface{} `json:"response"`
}

type PheonixGoSocket

type PheonixGoSocket struct {
	Host   string
	Schema string
	Path   string

	Status PhxGoSocketStatus

	Timeout time.Duration

	CustomAbsoultePath bool

	Transport Transport

	HeartbeatWorker *Worker

	Channels map[string]*Channel
}

func NewPheonixWebsocket

func NewPheonixWebsocket(Host string, Path string, Schema string, CustomAbsoultePath bool) PheonixGoSocket

Creates New Pheonix Websocket connection

func (*PheonixGoSocket) CloseChannel

func (phx *PheonixGoSocket) CloseChannel(topic string) error

func (*PheonixGoSocket) ClosePheonixWebsocket

func (phx *PheonixGoSocket) ClosePheonixWebsocket()

func (*PheonixGoSocket) GetChannel

func (phx *PheonixGoSocket) GetChannel(topic string) (*Channel, error)

Raw access for a channel

func (*PheonixGoSocket) JoinChannel

func (phx *PheonixGoSocket) JoinChannel(topic string, payload interface{}) error

func (PheonixGoSocket) Listen

func (phx PheonixGoSocket) Listen() error

Starts the Pheonix Websocket

func (*PheonixGoSocket) OpenChannel

func (phx *PheonixGoSocket) OpenChannel(topic string) (*Channel, error)

func (*PheonixGoSocket) SetCustomTimeout

func (phx *PheonixGoSocket) SetCustomTimeout(interval time.Duration)

Set your timeout intervel and heartbeat interval in format (interval * Duration) e.g (30 * time.Seconds)

type PhxGoSocketStatus

type PhxGoSocketStatus string
const (
	PhxGoOpen   PhxGoSocketStatus = "open"
	PhxGoError  PhxGoSocketStatus = "error"
	PhxGoClosed PhxGoSocketStatus = "closed"
)

type State

type State string
const (
	ClosedState  State = "closed"
	ErroredState State = "errored"
	JoinedState  State = "joined"
	JoiningState State = "joining"
	LeavingState State = "leaving"
)

func (State) StateToString

func (state State) StateToString() string

type Status

type Status string
const (
	OkStatus      Status = "ok"
	ErrorStatus   Status = "error"
	TimeoutStatus Status = "timeout"
)

func (Status) StatusToString

func (status Status) StatusToString() string

type Transport

type Transport string
const (
	PhxSocket   Transport = "/websocket"
	PhxLongPool Transport = "/longpoll"
)

func (Transport) ToPath

func (transport Transport) ToPath() string

type Worker

type Worker struct {
	Stopped         bool          // A flag determining the state of the worker
	ShutdownChannel chan string   // A channel to communicate to the routine
	Interval        time.Duration // The interval with which to run the Action
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(interval time.Duration, action ExecutionAction) *Worker

func (*Worker) Action

func (w *Worker) Action(action ExecutionAction)

func (*Worker) Run

func (w *Worker) Run()

Run starts the worker and listens for a shutdown call.

func (*Worker) Shutdown

func (w *Worker) Shutdown()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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