├── PusherRealtimeChat.WebAPI
├── Global.asax
├── Models
│ └── ChatMessage.cs
├── Global.asax.cs
├── App_Start
│ └── WebApiConfig.cs
├── Web.Debug.config
├── Web.Release.config
├── Properties
│ └── AssemblyInfo.cs
├── packages.config
├── Controllers
│ └── MessagesController.cs
├── Web.config
├── ApplicationInsights.config
└── PusherRealtimeChat.WebAPI.csproj
├── PusherRealtimeChat.UI
├── pusher_logo_dark.png
├── webpack.config.js
├── package.json
├── packages.config
├── index.html
├── Web.Debug.config
├── Web.Release.config
├── Properties
│ └── AssemblyInfo.cs
├── Web.config
├── index.js
├── ApplicationInsights.config
├── PusherRealtimeChat.UI.csproj
└── scripts
│ └── ai.0.22.19-build00125.min.js
├── PusherRealtimeChat.sln
└── .gitignore
/PusherRealtimeChat.WebAPI/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="PusherRealtimeChat.WebAPI.WebApiApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/pusher_logo_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pusher-community/pusher-dotnet-react-chat/HEAD/PusherRealtimeChat.UI/pusher_logo_dark.png
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Models/ChatMessage.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace PusherRealtimeChat.WebAPI.Models
4 | {
5 | public class ChatMessage
6 | {
7 | [Required]
8 | public string Text { get; set; }
9 |
10 | [Required]
11 | public string AuthorTwitterHandle { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using System.Web.Http;
6 | using System.Web.Routing;
7 |
8 | namespace PusherRealtimeChat.WebAPI
9 | {
10 | public class WebApiApplication : System.Web.HttpApplication
11 | {
12 | protected void Application_Start()
13 | {
14 | GlobalConfiguration.Configure(WebApiConfig.Register);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/webpack.config.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | module.exports = {
4 | entry: "./index.js",
5 | output: {
6 | filename: "bundle.js"
7 | },
8 | module: {
9 | loaders: [
10 | {
11 | test: /\.js$/,
12 | loader: "babel-loader",
13 | exclude: /node_modules/,
14 | query: {
15 | presets: ["es2015", "react"]
16 | }
17 | }
18 | ]
19 | }
20 | };
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.0.0",
3 | "name": "ASP.NET",
4 | "private": true,
5 | "devDependencies": {
6 | "webpack": "1.13.1",
7 | "babel": "6.5.2",
8 | "babel-preset-es2015": "6.9.0",
9 | "babel-preset-react": "6.11.1",
10 | "babel-loader": "6.2.4"
11 | },
12 | "dependencies": {
13 | "react": "15.2.1",
14 | "react-dom": "15.2.1",
15 | "axios": "0.13.1",
16 | "pusher-js": "3.1.0"
17 | },
18 | "scripts": {
19 | "build": "webpack --config webpack.config.js"
20 | },
21 | "-vs-binding": { "AfterBuild": [ "build" ] }
22 | }
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/App_Start/WebApiConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web.Http;
5 |
6 | namespace PusherRealtimeChat.WebAPI
7 | {
8 | public static class WebApiConfig
9 | {
10 | public static void Register(HttpConfiguration config)
11 | {
12 | // Web API configuration and services
13 | config.EnableCors();
14 |
15 | // Web API routes
16 | config.MapHttpAttributeRoutes();
17 |
18 | config.Routes.MapHttpRoute(
19 | name: "DefaultApi",
20 | routeTemplate: "api/{controller}/{id}",
21 | defaults: new { id = RouteParameter.Optional }
22 | );
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Pusher Realtime Chat
4 |
5 |
41 |
42 |
43 |
44 |

45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PusherRealtimeChat.UI")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PusherRealtimeChat.UI")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7941a064-56eb-453f-9952-a8298d361267")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PusherRealtimeChat.WebAPI")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PusherRealtimeChat.WebAPI")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3880fbcd-e801-49b4-9754-b5f39c923351")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PusherRealtimeChat.WebAPI", "PusherRealtimeChat.WebAPI\PusherRealtimeChat.WebAPI.csproj", "{3880FBCD-E801-49B4-9754-B5F39C923351}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PusherRealtimeChat.UI", "PusherRealtimeChat.UI\PusherRealtimeChat.UI.csproj", "{7941A064-56EB-453F-9952-A8298D361267}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {3880FBCD-E801-49B4-9754-B5F39C923351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {3880FBCD-E801-49B4-9754-B5F39C923351}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {3880FBCD-E801-49B4-9754-B5F39C923351}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {3880FBCD-E801-49B4-9754-B5F39C923351}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {7941A064-56EB-453F-9952-A8298D361267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {7941A064-56EB-453F-9952-A8298D361267}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {7941A064-56EB-453F-9952-A8298D361267}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {7941A064-56EB-453F-9952-A8298D361267}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Controllers/MessagesController.cs:
--------------------------------------------------------------------------------
1 | using PusherRealtimeChat.WebAPI.Models;
2 | using PusherServer;
3 | using System.Collections.Generic;
4 | using System.Net;
5 | using System.Net.Http;
6 | using System.Web.Http;
7 | using System.Web.Http.Cors;
8 |
9 | namespace PusherRealtimeChat.WebAPI.Controllers
10 | {
11 | [EnableCors("*", "*", "*")]
12 | public class MessagesController : ApiController
13 | {
14 | private static List messages =
15 | new List()
16 | {
17 | new ChatMessage
18 | {
19 | AuthorTwitterHandle = "Pusher",
20 | Text = "Hi there! 😘"
21 | },
22 | new ChatMessage
23 | {
24 | AuthorTwitterHandle = "Pusher",
25 | Text = "Welcome to your chat app"
26 | }
27 | };
28 |
29 | public HttpResponseMessage Get()
30 | {
31 | return Request.CreateResponse(HttpStatusCode.OK, messages);
32 | }
33 |
34 | public HttpResponseMessage Post(ChatMessage message)
35 | {
36 | if (message == null || !ModelState.IsValid)
37 | {
38 | return Request.CreateErrorResponse(
39 | HttpStatusCode.BadRequest,
40 | "Invalid input");
41 | }
42 | messages.Add(message);
43 | var pusher = new Pusher(
44 | "YOUR APP ID",
45 | "YOUR APP KEY",
46 | "YOUR APP SECRET");
47 | pusher.Trigger(
48 | channelName: "messages",
49 | eventName: "new_message",
50 | data: new
51 | {
52 | AuthorTwitterHandle = message.AuthorTwitterHandle,
53 | Text = message.Text
54 | });
55 | return Request.CreateResponse(HttpStatusCode.Created);
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/PusherRealtimeChat.WebAPI/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/PusherRealtimeChat.UI/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import axios from "axios";
4 | import Pusher from "pusher-js";
5 |
6 | const baseUrl = 'http://localhost:50811';
7 |
8 | const Welcome = ({ onSubmit }) => {
9 | let usernameInput;
10 | return (
11 |
12 |
Enter your Twitter name and start chatting!
13 |
22 |
23 | );
24 | };
25 |
26 | const ChatInputForm = ({
27 | onSubmit
28 | }) => {
29 | let messageInput;
30 | return (
31 |