1 module dscord.voice.packets; 2 3 import std.stdio; 4 5 import dscord.types.all, 6 dscord.gateway.packets; 7 8 enum VoiceOPCode { 9 VOICE_IDENTIFY = 0, 10 VOICE_SELECT_PROTOCOL = 1, 11 VOICE_READY = 2, 12 VOICE_HEARTBEAT = 3, 13 VOICE_SESSION_DESCRIPTION = 4, 14 VOICE_SPEAKING = 5, 15 } 16 17 class VoiceIdentifyPacket : BasePacket, Serializable { 18 Snowflake serverID; 19 Snowflake userID; 20 string sessionID; 21 string token; 22 23 this(Snowflake server, Snowflake user, string session, string token) { 24 this.serverID = server; 25 this.userID = user; 26 this.sessionID = session; 27 this.token = token; 28 } 29 30 override JSONValue serialize() { 31 JSONValue res; 32 res["server_id"] = JSONValue(this.serverID); 33 res["user_id"] = JSONValue(this.userID); 34 res["session_id"] = JSONValue(this.sessionID); 35 res["token"] = JSONValue(this.token); 36 return super.serialize(VoiceOPCode.VOICE_IDENTIFY, res); 37 } 38 } 39 40 class VoiceReadyPacket : BasePacket { 41 ushort ssrc; 42 ushort port; 43 string[] modes; 44 ushort heartbeat_interval; 45 } 46 47 class VoiceSelectProtocolPacket : BasePacket, Serializable { 48 string protocol; 49 string mode; 50 string ip; 51 ushort port; 52 53 this(string protocol, string mode, string ip, ushort port) { 54 this.protocol = protocol; 55 this.mode = mode; 56 this.ip = ip; 57 this.port = port; 58 } 59 60 override JSONValue serialize() { 61 JSONValue res; 62 res["port"] = this.port; 63 res["address"] = this.ip; 64 res["mode"] = this.mode; 65 return super.serialize(VoiceOPCode.VOICE_SELECT_PROTOCOL, res); 66 } 67 } 68 69 class VoiceHeartbeatPacket : BasePacket, Serializable { 70 uint ts; 71 72 this(uint ts) { 73 this.ts = ts; 74 } 75 76 override JSONValue serialize() { 77 return super.serialize(VoiceOPCode.VOICE_HEARTBEAT, JSONValue(this.ts)); 78 } 79 } 80 81 class VoiceSpeakingPacket : BasePacket, Serializable { 82 bool speaking; 83 uint delay; 84 85 this(bool speaking, uint delay) { 86 this.speaking = speaking; 87 this.delay = delay; 88 } 89 90 override JSONValue serialize() { 91 JSONValue res; 92 res["speaking"] = this.speaking; 93 res["delay"] = this.delay; 94 return super.serialize(VoiceOPCode.VOICE_SPEAKING, res); 95 } 96 } 97 98 class VoiceSessionDescriptionPacket : BasePacket { 99 string secretKey; 100 } 101