├── .editorconfig ├── .github └── workflows │ ├── ci.yml │ └── publish.yml ├── .gitignore ├── Directory.Build.props ├── Directory.Build.targets ├── LICENSE ├── README.md ├── SignalR.sln ├── global.json ├── package-lock.json ├── src ├── Blazor.Extensions.SignalR.JS │ ├── Blazor.Extensions.SignalR.JS.csproj │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── HubConnectionManager.ts │ │ └── InitializeSignalR.ts │ ├── tsconfig.json │ ├── tsfmt.json │ ├── tslint.json │ └── webpack.config.js ├── Blazor.Extensions.SignalR │ ├── Blazor.Extensions.SignalR.csproj │ ├── HttpConnectionOptions.cs │ ├── HttpTransportType.cs │ ├── HubCloseCallback.cs │ ├── HubConnection.cs │ ├── HubConnectionBuilder.cs │ ├── HubMethodCallback.cs │ ├── JSRuntimeExtensions.cs │ └── SignalRLogLevel.cs ├── Directory.Build.props └── Directory.Build.targets └── test ├── Blazor.Extensions.SignalR.Test.Client ├── App.razor ├── Blazor.Extensions.SignalR.Test.Client.csproj ├── DemoData.cs ├── Pages │ ├── Chat.razor │ ├── ChatComponent.cs │ └── _Imports.razor ├── Program.cs ├── Shared │ ├── MainLayout.razor │ └── NavMenu.razor ├── Startup.cs ├── _Imports.razor └── wwwroot │ ├── css │ ├── bootstrap │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ └── site.css │ └── index.html ├── Blazor.Extensions.SignalR.Test.Server ├── Blazor.Extensions.SignalR.Test.Server.csproj ├── Controllers │ └── TokenController.cs ├── Hubs │ └── ChatHub.cs ├── Program.cs └── Startup.cs └── Directory.Build.props /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://EditorConfig.org 2 | 3 | # This file is the top-most EditorConfig file 4 | root = true 5 | 6 | # All Files 7 | [*] 8 | charset = utf-8 9 | end_of_line = crlf 10 | indent_style = space 11 | indent_size = 4 12 | insert_final_newline = false 13 | trim_trailing_whitespace = true 14 | 15 | # Solution Files 16 | [*.sln] 17 | indent_style = tab 18 | 19 | # XML Project Files 20 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 21 | indent_size = 2 22 | 23 | # Configuration Files 24 | [*.{json,xml,yml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}] 25 | indent_size = 2 26 | 27 | # Markdown Files 28 | [*.md] 29 | trim_trailing_whitespace = false 30 | 31 | # Web Files 32 | [*.{htm,html,js,ts,css,scss,less}] 33 | indent_size = 2 34 | insert_final_newline = true 35 | 36 | # Bash Files 37 | [*.sh] 38 | end_of_line = lf 39 | 40 | # Dotnet Code Style Settings 41 | # See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 42 | # See http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers 43 | [*.{cs,csx,cake,vb}] 44 | dotnet_sort_system_directives_first = true:warning 45 | dotnet_style_coalesce_expression = true:warning 46 | dotnet_style_collection_initializer = true:warning 47 | dotnet_style_explicit_tuple_names = true:warning 48 | dotnet_style_null_propagation = true:warning 49 | dotnet_style_object_initializer = true:warning 50 | dotnet_style_predefined_type_for_locals_parameters_members = true:warning 51 | dotnet_style_predefined_type_for_member_access = true:warning 52 | dotnet_style_qualification_for_event = true:warning 53 | dotnet_style_qualification_for_field = true:warning 54 | dotnet_style_qualification_for_method = true:warning 55 | dotnet_style_qualification_for_property = true:warning 56 | 57 | # Naming Symbols 58 | # constant_fields - Define constant fields 59 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 60 | dotnet_naming_symbols.constant_fields.required_modifiers = const 61 | # non_private_readonly_fields - Define public, internal and protected readonly fields 62 | dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, internal, protected 63 | dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field 64 | dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly 65 | # static_readonly_fields - Define static and readonly fields 66 | dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field 67 | dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly 68 | # private_readonly_fields - Define private readonly fields 69 | dotnet_naming_symbols.private_readonly_fields.applicable_accessibilities = private 70 | dotnet_naming_symbols.private_readonly_fields.applicable_kinds = field 71 | dotnet_naming_symbols.private_readonly_fields.required_modifiers = readonly 72 | # public_internal_fields - Define public and internal fields 73 | dotnet_naming_symbols.public_internal_fields.applicable_accessibilities = public, internal 74 | dotnet_naming_symbols.public_internal_fields.applicable_kinds = field 75 | # private_protected_fields - Define private and protected fields 76 | dotnet_naming_symbols.private_protected_fields.applicable_accessibilities = private, protected 77 | dotnet_naming_symbols.private_protected_fields.applicable_kinds = field 78 | # public_symbols - Define any public symbol 79 | dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, internal, protected, protected_internal 80 | dotnet_naming_symbols.public_symbols.applicable_kinds = method, property, event, delegate 81 | # parameters - Defines any parameter 82 | dotnet_naming_symbols.parameters.applicable_kinds = parameter 83 | # non_interface_types - Defines class, struct, enum and delegate types 84 | dotnet_naming_symbols.non_interface_types.applicable_kinds = class, struct, enum, delegate 85 | # interface_types - Defines interfaces 86 | dotnet_naming_symbols.interface_types.applicable_kinds = interface 87 | 88 | # Naming Styles 89 | # camel_case - Define the camelCase style 90 | dotnet_naming_style.camel_case.capitalization = camel_case 91 | # pascal_case - Define the Pascal_case style 92 | dotnet_naming_style.pascal_case.capitalization = pascal_case 93 | # first_upper - The first character must start with an upper-case character 94 | dotnet_naming_style.first_upper.capitalization = first_word_upper 95 | # prefix_interface_interface_with_i - Interfaces must be PascalCase and the first character of an interface must be an 'I' 96 | dotnet_naming_style.prefix_interface_interface_with_i.capitalization = pascal_case 97 | dotnet_naming_style.prefix_interface_interface_with_i.required_prefix = I 98 | 99 | # Naming Rules 100 | # Constant fields must be PascalCase 101 | dotnet_naming_rule.constant_fields_must_be_pascal_case.severity = warning 102 | dotnet_naming_rule.constant_fields_must_be_pascal_case.symbols = constant_fields 103 | dotnet_naming_rule.constant_fields_must_be_pascal_case.style = pascal_case 104 | # Public, internal and protected readonly fields must be PascalCase 105 | dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.severity = warning 106 | dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.symbols = non_private_readonly_fields 107 | dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.style = pascal_case 108 | # Static readonly fields must be PascalCase 109 | dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.severity = warning 110 | dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.symbols = static_readonly_fields 111 | dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.style = pascal_case 112 | # Private readonly fields must be camelCase 113 | dotnet_naming_rule.private_readonly_fields_must_be_camel_case.severity = warning 114 | dotnet_naming_rule.private_readonly_fields_must_be_camel_case.symbols = private_readonly_fields 115 | dotnet_naming_rule.private_readonly_fields_must_be_camel_case.style = camel_case 116 | # Public and internal fields must be PascalCase 117 | dotnet_naming_rule.public_internal_fields_must_be_pascal_case.severity = warning 118 | dotnet_naming_rule.public_internal_fields_must_be_pascal_case.symbols = public_internal_fields 119 | dotnet_naming_rule.public_internal_fields_must_be_pascal_case.style = pascal_case 120 | # Private and protected fields must be camelCase 121 | dotnet_naming_rule.private_protected_fields_must_be_camel_case.severity = warning 122 | dotnet_naming_rule.private_protected_fields_must_be_camel_case.symbols = private_protected_fields 123 | dotnet_naming_rule.private_protected_fields_must_be_camel_case.style = camel_case 124 | # Public members must be capitalized 125 | dotnet_naming_rule.public_members_must_be_capitalized.severity = warning 126 | dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols 127 | dotnet_naming_rule.public_members_must_be_capitalized.style = first_upper 128 | # Parameters must be camelCase 129 | dotnet_naming_rule.parameters_must_be_camel_case.severity = warning 130 | dotnet_naming_rule.parameters_must_be_camel_case.symbols = parameters 131 | dotnet_naming_rule.parameters_must_be_camel_case.style = camel_case 132 | # Class, struct, enum and delegates must be PascalCase 133 | dotnet_naming_rule.non_interface_types_must_be_pascal_case.severity = warning 134 | dotnet_naming_rule.non_interface_types_must_be_pascal_case.symbols = non_interface_types 135 | dotnet_naming_rule.non_interface_types_must_be_pascal_case.style = pascal_case 136 | # Interfaces must be PascalCase and start with an 'I' 137 | dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning 138 | dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types 139 | dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i 140 | 141 | # C# Code Style Settings 142 | # See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference 143 | # See http://kent-boogaart.com/blog/editorconfig-reference-for-c-developers 144 | [*.cs,csx,cake] 145 | # Indentation Options 146 | csharp_indent_block_contents = true:warning 147 | csharp_indent_braces = false:warning 148 | csharp_indent_case_contents = true:warning 149 | csharp_indent_labels = no_change:warning 150 | csharp_indent_switch_labels = true:warning 151 | # Style Options 152 | csharp_style_conditional_delegate_call = true:warning 153 | csharp_style_expression_bodied_accessors = true:warning 154 | csharp_style_expression_bodied_constructors = true:warning 155 | csharp_style_expression_bodied_indexers = true:warning 156 | csharp_style_expression_bodied_methods = true:warning 157 | csharp_style_expression_bodied_operators = true:warning 158 | csharp_style_expression_bodied_properties = true:warning 159 | csharp_style_inlined_variable_declaration = true:warning 160 | csharp_style_pattern_matching_over_as_with_null_check = true:warning 161 | csharp_style_pattern_matching_over_is_with_cast_check = true:warning 162 | csharp_style_throw_expression = true:warning 163 | csharp_style_var_elsewhere = true:warning 164 | csharp_style_var_for_built_in_types = true:warning 165 | csharp_style_var_when_type_is_apparent = true:warning 166 | # New Line Options 167 | csharp_new_line_before_catch = true:warning 168 | csharp_new_line_before_else = true:warning 169 | csharp_new_line_before_finally = true:warning 170 | csharp_new_line_before_members_in_anonymous_types = true:warning 171 | csharp_new_line_before_members_in_object_initializers = true:warning 172 | # BUG: Warning level cannot be set https://github.com/dotnet/roslyn/issues/18010 173 | csharp_new_line_before_open_brace = all 174 | csharp_new_line_between_query_expression_clauses = true:warning 175 | # Spacing Options 176 | csharp_space_after_cast = false:warning 177 | csharp_space_after_colon_in_inheritance_clause = true:warning 178 | csharp_space_after_comma = true:warning 179 | csharp_space_after_dot = false:warning 180 | csharp_space_after_keywords_in_control_flow_statements = true:warning 181 | csharp_space_after_semicolon_in_for_statement = true:warning 182 | csharp_space_around_binary_operators = before_and_after:warning 183 | csharp_space_around_declaration_statements = do_not_ignore:warning 184 | csharp_space_before_colon_in_inheritance_clause = true:warning 185 | csharp_space_before_comma = false:warning 186 | csharp_space_before_dot = false:warning 187 | csharp_space_before_semicolon_in_for_statement = false:warning 188 | csharp_space_before_open_square_brackets = false:warning 189 | csharp_space_between_empty_square_brackets = false:warning 190 | csharp_space_between_method_declaration_name_and_open_parenthesis = false:warning 191 | csharp_space_between_method_declaration_parameter_list_parentheses = false:warning 192 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false:warning 193 | csharp_space_between_method_call_name_and_opening_parenthesis = false:warning 194 | csharp_space_between_method_call_parameter_list_parentheses = false:warning 195 | csharp_space_between_method_call_empty_parameter_list_parentheses = false:warning 196 | csharp_space_between_parentheses = expressions:warning 197 | csharp_space_between_square_brackets = false:warning 198 | # Wrapping Options 199 | csharp_preserve_single_line_blocks = true:warning 200 | csharp_preserve_single_line_statements = false:warning -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v1 15 | - name: Setup .NET Core 16 | uses: actions/setup-dotnet@v1 17 | with: 18 | dotnet-version: 3.1.100-preview3-014645 19 | - name: Build 20 | run: dotnet build --configuration Release -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: Setup .NET Core 15 | uses: actions/setup-dotnet@v1 16 | with: 17 | dotnet-version: 3.1.100-preview3-014645 18 | - name: Build 19 | run: dotnet build --configuration Release 20 | - name: Test 21 | run: dotnet test --configuration Release --no-build 22 | - name: Pack 23 | run: dotnet pack --configuration Release --output packages -p:Version=${GITHUB_REF##*/v} 24 | - name: Push 25 | working-directory: packages 26 | run: | 27 | dotnet nuget push Blazor.Extensions.SignalR.*.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json 28 | - name: Create Release 29 | uses: actions/create-release@master 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | with: 33 | tag_name: ${{ github.ref }} 34 | release_name: Release ${{ github.ref }} 35 | draft: false 36 | prerelease: false 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | [Pp]ublish[Oo]utput/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | dist/ 28 | 29 | # Visual Studio 2015 cache/options directory 30 | .vs/ 31 | # Uncomment if you have tasks that create the project's static files in wwwroot 32 | #wwwroot/ 33 | 34 | # MSTest test Results 35 | [Tt]est[Rr]esult*/ 36 | [Bb]uild[Ll]og.* 37 | 38 | # NUNIT 39 | *.VisualState.xml 40 | TestResult.xml 41 | 42 | # Build Results of an ATL Project 43 | [Dd]ebugPS/ 44 | [Rr]eleasePS/ 45 | dlldata.c 46 | 47 | # .NET Core 48 | project.lock.json 49 | project.fragment.lock.json 50 | artifacts/ 51 | **/Properties/launchSettings.json 52 | 53 | *_i.c 54 | *_p.c 55 | *_i.h 56 | *.ilk 57 | *.meta 58 | *.obj 59 | *.pch 60 | *.pdb 61 | *.pgc 62 | *.pgd 63 | *.rsp 64 | *.sbr 65 | *.tlb 66 | *.tli 67 | *.tlh 68 | *.tmp 69 | *.tmp_proj 70 | *.log 71 | *.vspscc 72 | *.vssscc 73 | .builds 74 | *.pidb 75 | *.svclog 76 | *.scc 77 | 78 | # Chutzpah Test files 79 | _Chutzpah* 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opendb 86 | *.opensdf 87 | *.sdf 88 | *.cachefile 89 | *.VC.db 90 | *.VC.VC.opendb 91 | 92 | # Visual Studio profiler 93 | *.psess 94 | *.vsp 95 | *.vspx 96 | *.sap 97 | 98 | # TFS 2012 Local Workspace 99 | $tf/ 100 | 101 | # Guidance Automation Toolkit 102 | *.gpState 103 | 104 | # ReSharper is a .NET coding add-in 105 | _ReSharper*/ 106 | *.[Rr]e[Ss]harper 107 | *.DotSettings.user 108 | 109 | # JustCode is a .NET coding add-in 110 | .JustCode 111 | 112 | # TeamCity is a build add-in 113 | _TeamCity* 114 | 115 | # DotCover is a Code Coverage Tool 116 | *.dotCover 117 | 118 | # Visual Studio code coverage results 119 | *.coverage 120 | *.coveragexml 121 | 122 | # NCrunch 123 | _NCrunch_* 124 | .*crunch*.local.xml 125 | nCrunchTemp_* 126 | 127 | # MightyMoose 128 | *.mm.* 129 | AutoTest.Net/ 130 | 131 | # Web workbench (sass) 132 | .sass-cache/ 133 | 134 | # Installshield output folder 135 | [Ee]xpress/ 136 | 137 | # DocProject is a documentation generator add-in 138 | DocProject/buildhelp/ 139 | DocProject/Help/*.HxT 140 | DocProject/Help/*.HxC 141 | DocProject/Help/*.hhc 142 | DocProject/Help/*.hhk 143 | DocProject/Help/*.hhp 144 | DocProject/Help/Html2 145 | DocProject/Help/html 146 | 147 | # Click-Once directory 148 | publish/ 149 | 150 | # Publish Web Output 151 | *.[Pp]ublish.xml 152 | *.azurePubxml 153 | # TODO: Comment the next line if you want to checkin your web deploy settings 154 | # but database connection strings (with potential passwords) will be unencrypted 155 | *.pubxml 156 | *.publishproj 157 | 158 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 159 | # checkin your Azure Web App publish settings, but sensitive information contained 160 | # in these scripts will be unencrypted 161 | PublishScripts/ 162 | 163 | # NuGet Packages 164 | *.nupkg 165 | # The packages folder can be ignored because of Package Restore 166 | **/packages/* 167 | # except build/, which is used as an MSBuild target. 168 | !**/packages/build/ 169 | # Uncomment if necessary however generally it will be regenerated when needed 170 | #!**/packages/repositories.config 171 | # NuGet v3's project.json files produces more ignorable files 172 | *.nuget.props 173 | *.nuget.targets 174 | 175 | # Microsoft Azure Build Output 176 | csx/ 177 | *.build.csdef 178 | 179 | # Microsoft Azure Emulator 180 | ecf/ 181 | rcf/ 182 | 183 | # Windows Store app package directories and files 184 | AppPackages/ 185 | BundleArtifacts/ 186 | Package.StoreAssociation.xml 187 | _pkginfo.txt 188 | 189 | # Visual Studio cache files 190 | # files ending in .cache can be ignored 191 | *.[Cc]ache 192 | # but keep track of directories ending in .cache 193 | !*.[Cc]ache/ 194 | 195 | # Others 196 | ClientBin/ 197 | ~$* 198 | *~ 199 | *.dbmdl 200 | *.dbproj.schemaview 201 | *.jfm 202 | *.pfx 203 | *.publishsettings 204 | orleans.codegen.cs 205 | 206 | # Since there are multiple workflows, uncomment next line to ignore bower_components 207 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 208 | #bower_components/ 209 | 210 | # RIA/Silverlight projects 211 | Generated_Code/ 212 | 213 | # Backup & report files from converting an old project file 214 | # to a newer Visual Studio version. Backup files are not needed, 215 | # because we have git ;-) 216 | _UpgradeReport_Files/ 217 | Backup*/ 218 | UpgradeLog*.XML 219 | UpgradeLog*.htm 220 | 221 | # SQL Server files 222 | *.mdf 223 | *.ldf 224 | *.ndf 225 | 226 | # Business Intelligence projects 227 | *.rdl.data 228 | *.bim.layout 229 | *.bim_*.settings 230 | 231 | # Microsoft Fakes 232 | FakesAssemblies/ 233 | 234 | # GhostDoc plugin setting file 235 | *.GhostDoc.xml 236 | 237 | # Node.js Tools for Visual Studio 238 | .ntvs_analysis.dat 239 | node_modules/ 240 | 241 | # Typescript v1 declaration files 242 | typings/ 243 | 244 | # Visual Studio 6 build log 245 | *.plg 246 | 247 | # Visual Studio 6 workspace options file 248 | *.opt 249 | 250 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 251 | *.vbw 252 | 253 | # Visual Studio LightSwitch build output 254 | **/*.HTMLClient/GeneratedArtifacts 255 | **/*.DesktopClient/GeneratedArtifacts 256 | **/*.DesktopClient/ModelManifest.xml 257 | **/*.Server/GeneratedArtifacts 258 | **/*.Server/ModelManifest.xml 259 | _Pvt_Extensions 260 | 261 | # Paket dependency manager 262 | .paket/paket.exe 263 | paket-files/ 264 | 265 | # FAKE - F# Make 266 | .fake/ 267 | 268 | # JetBrains Rider 269 | .idea/ 270 | *.sln.iml 271 | 272 | # CodeRush 273 | .cr/ 274 | 275 | # Python Tools for Visual Studio (PTVS) 276 | __pycache__/ 277 | *.pyc 278 | 279 | # Cake - Uncomment if you are using it 280 | # tools/** 281 | # !tools/packages.config 282 | 283 | # Telerik's JustMock configuration file 284 | *.jmconfig 285 | 286 | # BizTalk build output 287 | *.btp.cs 288 | *.btm.cs 289 | *.odx.cs 290 | *.xsd.cs 291 | .DS_Store 292 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Blazor Extensions Contributors 5 | Blazor Extensions 6 | (c) Blazor Extensions Contributors. All rights reserved. 7 | https://github.com/BlazorExtensions/SignalR#license 8 | https://github.com/BlazorExtensions/SignalR 9 | https://avatars2.githubusercontent.com/u/38994076?s%3D128%26v%3D4 10 | Microsoft ASP.NET Core Blazor Extensions SignalR 11 | 12 | https://github.com/BlazorExtensions/SignalR 13 | git 14 | true 15 | 16 | 17 | 18 | 19 | latest 20 | true 21 | true 22 | 23 | full 24 | 25 | 26 | 27 | netstandard2.0 28 | netstandard2.0 29 | 30 | 31 | 32 | 33 | 0.1.0 34 | dev 35 | 36 | 37 | 38 | 39 | 43 | 44 | <developer build> 45 | 46 | 47 | 48 | 49 | $(BUILD_SOURCEVERSION) 50 | 51 | 52 | 53 | 54 | $(GIT_COMMIT) 55 | 56 | 57 | 58 | 59 | Not found 60 | $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory).git')) 61 | $([System.IO.File]::ReadAllText('$(DotGitDir)/HEAD').Trim()) 62 | $(DotGitDir)/$(HeadFileContent.Substring(5)) 63 | $([System.IO.File]::ReadAllText('$(RefPath)').Trim()) 64 | $(HeadFileContent) 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(Version). Commit Hash: $(GitHeadSha) 5 | 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Blazor Extensions Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build](https://github.com/BlazorExtensions/SignalR/workflows/CI/badge.svg)](https://github.com/BlazorExtensions/SignalR/actions) 2 | [![Package Version](https://img.shields.io/nuget/v/Blazor.Extensions.SignalR.svg)](https://www.nuget.org/packages/Blazor.Extensions.SignalR) 3 | [![NuGet Downloads](https://img.shields.io/nuget/dt/Blazor.Extensions.SignalR.svg)](https://www.nuget.org/packages/Blazor.Extensions.SignalR) 4 | [![License](https://img.shields.io/github/license/BlazorExtensions/SignalR.svg)](https://github.com/BlazorExtensions/SignalR/blob/master/LICENSE) 5 | 6 | 7 | > **DEPRECATION NOTE**: This package is no longer required since [Blazor WebAssembly now supports SignalR Client](https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-1-release-now-available/). Users of this package should stop using it and use the official client instead. 8 | 9 | # Blazor Extensions 10 | 11 | Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net). 12 | 13 | # Blazor Extensions SignalR 14 | 15 | This package adds a [Microsoft ASP.NET Core SignalR](https://github.com/aspnet/SignalR) client library for [Microsoft ASP.NET Blazor](https://github.com/aspnet/Blazor). 16 | 17 | The package aims to mimic the C# APIs of SignalR Client as much as possible and it is developed by wrapping the TypeScript client by using Blazor's interop capabilities. 18 | 19 | For more information about SignalR development, please check [SignalR documentation](https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-2.1). 20 | 21 | # Features 22 | 23 | This package implements all public features of SignalR Typescript client. 24 | 25 | > Note: The _Streaming_ APIs are not implemented yet. We will add it soon. 26 | 27 | # Sample usage 28 | 29 | The following snippet shows how to setup the client to send and receive messages using SignalR. 30 | 31 | The HubConnectionBuilder needs to get injected, which must be registered: 32 | ```c# 33 | // in Startup.cs, ConfigureServices() 34 | services.AddTransient(); 35 | ``` 36 | ```c# 37 | // in Component class 38 | [Inject] 39 | private HubConnectionBuilder _hubConnectionBuilder { get; set; } 40 | ``` 41 | ```c# 42 | // in Component Initialization code 43 | var connection = _hubConnectionBuilder // the injected one from above. 44 | .WithUrl("/myHub", // The hub URL. If the Hub is hosted on the server where the blazor is hosted, you can just use the relative path. 45 | opt => 46 | { 47 | opt.LogLevel = SignalRLogLevel.Trace; // Client log level 48 | opt.Transport = HttpTransportType.WebSockets; // Which transport you want to use for this connection 49 | }) 50 | .Build(); // Build the HubConnection 51 | 52 | connection.On("Receive", this.Handle); // Subscribe to messages sent from the Hub to the "Receive" method by passing a handle (Func) to process messages. 53 | await connection.StartAsync(); // Start the connection. 54 | 55 | await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod" and pass parameters to it. 56 | 57 | var result = await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod", pass parameters to it and get the result back. 58 | ``` 59 | 60 | # Contributions and feedback 61 | 62 | Please feel free to use the component, open issues, fix bugs or provide feedback. 63 | 64 | # Contributors 65 | 66 | The following people are the maintainers of the Blazor Extensions projects: 67 | 68 | - [Attila Hajdrik](https://github.com/attilah) 69 | - [Gutemberg Ribiero](https://github.com/galvesribeiro) 70 | -------------------------------------------------------------------------------- /SignalR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B286BCBD-DAD8-4DE7-9334-3DE18DF233AF}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{20DAA632-F8AD-4C5F-9E5F-FC82B7CB56A7}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Extensions.SignalR", "src\Blazor.Extensions.SignalR\Blazor.Extensions.SignalR.csproj", "{9378C7BF-0899-4835-B8FB-099292C8C63D}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8A34FDEB-D488-4AE3-887B-8254B33C7A13}" 13 | ProjectSection(SolutionItems) = preProject 14 | README.md = README.md 15 | EndProjectSection 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Extensions.SignalR.JS", "src\Blazor.Extensions.SignalR.JS\Blazor.Extensions.SignalR.JS.csproj", "{1C49147F-7C73-4962-A71C-6A193970D058}" 18 | EndProject 19 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Extensions.SignalR.Test.Client", "test\Blazor.Extensions.SignalR.Test.Client\Blazor.Extensions.SignalR.Test.Client.csproj", "{752EC32C-EC70-4E7E-B2C3-610B0893249F}" 20 | EndProject 21 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Extensions.SignalR.Test.Server", "test\Blazor.Extensions.SignalR.Test.Server\Blazor.Extensions.SignalR.Test.Server.csproj", "{8952910D-6251-48A0-8A00-369553370547}" 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Any CPU = Debug|Any CPU 26 | Debug|x64 = Debug|x64 27 | Debug|x86 = Debug|x86 28 | Release|Any CPU = Release|Any CPU 29 | Release|x64 = Release|x64 30 | Release|x86 = Release|x86 31 | EndGlobalSection 32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 33 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|x64.ActiveCfg = Debug|Any CPU 36 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|x64.Build.0 = Debug|Any CPU 37 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|x86.ActiveCfg = Debug|Any CPU 38 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Debug|x86.Build.0 = Debug|Any CPU 39 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|x64.ActiveCfg = Release|Any CPU 42 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|x64.Build.0 = Release|Any CPU 43 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|x86.ActiveCfg = Release|Any CPU 44 | {9378C7BF-0899-4835-B8FB-099292C8C63D}.Release|x86.Build.0 = Release|Any CPU 45 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|x64.ActiveCfg = Debug|Any CPU 48 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|x64.Build.0 = Debug|Any CPU 49 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|x86.ActiveCfg = Debug|Any CPU 50 | {1C49147F-7C73-4962-A71C-6A193970D058}.Debug|x86.Build.0 = Debug|Any CPU 51 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|Any CPU.Build.0 = Release|Any CPU 53 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|x64.ActiveCfg = Release|Any CPU 54 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|x64.Build.0 = Release|Any CPU 55 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|x86.ActiveCfg = Release|Any CPU 56 | {1C49147F-7C73-4962-A71C-6A193970D058}.Release|x86.Build.0 = Release|Any CPU 57 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 58 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|Any CPU.Build.0 = Debug|Any CPU 59 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|x64.ActiveCfg = Debug|Any CPU 60 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|x64.Build.0 = Debug|Any CPU 61 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|x86.ActiveCfg = Debug|Any CPU 62 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Debug|x86.Build.0 = Debug|Any CPU 63 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|Any CPU.ActiveCfg = Release|Any CPU 64 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|Any CPU.Build.0 = Release|Any CPU 65 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|x64.ActiveCfg = Release|Any CPU 66 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|x64.Build.0 = Release|Any CPU 67 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|x86.ActiveCfg = Release|Any CPU 68 | {752EC32C-EC70-4E7E-B2C3-610B0893249F}.Release|x86.Build.0 = Release|Any CPU 69 | {8952910D-6251-48A0-8A00-369553370547}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 70 | {8952910D-6251-48A0-8A00-369553370547}.Debug|Any CPU.Build.0 = Debug|Any CPU 71 | {8952910D-6251-48A0-8A00-369553370547}.Debug|x64.ActiveCfg = Debug|Any CPU 72 | {8952910D-6251-48A0-8A00-369553370547}.Debug|x64.Build.0 = Debug|Any CPU 73 | {8952910D-6251-48A0-8A00-369553370547}.Debug|x86.ActiveCfg = Debug|Any CPU 74 | {8952910D-6251-48A0-8A00-369553370547}.Debug|x86.Build.0 = Debug|Any CPU 75 | {8952910D-6251-48A0-8A00-369553370547}.Release|Any CPU.ActiveCfg = Release|Any CPU 76 | {8952910D-6251-48A0-8A00-369553370547}.Release|Any CPU.Build.0 = Release|Any CPU 77 | {8952910D-6251-48A0-8A00-369553370547}.Release|x64.ActiveCfg = Release|Any CPU 78 | {8952910D-6251-48A0-8A00-369553370547}.Release|x64.Build.0 = Release|Any CPU 79 | {8952910D-6251-48A0-8A00-369553370547}.Release|x86.ActiveCfg = Release|Any CPU 80 | {8952910D-6251-48A0-8A00-369553370547}.Release|x86.Build.0 = Release|Any CPU 81 | EndGlobalSection 82 | GlobalSection(SolutionProperties) = preSolution 83 | HideSolutionNode = FALSE 84 | EndGlobalSection 85 | GlobalSection(NestedProjects) = preSolution 86 | {9378C7BF-0899-4835-B8FB-099292C8C63D} = {B286BCBD-DAD8-4DE7-9334-3DE18DF233AF} 87 | {1C49147F-7C73-4962-A71C-6A193970D058} = {B286BCBD-DAD8-4DE7-9334-3DE18DF233AF} 88 | {752EC32C-EC70-4E7E-B2C3-610B0893249F} = {20DAA632-F8AD-4C5F-9E5F-FC82B7CB56A7} 89 | {8952910D-6251-48A0-8A00-369553370547} = {20DAA632-F8AD-4C5F-9E5F-FC82B7CB56A7} 90 | EndGlobalSection 91 | GlobalSection(ExtensibilityGlobals) = postSolution 92 | SolutionGuid = {A97C0A4B-E309-4485-BB76-898B37BFBFFF} 93 | EndGlobalSection 94 | EndGlobal 95 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "3.1.100-preview3-014645" 4 | } 5 | } -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.SignalR.JS/Blazor.Extensions.SignalR.JS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | false 6 | false 7 | true 8 | Latest 9 | ${DefaultItemExcludes};dist\**;node_modules\** 10 | CS2008 11 | 12 | 13 | true 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.SignalR.JS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blazor.extensions.signalr", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "webpack-cli", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "devDependencies": { 11 | "@types/emscripten": "0.0.34", 12 | "ts-loader": "6.0.4", 13 | "typescript": "3.5.3", 14 | "webpack": "4.37.0", 15 | "webpack-cli": "3.3.6" 16 | }, 17 | "dependencies": { 18 | "@microsoft/signalr": "3.0.0", 19 | "@microsoft/signalr-protocol-msgpack": "3.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.SignalR.JS/src/HubConnectionManager.ts: -------------------------------------------------------------------------------- 1 | import * as signalR from "@microsoft/signalr"; 2 | import * as sianglRMessagePack from "@microsoft/signalr-protocol-msgpack"; 3 | import { HttpTransportType, LogLevel } from "@microsoft/signalr"; 4 | 5 | type DotNetType = { 6 | invokeMethod(assemblyName: string, methodIdentifier: string, ...args: any[]): T, 7 | invokeMethodAsync(assemblyName: string, methodIdentifier: string, ...args: any[]): Promise 8 | } 9 | 10 | type DotNetReferenceType = { 11 | invokeMethod(methodIdentifier: string, ...args: any[]): T, 12 | invokeMethodAsync(methodIdentifier: string, ...args: any[]): Promise 13 | } 14 | 15 | export class HubConnectionManager { 16 | private _hubConnections: Map = new Map(); 17 | private _handles: Map Promise> = new Map Promise>(); 18 | 19 | public CreateConnection = (connectionId: string, httpConnectionOptions: DotNetReferenceType) => { 20 | if (!connectionId) throw new Error('Invalid connectionId.'); 21 | if (!httpConnectionOptions) throw new Error('Invalid transport options.'); 22 | 23 | const url = httpConnectionOptions.invokeMethod('get_Url'); 24 | 25 | if (!url) throw new Error('Invalid hub url.'); 26 | 27 | let options: any = { 28 | logger: httpConnectionOptions.invokeMethod('get_LogLevel'), 29 | transport: httpConnectionOptions.invokeMethod('get_Transport'), 30 | logMessageContent: httpConnectionOptions.invokeMethod('get_LogMessageContent'), 31 | skipNegotiation: httpConnectionOptions.invokeMethod('get_SkipNegotiation') 32 | }; 33 | 34 | if (httpConnectionOptions.invokeMethod('HasAccessTokenFactory')) { 35 | options.accessTokenFactory = () => { 36 | return new Promise(async (resolve, reject) => { 37 | const token = await httpConnectionOptions.invokeMethodAsync('GetAccessToken'); 38 | if (token) { 39 | resolve(token); 40 | } else { 41 | reject(); 42 | } 43 | }) 44 | } 45 | } 46 | 47 | if (this._hubConnections[connectionId]) return; 48 | 49 | let connectionBuilder = new signalR.HubConnectionBuilder() 50 | .withUrl(url, options); 51 | 52 | if (httpConnectionOptions.invokeMethod('get_EnableMessagePack')) { 53 | connectionBuilder 54 | .withHubProtocol(new sianglRMessagePack.MessagePackHubProtocol()); 55 | } 56 | 57 | this._hubConnections.set(connectionId, connectionBuilder.build()); 58 | } 59 | 60 | public RemoveConnection = (connectionId: string) => { 61 | this._hubConnections.delete(connectionId); 62 | } 63 | 64 | public StartConnection = (connectionId: string): Promise => { 65 | const connection = this.GetConnection(connectionId); 66 | 67 | return connection.start(); 68 | } 69 | 70 | public StopConnection = (connectionId: string): Promise => { 71 | const connection = this.GetConnection(connectionId); 72 | 73 | return connection.stop(); 74 | } 75 | 76 | public InvokeAsync = (connectionId: string, methodName: string, args: any[]): Promise => { 77 | const connection = this.GetConnection(connectionId); 78 | 79 | return connection.invoke(methodName, ...args); 80 | } 81 | 82 | public InvokeWithResultAsync = async (connectionId: string, methodName: string, args: any[]): Promise => { 83 | const connection = this.GetConnection(connectionId); 84 | 85 | var result = await connection.invoke(methodName, ...args); 86 | 87 | return this.ReplaceTypedArray(result); 88 | } 89 | 90 | private GetConnection = (connectionId: string) => { 91 | if (!connectionId) throw new Error('Invalid connectionId.'); 92 | 93 | const connection = this._hubConnections.get(connectionId); 94 | 95 | if (!connection) throw new Error('Invalid connection.'); 96 | 97 | return connection; 98 | } 99 | 100 | private ReplaceTypedArray = (obj: any): any => { 101 | if (obj instanceof Int8Array || 102 | obj instanceof Uint8Array || 103 | obj instanceof Uint8ClampedArray || 104 | obj instanceof Int16Array || 105 | obj instanceof Uint16Array || 106 | obj instanceof Int32Array || 107 | obj instanceof Uint32Array || 108 | obj instanceof Float32Array || 109 | obj instanceof Float64Array) 110 | { 111 | obj = Array.prototype.slice.call(obj); 112 | } 113 | 114 | return obj; 115 | } 116 | 117 | public On = (connectionId: string, callback: DotNetReferenceType) => { 118 | const connection = this.GetConnection(connectionId); 119 | const handle = (...payloads) => callback.invokeMethodAsync( 120 | 'On', payloads.map(payload => JSON.stringify(this.ReplaceTypedArray(payload)))); 121 | 122 | this._handles.set(callback.invokeMethod('get_Id'), handle); 123 | 124 | connection.on(callback.invokeMethod('get_MethodName'), handle); 125 | } 126 | 127 | public Off = (connectionId: string, methodName: string, handleId: string) => { 128 | const connection = this.GetConnection(connectionId); 129 | const handle = this._handles.get(handleId); 130 | 131 | if (handle) { 132 | connection.off(methodName, handle); 133 | 134 | this._handles.delete(handleId); 135 | } 136 | } 137 | 138 | public OnClose = (connectionId: string, onErrorCallback: DotNetReferenceType) => { 139 | const connection = this.GetConnection(connectionId); 140 | 141 | connection.onclose(async err => { 142 | onErrorCallback.invokeMethodAsync('OnClose', JSON.stringify(err)); 143 | }); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/Blazor.Extensions.SignalR.JS/src/InitializeSignalR.ts: -------------------------------------------------------------------------------- 1 | import { HubConnectionManager } from './HubConnectionManager'; 2 | 3 | namespace SignalR { 4 | const blazorExtensions: string = 'BlazorExtensions'; 5 | // define what this extension adds to the window object inside BlazorExtensions 6 | const extensionObject = { 7 | SignalR: new HubConnectionManager() 8 | }; 9 | 10 | export function initialize(): void { 11 | if (typeof window !== 'undefined' && !window[blazorExtensions]) { 12 | // when the library is loaded in a browser via a 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.SignalR.Test.Server/Blazor.Extensions.SignalR.Test.Server.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.1 5 | 6 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json; 7 | https://dotnet.myget.org/F/blazor-dev/api/v3/index.json; 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.SignalR.Test.Server/Controllers/TokenController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.IdentityModel.Tokens; 3 | using System; 4 | using System.IdentityModel.Tokens.Jwt; 5 | using System.Security.Claims; 6 | using System.Text; 7 | 8 | namespace Blazor.Extensions.SignalR.Test.Server.Controllers 9 | { 10 | [Route("generatetoken")] 11 | public class TokenController : Controller 12 | { 13 | [HttpGet] 14 | public string GenerateToken() 15 | { 16 | var tokenHandler = new JwtSecurityTokenHandler(); 17 | var key = Encoding.ASCII.GetBytes(Startup.SECRET); 18 | var tokenDescriptor = new SecurityTokenDescriptor 19 | { 20 | Subject = new ClaimsIdentity(new Claim[] 21 | { 22 | new Claim(ClaimTypes.Name, "TestUser") 23 | }), 24 | Expires = DateTime.UtcNow.AddDays(1), 25 | SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) 26 | }; 27 | var token = tokenHandler.CreateToken(tokenDescriptor); 28 | return tokenHandler.WriteToken(token); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.SignalR.Test.Server/Hubs/ChatHub.cs: -------------------------------------------------------------------------------- 1 | using Blazor.Extensions.SignalR.Test.Client; 2 | using Microsoft.AspNetCore.Authentication.JwtBearer; 3 | using Microsoft.AspNetCore.Authorization; 4 | using Microsoft.AspNetCore.SignalR; 5 | using System; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace Blazor.Extensions.SignalR.Test.Server.Hubs 10 | { 11 | [Authorize] 12 | public class ChatHub : Hub 13 | { 14 | public async Task DoSomething() 15 | { 16 | await this.Clients.All.SendAsync("DemoMethodObject", new DemoData { Id = 1, Data = "Demo Data", DateTime = DateTime.UtcNow, DecimalData = 1.98M, Bool = true, EnumData = EnumType.A }); 17 | await this.Clients.All.SendAsync("DemoMethodList", 18 | Enumerable.Range(1, 10).Select(x => new DemoData { Id = x, Data = $"Demo Data #{x}", DateTime = DateTime.UtcNow, DecimalData = 2.2M, Bool = true, EnumData = EnumType.B }).ToList()); 19 | } 20 | 21 | public override async Task OnConnectedAsync() 22 | { 23 | await this.Clients.All.SendAsync("Send", $"{this.Context.ConnectionId} joined"); 24 | } 25 | 26 | public override async Task OnDisconnectedAsync(Exception ex) 27 | { 28 | await this.Clients.Others.SendAsync("Send", $"{this.Context.ConnectionId} left"); 29 | } 30 | 31 | public async Task DoByteArrayArg() 32 | { 33 | var array = new byte[] { 1, 2, 3 }; 34 | 35 | await this.Clients.All.SendAsync("DemoByteArrayArg", array); 36 | 37 | return array; 38 | } 39 | 40 | public Task DoMultipleArgs() 41 | { 42 | return this.Clients.All.SendAsync("DemoMultiArgs", "one", 2, "three", 4); 43 | } 44 | 45 | public Task DoMultipleArgsComplex() 46 | { 47 | return this.Clients.All.SendAsync("DemoMultiArgs2", new DemoData { Id = 1, Data = "Demo Data", DecimalData = 0.000000001M, DateTime = DateTime.UtcNow, Bool = true }, 48 | Enumerable.Range(1, 10).Select(x => new DemoData { Id = x, Data = $"Demo Data #{x}", DecimalData = x * 0.000000001M, DateTime = DateTime.UtcNow.AddSeconds(-x), Bool = (x % 2 == 0) }).ToList()); 49 | } 50 | 51 | public Task Send(string message) 52 | { 53 | return this.Clients.All.SendAsync("Send", $"{this.Context.ConnectionId}: {message}"); 54 | } 55 | 56 | public Task SendToOthers(string message) 57 | { 58 | return this.Clients.Others.SendAsync("Send", $"{this.Context.ConnectionId}: {message}"); 59 | } 60 | 61 | public Task SendToConnection(string connectionId, string message) 62 | { 63 | return this.Clients.Client(connectionId).SendAsync("Send", $"Private message from {this.Context.ConnectionId}: {message}"); 64 | } 65 | 66 | public Task SendToGroup(string groupName, string message) 67 | { 68 | return this.Clients.Group(groupName).SendAsync("Send", $"{this.Context.ConnectionId}@{groupName}: {message}"); 69 | } 70 | 71 | public Task SendToOthersInGroup(string groupName, string message) 72 | { 73 | return this.Clients.OthersInGroup(groupName).SendAsync("Send", $"{this.Context.ConnectionId}@{groupName}: {message}"); 74 | } 75 | 76 | public async Task JoinGroup(string groupName) 77 | { 78 | await this.Groups.AddToGroupAsync(this.Context.ConnectionId, groupName); 79 | 80 | await this.Clients.Group(groupName).SendAsync("Send", $"{this.Context.ConnectionId} joined {groupName}"); 81 | } 82 | 83 | public async Task LeaveGroup(string groupName) 84 | { 85 | await this.Clients.Group(groupName).SendAsync("Send", $"{this.Context.ConnectionId} left {groupName}"); 86 | 87 | await this.Groups.RemoveFromGroupAsync(this.Context.ConnectionId, groupName); 88 | } 89 | 90 | public Task Echo(string message) 91 | { 92 | return this.Clients.Caller.SendAsync("Send", $"{this.Context.ConnectionId}: {message}"); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.SignalR.Test.Server/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | 8 | namespace Blazor.Extensions.SignalR.Test.Server 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | BuildWebHost(args).Run(); 15 | } 16 | 17 | public static IWebHost BuildWebHost(string[] args) => 18 | WebHost.CreateDefaultBuilder(args) 19 | .UseConfiguration(new ConfigurationBuilder() 20 | .AddCommandLine(args) 21 | .Build()) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Blazor.Extensions.SignalR.Test.Server/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Blazor.Extensions.SignalR.Test.Server.Hubs; 5 | using Microsoft.AspNetCore.Authentication.JwtBearer; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore.Http; 9 | using Microsoft.AspNetCore.ResponseCompression; 10 | using Microsoft.AspNetCore.Routing; 11 | using Microsoft.Extensions.DependencyInjection; 12 | using Microsoft.IdentityModel.Tokens; 13 | using Newtonsoft.Json.Serialization; 14 | using System; 15 | using System.IdentityModel.Tokens.Jwt; 16 | using System.Linq; 17 | using System.Net.Mime; 18 | using System.Security.Claims; 19 | using System.Threading.Tasks; 20 | using Microsoft.Extensions.Hosting; 21 | using System.Text; 22 | 23 | namespace Blazor.Extensions.SignalR.Test.Server 24 | { 25 | public class Startup 26 | { 27 | public const string SECRET = "THIS IS OUR AWESOME SUPER SECRET!!!"; 28 | 29 | // This method gets called by the runtime. Use this method to add services to the container. 30 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 31 | public void ConfigureServices(IServiceCollection services) 32 | { 33 | services.AddConnections(); 34 | services 35 | .AddSignalR(options => options.KeepAliveInterval = TimeSpan.FromSeconds(5)) 36 | //.AddMessagePackProtocol(); 37 | .AddJsonProtocol(); 38 | 39 | services.AddAuthentication(opt => 40 | { 41 | opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 42 | opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 43 | }) 44 | .AddJwtBearer(opt => 45 | { 46 | opt.RequireHttpsMetadata = false; 47 | opt.SaveToken = true; 48 | opt.TokenValidationParameters = new TokenValidationParameters 49 | { 50 | ValidateIssuerSigningKey = true, 51 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SECRET)), 52 | ValidateIssuer = false, 53 | ValidateAudience = false 54 | }; 55 | opt.Events = new JwtBearerEvents 56 | { 57 | OnMessageReceived = context => 58 | { 59 | var accessToken = context.Request.Query["access_token"]; 60 | 61 | // If the request is for our hub... 62 | var path = context.HttpContext.Request.Path; 63 | if (!string.IsNullOrEmpty(accessToken) && 64 | (path.StartsWithSegments("/chathub"))) 65 | { 66 | // Read the token out of the query string 67 | context.Token = accessToken; 68 | } 69 | return Task.CompletedTask; 70 | } 71 | }; 72 | }); 73 | services.AddAuthorization(); 74 | 75 | services.Configure(options => 76 | { 77 | options.CheckConsentNeeded = context => true; 78 | options.MinimumSameSitePolicy = SameSiteMode.None; 79 | }); 80 | 81 | services.AddMvc(); 82 | 83 | services.AddResponseCompression(opts => 84 | { 85 | opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat( 86 | new[] { "application/octet-stream" }); 87 | }); 88 | } 89 | 90 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 91 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 92 | { 93 | app.UseResponseCompression(); 94 | 95 | if (env.IsDevelopment()) 96 | { 97 | app.UseDeveloperExceptionPage(); 98 | app.UseBlazorDebugging(); 99 | } 100 | else 101 | { 102 | app.UseExceptionHandler("/Error"); 103 | app.UseHsts(); 104 | } 105 | 106 | app.UseRouting(); 107 | 108 | app.UseAuthentication(); 109 | app.UseAuthorization(); 110 | 111 | app.UseClientSideBlazorFiles(); 112 | 113 | app.UseEndpoints(endpoints => 114 | { 115 | endpoints.MapDefaultControllerRoute(); 116 | endpoints.MapHub("/chathub"); 117 | endpoints.MapFallbackToClientSideBlazor("index.html"); 118 | }); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | <_ParentDirectoryBuildPropsPath Condition="'$(_DirectoryBuildPropsFile)' != ''">$([System.IO.Path]::Combine('..', '$(_DirectoryBuildPropsFile)')) 4 | 5 | 6 | 7 | 8 | 9 | false 10 | false 11 | $(NoWarn);1591 12 | 13 | 14 | 15 | 16 | $(TestProjectTargetFramework) 17 | 18 | 19 | 20 | 21 | full 22 | 23 | 24 | --------------------------------------------------------------------------------