Snippets Collections
using Microsoft.AspNetCore.SignalR;
using System.Security.Claims;
using System.Threading.Tasks;

public class MyHub : Hub
{
    public override async Task OnConnectedAsync()
    {
        var userId = Context.User.FindFirstValue(ClaimTypes.NameIdentifier);
        await Groups.AddToGroupAsync(Context.ConnectionId, userId);

        await base.OnConnectedAsync();
    }
}
////////////////////////////////////////////////////////////////////
public async Task SendMessageToUser(string userId, string message)
{
    await Clients.Group(userId).SendAsync("ReceiveMessage", message);
}
public async Task AddToGroup(string groupName)
{
    await Groups.AddToGroupAsync(Context.ConnectionId, groupName);

    await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} has joined the group {groupName}.");
}

public async Task RemoveFromGroup(string groupName)
{
    await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);

    await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} has left the group {groupName}.");
}
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    entry: "./src/index.ts",
    output: {
        path: path.resolve(__dirname, "wwwroot"),
        filename: "[name].[chunkhash].js",
        publicPath: "/",
    },
    resolve: {
        extensions: [".js", ".ts"],
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: "ts-loader",
            },
            {
                test: /\.css$/,
                use: [MiniCssExtractPlugin.loader, "css-loader"],
            },
        ],
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template: "./src/index.html",
        }),
        new MiniCssExtractPlugin({
            filename: "css/[name].[chunkhash].css",
        }),
    ],
};
star

Sun Jul 02 2023 19:05:28 GMT+0000 (Coordinated Universal Time)

#signalr #c#
star

Sun Jul 02 2023 18:57:56 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-us/aspnet/core/signalr/groups?view

#signalr #c#
star

Sun Jul 02 2023 18:09:01 GMT+0000 (Coordinated Universal Time) https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr-typescript-webpack?view

#signalr #c#

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension