Skip to content

Commit 0332441

Browse files
committed
Review tabs
1 parent 44d2326 commit 0332441

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

articles/azure-web-pubsub/tutorial-build-chat.md

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Copy the fetched **ConnectionString** and it will be used later in this tutorial
5959

6060
# [Java](#tab/java)
6161

62-
- [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above
63-
- [Apache Maven](https://maven.apache.org/download.cgi)
62+
* [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or above
63+
* [Apache Maven](https://maven.apache.org/download.cgi)
6464

6565
---
6666

@@ -151,7 +151,7 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
151151
}
152152
```
153153
154-
`AddWebPubSubServiceClient<THub>()` is used to inject the service client `WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token and in hub methods to invoke service REST APIs when hub events are triggered.
154+
`AddWebPubSubServiceClient<THub>()` is used to inject the service client `WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token and in hub methods to invoke service REST APIs when hub events are triggered.
155155
156156
3. Add a `/negotiate` API to the server inside `app.UseEndpoints` to generate the token.
157157
@@ -173,9 +173,9 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
173173
});
174174
```
175175
176-
This token generation code is similar to the one we used in the [publish and subscribe message tutorial](./tutorial-pub-sub-messages.md), except we pass one more argument (`userId`) when generating the token. User ID can be used to identify the identity of client so when you receive a message you know where the message is coming from.
176+
This token generation code is similar to the one we used in the [publish and subscribe message tutorial](./tutorial-pub-sub-messages.md), except we pass one more argument (`userId`) when generating the token. User ID can be used to identify the identity of client so when you receive a message you know where the message is coming from.
177177
178-
You can test this API by running `dotnet run --urls http://localhost:8080` and accessing `http://localhost:8080/negotiate?id=<user-id>` and it will give you the full url of the Azure Web PubSub with an access token.
178+
You can test this API by running `dotnet run --urls http://localhost:8080` and accessing `http://localhost:8080/negotiate?id=<user-id>` and it will give you the full url of the Azure Web PubSub with an access token.
179179
180180
4. Then update `index.html` to include the following script to get the token from server and connect to service.
181181
@@ -197,7 +197,7 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
197197
</html>
198198
```
199199
200-
If you are using Chrome, you can test it by opening the home page, input your user name. Press F12 to open the Developer Tools window, switch to **Console** table and you'll see `connected` being printed in browser console.
200+
If you are using Chrome, you can test it by opening the home page, input your user name. Press F12 to open the Developer Tools window, switch to **Console** table and you'll see `connected` being printed in browser console.
201201
202202
# [C# .NET 6](#tab/net6)
203203
We'll use [ASP.NET Core 6](/aspnet/core) to host the web pages and handle incoming requests.
@@ -236,6 +236,7 @@ First let's create an empty ASP.NET Core app.
236236
</body>
237237
</html>
238238
```
239+
239240
You can test the server by running `dotnet run --urls http://localhost:8080` and access http://localhost:8080/index.html in browser.
240241
241242
You may remember in the [publish and subscribe message tutorial](./tutorial-pub-sub-messages.md) the subscriber uses an API in Web PubSub SDK to generate an access token from connection string and use it to connect to the service. This is usually not safe in a real world application as connection string has high privilege to do any operation to the service so you don't want to share it with any client. Let's change this access token generation process to a REST API at server side, so client can call this API to request an access token every time it needs to connect, without need to hold the connection string.
@@ -249,43 +250,43 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
249250
2. Create a file `SampleChatHub.cs` for the `SampleChatHub` class to handle hub events with the following content.
250251
251252
```csharp
252-
using Microsoft.Azure.WebPubSub.AspNetCore;
253+
using Microsoft.Azure.WebPubSub.AspNetCore;
253254

254-
sealed class SampleChatHub : WebPubSubHub
255-
{
256-
}
255+
sealed class SampleChatHub : WebPubSubHub
256+
{
257+
}
257258
```
258259
259260
3. Then update the `Program.cs` file to add DI for the service middleware and service client inside. Don't forget to replace `<connection_string>` with the one of your services.
260261
261262
```csharp
262-
using Microsoft.Azure.WebPubSub.AspNetCore;
263+
using Microsoft.Azure.WebPubSub.AspNetCore;
263264
264-
var builder = WebApplication.CreateBuilder(args);
265+
var builder = WebApplication.CreateBuilder(args);
265266
266-
builder.Services.AddWebPubSub(
267-
o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
268-
.AddWebPubSubServiceClient<SampleChatHub>();
267+
builder.Services.AddWebPubSub(
268+
o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
269+
.AddWebPubSubServiceClient<SampleChatHub>();
269270
270-
var app = builder.Build();
271+
var app = builder.Build();
271272
272-
if (app.Environment.IsDevelopment())
273-
{
274-
app.UseDeveloperExceptionPage();
275-
}
273+
if (app.Environment.IsDevelopment())
274+
{
275+
app.UseDeveloperExceptionPage();
276+
}
276277
277-
app.UseDefaultFiles();
278-
app.UseStaticFiles();
279-
app.UseRouting();
278+
app.UseDefaultFiles();
279+
app.UseStaticFiles();
280+
app.UseRouting();
280281
281-
app.UseEndpoints(endpoints =>
282-
{
283-
});
282+
app.UseEndpoints(endpoints =>
283+
{
284+
});
284285
285-
app.Run();
286+
app.Run();
286287
```
287288
288-
`AddWebPubSubServiceClient<THub>()` is used to inject the service client `WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token and in hub methods to invoke service REST APIs when hub events are triggered.
289+
`AddWebPubSubServiceClient<THub>()` is used to inject the service client `WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token and in hub methods to invoke service REST APIs when hub events are triggered.
289290
290291
4. Add a `/negotiate` API to the server inside `app.UseEndpoints` to generate the token.
291292
@@ -305,9 +306,10 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
305306
});
306307
});
307308
```
308-
This token generation code is similar to the one we used in the [publish and subscribe message tutorial](./tutorial-pub-sub-messages.md), except we pass one more argument (`userId`) when generating the token. User ID can be used to identify the identity of client so when you receive a message you know where the message is coming from.
309309
310-
You can test this API by running `dotnet run --urls http://localhost:8080` and accessing `http://localhost:8080/negotiate?id=<user-id>` and it will give you the full url of the Azure Web PubSub with an access token.
310+
This token generation code is similar to the one we used in the [publish and subscribe message tutorial](./tutorial-pub-sub-messages.md), except we pass one more argument (`userId`) when generating the token. User ID can be used to identify the identity of client so when you receive a message you know where the message is coming from.
311+
312+
You can test this API by running `dotnet run --urls http://localhost:8080` and accessing `http://localhost:8080/negotiate?id=<user-id>` and it will give you the full url of the Azure Web PubSub with an access token.
311313
312314
5. Then update `index.html` to include the following script to get the token from server and connect to service.
313315
@@ -678,6 +680,7 @@ Here we're using Web PubSub middleware SDK, there is already an implementation t
678680
```
679681
680682
2. Go the `SampleChatHub` we created in previous step. Add a constructor to work with `WebPubSubServiceClient<SampleChatHub>` so we can use to invoke service. And override `OnConnectedAsync()` method to respond when `connected` event is triggered.
683+
681684
```csharp
682685
using Microsoft.Azure.WebPubSub.AspNetCore;
683686
using Microsoft.Azure.WebPubSub.Common;

0 commit comments

Comments
 (0)