1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-30 18:53:30 +00:00
arikawa/voice/voicegateway/event_methods.go
diamondburned 54cadd2f45 gateway: Refactor for a better concurrent API
This commit refactors the whole package gateway as well as utils/ws
(formerly utils/wsutil) and voice/voicegateway. The new refactor
utilizes a design pattern involving a concurrent loop and an arriving
event channel.

An additional change was made to the way gateway events are typed.
Before, pretty much any type will satisfy a gateway event type, since
the actual type was just interface{}. The new refactor defines a
concrete interface that events can implement:

    type Event interface {
        Op() OpCode
        EventType() EventType
    }

Using this interface, the user can easily add custom gateway events
independently of the library without relying on string maps. This adds a
lot of type safety into the library and makes type-switching on Event
types much more reasonable.

Gateway error callbacks are also almost entirely removed in favor of
custom gateway events. A catch-all can easily be added like this:

    s.AddHandler(func(err error) {
        log.Println("gateway error:, err")
    })
2021-12-14 13:49:34 -08:00

95 lines
3.1 KiB
Go

// Code generated by genevent. DO NOT EDIT.
package voicegateway
import "github.com/diamondburned/arikawa/v3/utils/ws"
func init() {
OpUnmarshalers.Add(
func() ws.Event { return new(IdentifyCommand) },
func() ws.Event { return new(SelectProtocolCommand) },
func() ws.Event { return new(ReadyEvent) },
func() ws.Event { return new(HeartbeatCommand) },
func() ws.Event { return new(SessionDescriptionEvent) },
func() ws.Event { return new(SpeakingEvent) },
func() ws.Event { return new(HeartbeatAckEvent) },
func() ws.Event { return new(ResumeCommand) },
func() ws.Event { return new(HelloEvent) },
func() ws.Event { return new(ResumedEvent) },
func() ws.Event { return new(ClientConnectEvent) },
func() ws.Event { return new(ClientDisconnectEvent) },
)
}
// Op implements Event. It always returns Op 0.
func (*IdentifyCommand) Op() ws.OpCode { return 0 }
// EventType implements Event.
func (*IdentifyCommand) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 1.
func (*SelectProtocolCommand) Op() ws.OpCode { return 1 }
// EventType implements Event.
func (*SelectProtocolCommand) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 2.
func (*ReadyEvent) Op() ws.OpCode { return 2 }
// EventType implements Event.
func (*ReadyEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 3.
func (*HeartbeatCommand) Op() ws.OpCode { return 3 }
// EventType implements Event.
func (*HeartbeatCommand) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 4.
func (*SessionDescriptionEvent) Op() ws.OpCode { return 4 }
// EventType implements Event.
func (*SessionDescriptionEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 5.
func (*SpeakingEvent) Op() ws.OpCode { return 5 }
// EventType implements Event.
func (*SpeakingEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 6.
func (*HeartbeatAckEvent) Op() ws.OpCode { return 6 }
// EventType implements Event.
func (*HeartbeatAckEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 7.
func (*ResumeCommand) Op() ws.OpCode { return 7 }
// EventType implements Event.
func (*ResumeCommand) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 8.
func (*HelloEvent) Op() ws.OpCode { return 8 }
// EventType implements Event.
func (*HelloEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 9.
func (*ResumedEvent) Op() ws.OpCode { return 9 }
// EventType implements Event.
func (*ResumedEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 12.
func (*ClientConnectEvent) Op() ws.OpCode { return 12 }
// EventType implements Event.
func (*ClientConnectEvent) EventType() ws.EventType { return "" }
// Op implements Event. It always returns Op 13.
func (*ClientDisconnectEvent) Op() ws.OpCode { return 13 }
// EventType implements Event.
func (*ClientDisconnectEvent) EventType() ws.EventType { return "" }