ClientDelegate
public protocol ClientDelegate : AnyObject
Protocol to be implemented to receive LightstreamerClient events comprehending notifications of connection activity and errors.
Events for these delegates are dispatched by a different thread than the one that generates them. This means that, upon reception of an event,
it is possible that the internal state of the client has changed. On the other hand, all the notifications for a single LightstreamerClient, including
notifications to LSClientDelegate, SubscriptionDelegate, ClientMessageDelegate, MPNDeviceDelegate and MPNSubscriptionDelegate, will be dispatched by the same thread.
-
Event handler that receives a notification when the LSClientDelegate instance is removed from a
LightstreamerClientthroughLightstreamerClient.removeDelegate(_:).This is the last event to be fired on the delegate.
Declaration
Swift
func clientDidRemoveDelegate(_ client: LightstreamerClient)Parameters
clientThe
LightstreamerClientthis instance was removed from. -
Event handler that receives a notification when the LSClientDelegate instance is added to a
LightstreamerClientthroughLightstreamerClient.addDelegate(_:).This is the first event to be fired on the delegate.
Declaration
Swift
func clientDidAddDelegate(_ client: LightstreamerClient)Parameters
clientThe
LightstreamerClientthis instance was added to. -
Event handler that is called when the Server notifies a refusal on the client attempt to open a new connection or the interruption of a streaming connection.
In both cases, the
client(_:didChangeStatus:)event handler has already been invoked with aDISCONNECTEDstatus and no recovery attempt has been performed. By setting a custom handler, however, it is possible to override this and perform custom recovery actions.The error code can be one of the following:
1 - user/password check failed
2 - requested Adapter Set not available
7 - licensed maximum number of sessions reached (this can only happen with some licenses)
8 - configured maximum number of sessions reached
9 - configured maximum server load reached
10 - new sessions temporarily blocked
11 - streaming is not available because of Server license restrictions (this can only happen with special licenses).
21 - a request for this session has unexpectedly reached a wrong Server instance, which suggests that a routing issue may be in place.
30-41 - the current connection or the whole session has been closed by external agents; the possible cause may be:
The session was closed on the Server side (via software or by the administrator) (32), or through a client “destroy” request (31);
The Metadata Adapter imposes limits on the overall open sessions for the current user and has requested the closure of the current session upon opening of a new session for the same user on a different browser window (35);
An unexpected error occurred on the Server while the session was in activity (33, 34);
An unknown or unexpected cause; any code different from the ones identified in the above cases could be issued. A detailed description for the specific cause is currently not supplied (i.e. errorMessage is nil in this case).
60 - this version of the client is not allowed by the current license terms.
61 - there was an error in the parsing of the server response thus the client cannot continue with the current session.
66 - an unexpected exception was thrown by the Metadata Adapter while authorizing the connection.
68 - the Server could not open or continue with the session because of an internal error.
71 - this kind of client is not allowed by the current license terms.
<=0 - the Metadata Adapter has refused the user connection; the code value is dependent on the specific Metadata Adapter implementation
See also
See also
Declaration
Swift
func client(_ client: LightstreamerClient, didReceiveServerError errorCode: Int, withMessage errorMessage: String)Parameters
clientThe
LightstreamerClientinstance.errorCodeThe error code.
errorMessageThe description of the error as sent by the Server.
-
Event handler that receives a notification each time the
LightstreamerClientstatus has changed.The status changes may be originated either by custom actions (e.g. by calling
LightstreamerClient.disconnect()) or by internal actions. The normal cases are the following:After issuing
LightstreamerClient.connect(), if the current status isDISCONNECTED*, the client will switch toCONNECTINGfirst and toCONNECTED:STREAM-SENSINGas soon as the pre-flight request receives its answer. As soon as the new session is established, it will switch toCONNECTED:WS-STREAMINGif the environment permits WebSockets; otherwise it will switch toCONNECTED:HTTP-STREAMINGif the environment permits streaming or toCONNECTED:HTTP-POLLINGas a last resort. On the other hand if the status is alreadyCONNECTED:*a switch toCONNECTINGis usually not needed.After issuing
LightstreamerClient.disconnect(), the status will switch toDISCONNECTED.In case of a server connection refusal, the status may switch from
CONNECTINGdirectly toDISCONNECTED. After that, theclient(_:didReceiveServerError:withMessage:)event handler will be invoked.
Possible special cases are the following:
In case of Server unavailability during streaming, the status may switch from
CONNECTED:*-STREAMINGtoSTALLED(seeConnectionOptions.stalledTimeout). If the unavailability ceases, the status will switch back toCONNECTED:*-STREAMING; otherwise, if the unavailability persists (seeConnectionOptions.reconnectTimeout), the status will switch toDISCONNECTED:TRYING-RECOVERYand eventually toCONNECTED:*-STREAMING.In case the connection or the whole session is forcibly closed by the Server, the status may switch from
CONNECTED:*-STREAMINGorCONNECTED:*-POLLINGdirectly toDISCONNECTED. After that, theclient(_:didReceiveServerError:withMessage:)event handler will be invoked.Depending on the setting in
ConnectionOptions.slowingEnabled, in case of slow update processing, the status may switch fromCONNECTED:WS-STREAMINGtoCONNECTED:WS-POLLINGor fromCONNECTED:HTTP-STREAMINGtoCONNECTED:HTTP-POLLING.If the status is
CONNECTED:*-POLLINGand any problem during an intermediate poll occurs, the status may switch toCONNECTINGand eventually toCONNECTED:*-POLLING. The same may hold for theCONNECTED:*-STREAMINGcase, when a rebind is needed.In case a forced transport was set through
ConnectionOptions.forcedTransport, only the related final status or statuses are possible.In case of connection problems, the status may switch from any value to
DISCONNECTED:WILL-RETRY(seeConnectionOptions.retryDelay), then toCONNECTINGand a new attempt will start. However, in most cases, the client will try to recover the current session; hence, theDISCONNECTED:TRYING-RECOVERYstatus will be entered and the recovery attempt will start.In case of connection problems during a recovery attempt, the status may stay in
DISCONNECTED:TRYING-RECOVERYfor long time, while further attempts are made. If the recovery is no longer possible, the current session will be abandoned and the status will switch toDISCONNECTED:WILL-RETRYbefore the next attempts.
By setting a custom handler it is possible to perform actions related to connection and disconnection occurrences. Note that
LightstreamerClient.connect()andLightstreamerClient.disconnect(), as any other method, can be issued directly from within a handler.The full list of possible new statuses is the following:
CONNECTINGthe client has started a connection attempt and is waiting for a Server answer.CONNECTED:STREAM-SENSINGthe client received a first response from the server and is now evaluating if a streaming connection is fully functional.CONNECTED:WS-STREAMINGa streaming connection over WebSocket has been established.CONNECTED:HTTP-STREAMINGa streaming connection over HTTP has been established.CONNECTED:WS-POLLINGa polling connection over WebSocket has been started. Note that, unlike polling over HTTP, in this case only one connection is actually opened (seeConnectionOptions.slowingEnabled).CONNECTED:HTTP-POLLINGa polling connection over HTTP has been started.STALLEDa streaming session has been silent for a while, the status will eventually return to its previousCONNECTED:*-STREAMINGstatus or will switch toDISCONNECTED:WILL-RETRY/DISCONNECTED:TRYING-RECOVERY.DISCONNECTED:WILL-RETRYa connection or connection attempt has been closed; a new attempt will be performed (possibly after a timeout).DISCONNECTED:TRYING-RECOVERYa connection has been closed and the client has started a connection attempt and is waiting for a Server answer; if successful, the underlying session will be kept.DISCONNECTEDa connection or connection attempt has been closed. The client will not connect anymore until a newLightstreamerClient.connect()call is issued.
Platform limitations: On watchOS the WebSocket transport is not available.
See also
See also
See also
Declaration
Swift
func client(_ client: LightstreamerClient, didChangeStatus status: LightstreamerClient.Status)Parameters
clientThe
LightstreamerClientinstance.statusThe new status.
-
Event handler that receives a notification each time the value of a property of
LightstreamerClient.connectionDetailsorLightstreamerClient.connectionOptionsis changed.Properties of these objects can be modified by direct calls to them or by server sent events. Possible property names are the following:
adapterSetserverAddressuserpasswordserverInstanceAddressserverSocketNameclientIpsessionIdcontentLengthidleTimeoutkeepaliveIntervalrequestedMaxBandwidthrealMaxBandwidthpollingIntervalreconnectTimeoutstalledTimeoutretryDelayfirstRetryMaxDelayslowingEnabledforcedTransportserverInstanceAddressIgnoredreverseHeartbeatIntervalearlyWSOpenEnabledHTTPExtraHeadersHTTPExtraHeadersOnSessionCreationOnly
Declaration
Swift
func client(_ client: LightstreamerClient, didChangeProperty property: String)Parameters
clientThe
LightstreamerClientinstance.propertyThe name of the changed property.
ClientDelegate Protocol Reference