Browse Source

0.6 beta2 - Added api/gateway

tags/docs-0.9
RogueException 9 years ago
parent
commit
2086a0fa04
6 changed files with 23 additions and 17 deletions
  1. +3
    -1
      src/Discord.Net/API/DiscordAPI.cs
  2. +2
    -4
      src/Discord.Net/API/Endpoints.cs
  3. +6
    -0
      src/Discord.Net/API/Models/APIResponses.cs
  4. +7
    -5
      src/Discord.Net/DiscordClient.cs
  5. +4
    -6
      src/Discord.Net/DiscordWebSocket.cs
  6. +1
    -1
      src/Discord.Net/project.json

+ 3
- 1
src/Discord.Net/API/DiscordAPI.cs View File

@@ -11,7 +11,9 @@ namespace Discord.API
public const int MaxMessageSize = 2000;

//Auth
public static async Task<APIResponses.AuthRegister> LoginAnonymous(string username)
public static Task<APIResponses.Gateway> GetWebSocket()
=> Http.Get<APIResponses.Gateway>(Endpoints.Gateway);
public static async Task<APIResponses.AuthRegister> LoginAnonymous(string username)
{
var fingerprintResponse = await Http.Post<APIResponses.AuthFingerprint>(Endpoints.AuthFingerprint);
var registerRequest = new APIRequests.AuthRegisterRequest { Fingerprint = fingerprintResponse.Fingerprint, Username = username };


+ 2
- 4
src/Discord.Net/API/Endpoints.cs View File

@@ -9,7 +9,8 @@

// /api
public static readonly string BaseApi = $"{BaseHttps}/api";
public static readonly string Track = $"{BaseApi}/track";
//public static readonly string Track = $"{BaseApi}/track";
public static readonly string Gateway = $"{BaseApi}/gateway";

// /api/auth
public static readonly string Auth = $"{BaseApi}/auth";
@@ -49,9 +50,6 @@
public static readonly string VoiceRegions = $"{Voice}/regions";
public static readonly string VoiceIce = $"{Voice}/ice";

//Web Sockets
public static readonly string WebSocket_Hub = $"{BaseUrl}/hub";

//Website
public static string InviteUrl(string code) => $"{BaseShortHttps}/{code}";
}


+ 6
- 0
src/Discord.Net/API/Models/APIResponses.cs View File

@@ -9,6 +9,12 @@ namespace Discord.API.Models
{
internal static class APIResponses
{
public class Gateway
{
[JsonProperty(PropertyName = "url")]
public string Url;
}

public class AuthFingerprint
{
[JsonProperty(PropertyName = "fingerprint")]


+ 7
- 5
src/Discord.Net/DiscordClient.cs View File

@@ -301,7 +301,7 @@ namespace Discord
try
{
await Task.Delay(_config.ReconnectDelay);
await _webSocket.ConnectAsync(Endpoints.WebSocket_Hub);
await _webSocket.ReconnectAsync();
await _webSocket.Login();
break;
}
@@ -587,7 +587,7 @@ namespace Discord
{
_currentVoiceEndpoint = data.Endpoint.Split(':')[0];
_currentVoiceToken = data.Token;
await _voiceWebSocket.ConnectAsync(_currentVoiceEndpoint);
await _voiceWebSocket.ConnectAsync("wss://" + _currentVoiceEndpoint);
await _voiceWebSocket.Login(_currentVoiceServerId, UserId, SessionId, _currentVoiceToken);
}
#endif
@@ -859,12 +859,14 @@ namespace Discord
_blockEvent.Reset();
_disconnectToken = new CancellationTokenSource();

string url = (await DiscordAPI.GetWebSocket()).Url;

//Connect by Token
if (token != null)
{
try
{
await _webSocket.ConnectAsync(Endpoints.WebSocket_Hub);
await _webSocket.ConnectAsync(url);
Http.Token = token;
await _webSocket.Login();
success = true;
@@ -878,7 +880,7 @@ namespace Discord
if (!success && password != null) //Email/Password login
{
//Open websocket while we wait for login response
Task socketTask = _webSocket.ConnectAsync(Endpoints.WebSocket_Hub);
Task socketTask = _webSocket.ConnectAsync(url);
var response = await DiscordAPI.Login(emailOrUsername, password);
await socketTask;

@@ -891,7 +893,7 @@ namespace Discord
if (!success && password == null) //Anonymous login
{
//Open websocket while we wait for login response
Task socketTask = _webSocket.ConnectAsync(Endpoints.WebSocket_Hub);
Task socketTask = _webSocket.ConnectAsync(url);
var response = await DiscordAPI.LoginAnonymous(emailOrUsername);
await socketTask;



+ 4
- 6
src/Discord.Net/DiscordWebSocket.cs View File

@@ -1,14 +1,10 @@
using Discord.API.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.Linq;

namespace Discord
{
@@ -47,7 +43,7 @@ namespace Discord

_webSocket = new ClientWebSocket();
_webSocket.Options.KeepAliveInterval = TimeSpan.Zero;
await _webSocket.ConnectAsync(new Uri("wss://" + url), cancelToken);
await _webSocket.ConnectAsync(new Uri(url), cancelToken);
_host = url;

OnConnect();
@@ -78,6 +74,8 @@ namespace Discord
_tasks = null;
});
}
public Task ReconnectAsync()
=> ConnectAsync(_host);
public async Task DisconnectAsync()
{
if (_tasks != null)


+ 1
- 1
src/Discord.Net/project.json View File

@@ -1,5 +1,5 @@
{
"version": "0.6.0-beta1",
"version": "0.6.0-beta2",
"description": "An unofficial .Net API wrapper for the Discord client.",
"authors": [ "RogueException" ],
"tags": [ "discord", "discordapp" ],


Loading…
Cancel
Save