Class SocketIOEvent
- Namespace
- Firesplash.GameDevAssets.SocketIOPlus
- Assembly
- Firesplash.GameDevAssets.SocketIOPlus.dll
public class SocketIOEvent
- Inheritance
-
SocketIOEvent
- Derived
Fields
Namespace
Contians a reference to the SocketIONamespace this packet was received on. It is null on Packets generated locally for sending.
public SocketIONamespace Namespace
Field Value
eventName
The event name, this event was received under
public string eventName
Field Value
Properties
Length
Returns the number of payloads in this packet. Only valid for messages.
public int Length { get; }
Property Value
acknowledgementID
public int acknowledgementID { get; }
Property Value
callback
If this is an INCOMING acknowledgement, this action triggers sending the acknowledgement. Invoke it using callback.Invoke(payload) where the payload follows the same rules as for an emit. If this Packet is not an incoming acknowledgement, the callback is null.
public Action<object[]> callback { get; }
Property Value
namespacePath
public string namespacePath { get; }
Property Value
payloads
The payloads of this event. Every payload is eighter a byte[] (for binary payloads) or a JToken - which can be a JValue, JObject or JArray IT is recommended to access the paloadsy using GetPayload(...)
public List<object> payloads { get; }
Property Value
type
public DataTypes.PacketType type { get; }
Property Value
Methods
GetPayload<T>(int, bool)
Returns the payload at a specific position. The payload is checked and only returned, when it exists and the type is valid (castable). You can decide the behaviour, if the actual payload does not match the type. This method should work for most Object and Array types as well as binary (byte[]). It might not work for some enumerables. You can always directly access the payloads field.
public T GetPayload<T>(int position, bool throwOnError = true)
Parameters
position
intThe position of the payload (zero-based)
throwOnError
boolIf true or unset, an exception will be thrown if the payload does not exist or does not match the type. If false, the method returns the type's default and a warning is logged instead.
Returns
- T
The payload casted into the requested type
Type Parameters
T
The type of the payload
Exceptions
- IndexOutOfRangeException
Throws IndexOutOfRangeException if throwOnError is true and the event does not contain a payload at the specified position
- InvalidCastException
Throws InvalidCastException if throwOnError is true and the requested payload is of an incompatible type
- JsonException
Throws InvalidCastException if throwOnError is true and and the requested payload could not be deserialized by Json.Net