diff --git a/DiscoBot/98293701175955456-rss.db b/DiscoBot/98293701175955456-rss.db
index 755f253..69760fd 100644
Binary files a/DiscoBot/98293701175955456-rss.db and b/DiscoBot/98293701175955456-rss.db differ
diff --git a/DiscoBot/ClientApp/package-lock.json b/DiscoBot/ClientApp/package-lock.json
index e350c7b..146576a 100644
--- a/DiscoBot/ClientApp/package-lock.json
+++ b/DiscoBot/ClientApp/package-lock.json
@@ -4211,14 +4211,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -4233,20 +4231,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"core-util-is": {
"version": "1.0.2",
@@ -4363,8 +4358,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"ini": {
"version": "1.3.5",
@@ -4376,7 +4370,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -4391,7 +4384,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -4399,14 +4391,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@@ -4425,7 +4415,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -4506,8 +4495,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true,
- "optional": true
+ "dev": true
},
"object-assign": {
"version": "4.1.1",
@@ -4519,7 +4507,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"wrappy": "1"
}
@@ -4641,7 +4628,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
- "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
diff --git a/DiscoBot/ClientApp/src/app/app.module.ts b/DiscoBot/ClientApp/src/app/app.module.ts
index 908d0c7..4ffdb58 100644
--- a/DiscoBot/ClientApp/src/app/app.module.ts
+++ b/DiscoBot/ClientApp/src/app/app.module.ts
@@ -9,6 +9,7 @@ import { NavMenuComponent } from './nav-menu/nav-menu.component';
import { HomeComponent } from './home/home.component';
import { CounterComponent } from './counter/counter.component';
import { FetchDataComponent } from './fetch-data/fetch-data.component';
+import { CalendarComponent } from './calendar/calendar.component';
@NgModule({
declarations: [
@@ -16,7 +17,8 @@ import { FetchDataComponent } from './fetch-data/fetch-data.component';
NavMenuComponent,
HomeComponent,
CounterComponent,
- FetchDataComponent
+ FetchDataComponent,
+ CalendarComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
@@ -26,6 +28,7 @@ import { FetchDataComponent } from './fetch-data/fetch-data.component';
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
+ { path: 'calendar', component: CalendarComponent },
])
],
providers: [],
diff --git a/DiscoBot/ClientApp/src/app/calendar/calendar.component.html b/DiscoBot/ClientApp/src/app/calendar/calendar.component.html
new file mode 100644
index 0000000..2e88cde
--- /dev/null
+++ b/DiscoBot/ClientApp/src/app/calendar/calendar.component.html
@@ -0,0 +1,24 @@
+
Calendar
+
+This component demonstrates fetching data from the server.
+
+Loading...
+
+
+
+
+ Date |
+ Temp. (C) |
+ Temp. (F) |
+ Summary |
+
+
+
+
+ {{ forecast.dateFormatted }} |
+ {{ forecast.temperatureC }} |
+ {{ forecast.temperatureF }} |
+ {{ forecast.summary }} |
+
+
+
diff --git a/DiscoBot/ClientApp/src/app/calendar/calendar.component.ts b/DiscoBot/ClientApp/src/app/calendar/calendar.component.ts
new file mode 100644
index 0000000..35318cd
--- /dev/null
+++ b/DiscoBot/ClientApp/src/app/calendar/calendar.component.ts
@@ -0,0 +1,40 @@
+import { Component, Inject } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+
+@Component({
+ selector: 'app-calendar',
+ templateUrl: './calendar.component.html'
+})
+export class CalendarComponent {
+ public forecasts: CalendarForecast[];
+
+ constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
+ console.log("ws connecting to ws" + baseUrl.substring(4, baseUrl.length) + "ws/calendar");
+ var ws = new WebSocket("ws" + baseUrl.substring(4, baseUrl.length) + "ws/calendar");
+
+ ws.onopen = function () {
+
+ // Web Socket is connected, send data using send()
+ ws.send("Message to send");
+ alert("Message is sent...");
+ };
+
+ ws.onmessage = function (evt) {
+ var received_msg = evt.data;
+ alert("Message is received...");
+ };
+
+ ws.onclose = function () {
+
+ // websocket is closed.
+ alert("Connection is closed...");
+ };
+ }
+}
+
+interface CalendarForecast {
+ dateFormatted: string;
+ temperatureC: number;
+ temperatureF: number;
+ summary: string;
+}
diff --git a/DiscoBot/ClientApp/src/app/fetch-data/fetch-data.component.ts b/DiscoBot/ClientApp/src/app/fetch-data/fetch-data.component.ts
index c120bef..15164d0 100644
--- a/DiscoBot/ClientApp/src/app/fetch-data/fetch-data.component.ts
+++ b/DiscoBot/ClientApp/src/app/fetch-data/fetch-data.component.ts
@@ -9,9 +9,9 @@ export class FetchDataComponent {
public forecasts: WeatherForecast[];
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
- http.get(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
+ /*http.get(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
this.forecasts = result;
- }, error => console.error(error));
+ }, error => console.error(error));*/
}
}
diff --git a/DiscoBot/ClientApp/src/app/home/home.component.html b/DiscoBot/ClientApp/src/app/home/home.component.html
index f74c2e7..771cae3 100644
--- a/DiscoBot/ClientApp/src/app/home/home.component.html
+++ b/DiscoBot/ClientApp/src/app/home/home.component.html
@@ -11,4 +11,5 @@
Angular CLI integration. In development mode, there's no need to run ng serve
. It runs in the background automatically, so your client-side resources are dynamically built on demand and the page refreshes when you modify any file.
Efficient production builds. In production mode, development-time features are disabled, and your dotnet publish
configuration automatically invokes ng build
to produce minified, ahead-of-time compiled JavaScript files.
+
The ClientApp
subdirectory is a standard Angular CLI application. If you open a command prompt in that directory, you can run any ng
command (e.g., ng test
), or use npm
to install extra packages into it.
diff --git a/DiscoBot/ClientApp/src/app/nav-menu/nav-menu.component.html b/DiscoBot/ClientApp/src/app/nav-menu/nav-menu.component.html
index 9ada617..a63422f 100644
--- a/DiscoBot/ClientApp/src/app/nav-menu/nav-menu.component.html
+++ b/DiscoBot/ClientApp/src/app/nav-menu/nav-menu.component.html
@@ -17,6 +17,9 @@
Fetch data
+
+ Calendar
+
diff --git a/DiscoBot/DisBot.cs b/DiscoBot/DisBot.cs
index ce01d99..1657764 100644
--- a/DiscoBot/DisBot.cs
+++ b/DiscoBot/DisBot.cs
@@ -1,9 +1,12 @@
using Discord;
using Discord.WebSocket;
+using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net.WebSockets;
using System.Reflection;
+using System.Threading;
using System.Threading.Tasks;
namespace DiscoBot
@@ -11,6 +14,7 @@ namespace DiscoBot
public class DisBot
{
private DiscordSocketClient discordClient;
+ private List webSockets = new List();
private WSController wsC;
private List moduleTypes = new List();
private Dictionary>> guildcommands = new Dictionary>>();
@@ -19,6 +23,27 @@ namespace DiscoBot
this.wsC = wsC;
}
+ private async Task Echo(HttpContext context, WebSocket webSocket)
+ {
+ var buffer = new byte[1024 * 4];
+ WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None);
+ while (!result.CloseStatus.HasValue)
+ {
+ await webSocket.SendAsync(new ArraySegment(buffer, 0, result.Count), result.MessageType, result.EndOfMessage, CancellationToken.None);
+
+ result = await webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None);
+ }
+ //await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
+ }
+
+ public async Task HandleWebsocket(HttpContext context)
+ {
+ Console.WriteLine("Handling Websocket to "+ context.Request.Path);
+ WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
+ webSockets.Add(webSocket);
+ await Echo(context, webSocket);
+ }
+
public async void Initialize()
{
Console.WriteLine("In init!");
diff --git a/DiscoBot/Startup.cs b/DiscoBot/Startup.cs
index 63f8177..da9e719 100644
--- a/DiscoBot/Startup.cs
+++ b/DiscoBot/Startup.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.Configuration;
@@ -8,13 +9,13 @@ using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
+using System.Threading;
using System.Threading.Tasks;
namespace DiscoBot
{
public class Startup
{
- private List webSockets = new List();
private WSController wsC = new WSController();
private DisBot diBot;
public Startup(IConfiguration configuration)
@@ -68,13 +69,11 @@ namespace DiscoBot
app.Use(async (context, next) =>
{
- if (context.Request.Path == "/ws")
+ if (context.Request.Path.ToString().StartsWith("/ws"))
{
if (context.WebSockets.IsWebSocketRequest)
{
- WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
- webSockets.Add(webSocket);
- //await Echo(context, webSocket);
+ await diBot.HandleWebsocket(context);
}
else
{