DiscordEngine
open class DiscordEngine : DiscordEngineSpec
The base class for Discord WebSocket communications.
-
The url for the gateway.
Declaration
Swift
open var connectURL: String
-
The type of DiscordEngineSpec. Used to correctly fire events.
Declaration
Swift
open var description: String
-
Creates the handshake object that Discord expects. Override if you need to customize the handshake object.
Declaration
Swift
open var handshakeObject: [String: Any]
-
Creates the resume object that Discord expects. Override if you need to customize the resume object.
Declaration
Swift
open var resumeObject: [String: Any]
-
The dispatch queue that heartbeats are sent on.
Declaration
Swift
public let heartbeatQueue = DispatchQueue(label: "discordEngine.heartbeatQueue")
-
The total number of shards.
Declaration
Swift
public let numShards: Int
-
The shard number of this engine.
Declaration
Swift
public let shardNum: Int
-
The queue that WebSockets use to parse things.
Declaration
Swift
public let parseQueue = DispatchQueue(label: "discordEngine.parseQueue")
-
The UUID of this WebSocketable.
Declaration
Swift
public var connectUUID = UUID()
-
This engine’s session id.
Declaration
Swift
public var sessionId: String?
-
The underlying WebSocket.
On Linux this is a WebSockets.WebSocket. While on macOS/iOS this is a Starscream.WebSocket
Declaration
Swift
public var websocket: WebSocket?
-
Whether this engine is connected to the gateway.
Declaration
Swift
public internal(set) var connected = false
-
The interval (in seconds) to send heartbeats.
Declaration
Swift
public internal(set) var heartbeatInterval = 0
-
The delegate that this engine is associated with.
Declaration
Swift
public private(set) weak var delegate: DiscordShardDelegate?
-
The last sequence number received. Will be used for session resumes.
Declaration
Swift
public private(set) var lastSequenceNumber = -1
-
Creates a new DiscordEngine.
Declaration
Swift
public required init(delegate: DiscordShardDelegate, shardNum: Int = 0, numShards: Int = 1)
Parameters
delegate
The DiscordClientSpec this engine should be associated with.
-
Disconnects the engine. An
engine.disconnect
is fired on disconnection.Declaration
Swift
public func disconnect()
-
Handles a close from the WebSocket.
Declaration
Swift
open func handleClose(reason: Error? = nil)
Parameters
reason
The reason the socket closed.
-
Handles a dispatch payload.
Declaration
Swift
open func handleDispatch(_ payload: DiscordGatewayPayload)
Parameters
payload
The dispatch payload
-
Handles a DiscordGatewayPayload. You shouldn’t need to call this directly.
Override this method if you need to customize payload handling.
Declaration
Swift
open func handleGatewayPayload(_ payload: DiscordGatewayPayload)
Parameters
payload
The payload object
-
Handles the hello event.
Declaration
Swift
open func handleHello(_ payload: DiscordGatewayPayload)
Parameters
payload
The dispatch payload
-
Handles the resumed event. You shouldn’t call this directly.
Declaration
Swift
open func handleResumed(_ payload: DiscordGatewayPayload)
-
Parses a raw message from the WebSocket. This is the entry point for all Discord events. You shouldn’t call this directly.
Override this method if you need to customize parsing.
Declaration
Swift
open func parseGatewayMessage(_ string: String)
Parameters
string
The raw payload string
-
Tries to resume a disconnected gateway connection.
Declaration
Swift
open func resumeGateway()
-
Sends a heartbeat to Discord. You shouldn’t need to call this directly.
Override this method if you need to customize heartbeats.
Declaration
Swift
open func sendHeartbeat()
-
Starts the handshake with the Discord server. You shouldn’t need to call this directly.
Override this method if you need to customize the handshake process.
Declaration
Swift
open func startHandshake()
-
Starts the engine’s heartbeat. You should call this method when you know the interval that Discord expects.
Declaration
Swift
public func startHeartbeat(milliseconds: Int)
Parameters
milliseconds
The heartbeat interval