Download the PHP package spiral/websocket-client without Composer

On this page you can find all versions of the php package spiral/websocket-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package websocket-client

Spiral Framework WebSocket

JavaScript WebSockets client library with channel support.

Since RoadRunner 2.x, the communication protocol has been changed. Below is a table of version compatibility.

RoadRunner spiralscout/websockets
1.0+ 0.0.1+
2.3+ 0.1.0+

Installation

SFSocket available for installing with npm or yarn

Next use it like so

Or via bundle file

If you prefer CDN usage, use following URL for most recent version

API

SFSocket proposes easy way to use WebSockets:

SFSocket

SFSocket
Properties
static instances SFSocket[]
Array of all existing sockets
static isReady boolean
false before ready() is called. If is true any new SFSocket will connect upon creation.
Methods
static ready() Marks sockets as ready and launches all connections.
Use if you need to make all sockets to connect automatically on creation
constructor(options: ISFSocketConfig) Create websocket connection
options: ISFSocketConfig - connection options
joinChannel(channel, dontJoin) Creates a named channel and joins it
channel: string name of channel to join. Should NOT be one of system ones: @join, #join, @leave, #leave
dontJoin: boolean default false if true, channel is created, registered inside instance but not joined automatically. Call join method to join later.
return value: Channel returns channel object
getChannel(channel) Gets a previously created named channel
return value: Channel returns channel object
leaveChannel(channel) Removes a named channel and leaves it
channel: string name of channel to join. Should NOT be one of system ones @join, #join, @leave, #leave
return value: Channel returns channel object
subscribe(event, callback, channel) Subscribes to specific event
event: string one of valid event codes. See table below for possible events and their payload
callback: (payload) => void callback to call. Type of payload depends on event type
channel: string (optional) Channel name to follow. If none, subscribes for all. Note that doesn't automatically join channel, just adds listener to existing one.
unsubscribe(event, callback, channel) Unsubscribes from specific event
event: string one of valid event codes. See table below for possible events and their payload
callback: (payload) => void callback to call. Type of payload depends on event type
channel: string (optional) Channel name to unfollow. If none, unsubscribes from all channels. Note that doesn't automatically remove channel, just removes listener from existing one.

SFSocket constructor options

SFSocket supports standard (ws) and secure (wss) protocols.

SFSocket constructor new SFSocket(options: ISFSocketConfig) is expecting options of type ISFSocketConfig

ISFSocketConfig
host string
Host websocket should connect to
port string or number
(optional) Port websocket should connect to
Default: 80 or 443 if useTSL = true
useTSL boolean
(optional) Use TSL wss instead of regular ws protocol
Default: false
path string
(optional) Server path part
Default: empty
queryParams object of {[key: string]: string} type
(optional) Query params map to append to path
Default: empty
unavailableTimeout number
(optional) A timeout which is considered to be large enough to stop retrying reconnects if server response takes longer
Default: 10000

For example to establish connection to ws://some.domain.com/foo?bar=1 use following code

SFSocket channels

Channel
Properties
status string Channel status, can be closed, joinin, joined, leaving or error
name string Channel name
Methods
constructor(name: string, socket: SFSocket) Creates a channel based on specific SFSocket
name: string - channel name. Can NOT be @join, #join, @leave, #leave
join() Enables channel and sends join command once connection is working
leave() Disables channel and sends leave command if connection is working
subscribe(event, callback) Subscribes to specific event
event: string one of valid event codes. See table below for possible events and their payload
callback: (payload) => void callback to call. Type of payload depends on event type
unsubscribe(event, callback) Unsubscribes from specific event
event: string one of valid event codes. See table below for possible events and their payload
callback: (payload) => void callback to call. Type of payload depends on event type
connect() Starts connection. This method is automatically called after SFSocket.ready() for all existing and new instances
disconnect() Drops connection

Supported events

SFSocket and Channel make it possible to subscribe to connected, message, closed and error events

SFSocket additionally allows to subscribe to channel_joined, channel_join_failed and channel_left events

Events
message ISFSocketEvent
Generic event of message from specific channel or broadcasted Payload depends on channel server implementation
error ISFSocketEvent
Event of error happened in specific channel or broadcasted Payload would contain error details
closed ISFSocketEvent
Connection was closed due some error. Socket might automatically reconnect after that.
channel_joined string[]
Indicates server confirming joining specific channels
channel_left string[]
Indicates server confirming leaving specific channels
channel_join_failed string[]
Indicates server denies joining specific channels

ISFSocketEvent structure

ISFSocketEvent
type string
sfSocket:message, sfSocket:closed or sfSocket:error depending on event tracked.
data any
Any serializable payload depending on implementation that refers to successful flow
error string
Error message
context object
Object with event context details
context.code number
Error code if relevant
context.channel string
Channel name if relevant
Message Event
Error Event

Samples

Working with events

Multiple channels creation

Custom commands

Sending custom commands is supported via sendCommand method. join and leave commands can NOT be used as command name, payload can be any serializable data.

`

Development

Prerequisites
Windows

On windows execute git config core.autocrlf false to disable automatic line ending conversion.


All versions of websocket-client with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spiral/websocket-client contains the following files

Loading the files please wait ....