Movatterモバイル変換


[0]ホーム

URL:


SocketIO 16.0.0 Docs (100% documented)

SocketIO Reference SocketIOClient Class Reference

SocketIOClient

openclassSocketIOClient:NSObject,SocketIOClientSpec

Represents a socket.io-client.

Clients are created through aSocketManager, which owns theSocketEngineSpec that controls the connection to the server.

For example:

// Create a socket for the /swift namespaceletsocket=manager.socket(forNamespace:"/swift")// Add some handlers and connect

NOTE: The client is not thread/queue safe, all interaction with the socket should be done on themanager.handleQueue

Properties

  • The namespace that this socket is currently connected to.

    Must start with a/.

    Declaration

    Swift

    publicletnsp:String
  • A handler that will be called on any event.

    Declaration

    Swift

    publicprivate(set)varanyHandler:((SocketAnyEvent)->())?{get}
  • The array of handlers for this socket.

    Declaration

    Swift

    publicprivate(set)varhandlers:[SocketEventHandler]{get}
  • The manager for this socket.

    Declaration

    Swift

    publicprivate(set)weakvarmanager:SocketManagerSpec?{get}
  • A view into this socket where emits do not check for binary data.

    Usage:

    socket.rawEmitView.emit("myEvent",myObject)

    NOTE: It is not safe to hold on to this view beyond the life of the socket.

    Declaration

    Swift

    publicprivate(set)lazyvarrawEmitView:SocketRawView{getset}
  • The status of this client.

    Declaration

    Swift

    publicprivate(set)varstatus:SocketIOStatus{getset}
  • The id of this socket.io connect. This is different from the sid of the engine.io connection.

    Declaration

    Swift

    publicprivate(set)varsid:String?{get}

Initializers

  • Type safe way to create a new SocketIOClient.opts can be omitted.

    Declaration

    Swift

    publicinit(manager:SocketManagerSpec,nsp:String)

    Parameters

    manager

    The manager for this socket.

    nsp

    The namespace of the socket.

Methods

  • Connect to the server. The same as callingconnect(timeoutAfter:withHandler:) with a timeout of 0.

    Only call after adding your event listeners, unless you know what you’re doing.

    Declaration

    Swift

    openfuncconnect(withPayloadpayload:[String:Any]?=nil)

    Parameters

    withPayload

    An optional payload sent on connect

  • Connect to the server. If we aren’t connected aftertimeoutAfter seconds, thenwithHandler is called.

    Only call after adding your event listeners, unless you know what you’re doing.

    Declaration

    Swift

    openfuncconnect(withPayloadpayload:[String:Any]?=nil,timeoutAfter:Double,withHandlerhandler:(()->())?)

    Parameters

    withPayload

    An optional payload sent on connect

    timeoutAfter

    The number of seconds after which if we are not connected we assume the connection has failed. Pass 0 to never timeout.

    handler

    The handler to call when the client fails to connect.

  • Called when the client connects to a namespace. If the client was created with a namespace upfront,then this is only called when the client connects to that namespace.

    Declaration

    Swift

    openfuncdidConnect(toNamespacenamespace:String,payload:[String:Any]?)

    Parameters

    toNamespace

    The namespace that was connected to.

  • Called when the client has disconnected from socket.io.

    Declaration

    Swift

    openfuncdidDisconnect(reason:String)

    Parameters

    reason

    The reason for the disconnection.

  • Disconnects the socket.

    This will cause the socket to leave the namespace it is associated to, as well as remove itself from themanager.

    Declaration

    Swift

    openfuncdisconnect()
  • Send an event to the server, with optional data items and optional write completion handler.

    If an error occurs trying to transformitems into their socket representation, aSocketClientEvent.errorwill be emitted. The structure of the error data is[eventName, items, theError]

    Declaration

    Swift

    openfuncemit(_event:String,_items:SocketData...,completion:(()->())?=nil)

    Parameters

    event

    The event to send.

    items

    The items to send with this event. May be left out.

    completion

    Callback called on transport write completion.

  • Sends a message to the server, requesting an ack.

    NOTE: It is up to the server send an ack back, just calling this method does not mean the server will ack.Check that your server’s api will ack the event being sent.

    If an error occurs trying to transformitems into their socket representation, aSocketClientEvent.errorwill be emitted. The structure of the error data is[eventName, items, theError]

    Example:

    socket.emitWithAck("myEvent",1).timingOut(after:1){datain...}

    Declaration

    Swift

    openfuncemitWithAck(_event:String,_items:SocketData...)->OnAckCallback

    Parameters

    event

    The event to send.

    items

    The items to send with this event. May be left out.

    Return Value

    AnOnAckCallback. You must call thetimingOut(after:) method before the event will be sent.

  • Call when you wish to tell the server that you’ve received the event forack.

    You shouldn’t need to call this directly. Instead use anSocketAckEmitter that comes in an event callback.

    Declaration

    Swift

    openfuncemitAck(_ack:Int,withitems:[Any])

    Parameters

    ack

    The ack number.

    with

    The data for this ack.

  • Called when socket.io has acked one of our emits. Causes the corresponding ack callback to be called.

    Declaration

    Swift

    openfunchandleAck(_ack:Int,data:[Any])

    Parameters

    ack

    The number for this ack.

    data

    The data sent back with this ack.

  • Called on socket.io specific events.

    Declaration

    Swift

    openfunchandleClientEvent(_event:SocketClientEvent,data:[Any])

    Parameters

    event
    data

    The data for this event.

  • Called when we get an event from socket.io.

    Declaration

    Swift

    openfunchandleEvent(_event:String,data:[Any],isInternalMessage:Bool,withAckack:Int=-1)

    Parameters

    event

    The name of the event.

    data

    The data that was sent with this event.

    isInternalMessage

    Whether this event was sent internally. Iftrue it is always sent to handlers.

    ack

    If > 0 then this event expects to get an ack back from the client.

  • Causes a client to handle a socket.io packet. The namespace for the packet must match the namespace of thesocket.

    Declaration

    Swift

    openfunchandlePacket(_packet:SocketPacket)

    Parameters

    packet

    The packet to handle.

  • Call when you wish to leave a namespace and disconnect this socket.

    Declaration

    Swift

    openfuncleaveNamespace()
  • Joinsnsp. You shouldn’t need to call this directly, instead callconnect.

    Declaration

    Swift

    openfuncjoinNamespace(withPayloadpayload:[String:Any]?=nil)

    Parameters

    withPayload

    An optional payload sent on connect

  • Removes handler(s) for a client event.

    If you wish to remove a client event handler, call theoff(id:) with the UUID received from itson call.

    Declaration

    Swift

    openfuncoff(clientEventevent:SocketClientEvent)

    Parameters

    clientEvent

    The event to remove handlers for.

  • Removes handler(s) based on an event name.

    If you wish to remove a specific event, call theoff(id:) with the UUID received from itson call.

    Declaration

    Swift

    openfuncoff(_event:String)

    Parameters

    event

    The event to remove handlers for.

  • Removes a handler with the specified UUID gotten from anon oronce

    If you want to remove all events for an event, call the offoff(_:) method with the event name.

    Declaration

    Swift

    openfuncoff(id:UUID)

    Parameters

    id

    The UUID of the handler you wish to remove.

  • Adds a handler for an event.

    Declaration

    Swift

    @discardableResultopenfuncon(_event:String,callback:@escapingNormalCallback)->UUID

    Parameters

    event

    The event name for this handler.

    callback

    The callback that will execute when this event is received.

    Return Value

    A unique id for the handler that can be used to remove it.

  • Adds a handler for a client event.

    Example:

    socket.on(clientEvent:.connect){data,ackin...}

    Declaration

    Swift

    @discardableResultopenfuncon(clientEventevent:SocketClientEvent,callback:@escapingNormalCallback)->UUID

    Parameters

    event

    The event for this handler.

    callback

    The callback that will execute when this event is received.

    Return Value

    A unique id for the handler that can be used to remove it.

  • Adds a single-use handler for a client event.

    Declaration

    Swift

    @discardableResultopenfunconce(clientEventevent:SocketClientEvent,callback:@escapingNormalCallback)->UUID

    Parameters

    clientEvent

    The event for this handler.

    callback

    The callback that will execute when this event is received.

    Return Value

    A unique id for the handler that can be used to remove it.

  • Adds a single-use handler for an event.

    Declaration

    Swift

    @discardableResultopenfunconce(_event:String,callback:@escapingNormalCallback)->UUID

    Parameters

    event

    The event name for this handler.

    callback

    The callback that will execute when this event is received.

    Return Value

    A unique id for the handler that can be used to remove it.

  • Adds a handler that will be called on every event.

    Declaration

    Swift

    openfunconAny(_handler:@escaping(SocketAnyEvent)->())

    Parameters

    handler

    The callback that will execute whenever an event is received.

  • Removes all handlers.

    Can be used after disconnecting to break any potential remaining retain cycles.

    Declaration

    Swift

    openfuncremoveAllHandlers()
  • Puts the socket back into the connecting state.Called when the manager detects a broken connection, or when a manual reconnect is triggered.

    Declaration

    Swift

    openfuncsetReconnecting(reason:String)

    Parameters

    reason

    The reason this socket is reconnecting.

© 2021Erik. All rights reserved. (Last updated: 2021-02-01)

Generated byjazzy ♪♫ v0.13.6, aRealm project.


[8]ページ先頭

©2009-2025 Movatter.jp