### Build the Solution Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md After restoring packages, use this command to build the solution. This command is used when Mono is installed. ```sh xbuild pusher-dotnet-server.sln ``` -------------------------------- ### Install PusherServer NuGet Package Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use the following command to install the PusherServer NuGet package into your .NET project. ```powershell Install-Package PusherServer ``` -------------------------------- ### Configure Pusher with End-to-End Encryption Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Initializes the Pusher client with an encryption master key and enables the encrypted feature. This setup is required for end-to-end encrypted channels. ```cs Pusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions { Cluster = Config.Cluster, EncryptionMasterKey = encryptionMasterKey, Encrypted = true, }); ``` -------------------------------- ### Client-Side Event Data Size Limit Detection Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md This example shows how to configure the Pusher client with a data size limit and handle the `EventDataSizeExceededException` when an event's data exceeds the limit before it's sent to the server. ```csharp IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost, BatchEventDataSizeLimit = PusherOptions.DEFAULT_BATCH_EVENT_DATA_SIZE_LIMIT, // 10KB }); try { var events = new[] { new Event {Channel = "channel-1", EventName = "event-1", Data = "hello world"}, new Event {Channel = "channel-2", EventName = "event-2", Data = new string('Q', 10 * 1024 + 1)}, }; await pusher.TriggerAsync(events).ConfigureAwait(false); } catch (EventDataSizeExceededException eventDataSizeError) { // Handle the error when event data exceeds 10KB } ``` -------------------------------- ### Initialize Pusher Client with Options Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Configure and initialize the Pusher client with your application's credentials and optional settings like cluster and encryption. For best practice, reuse this instance as a singleton. ```csharp var options = new PusherOptions { Cluster = APP_CLUSTER, Encrypted = true, }; var pusher = new Pusher(APP_ID, APP_KEY, APP_SECRET, options); ``` -------------------------------- ### Configure Pusher with Debug Tracing Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Enable debug tracing for the Pusher library by configuring the TraceLogger option during Pusher instantiation. ```cs IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost, TraceLogger = new DebugTraceLogger(), }); ``` -------------------------------- ### Restore NuGet Packages Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use this command to restore NuGet packages for the solution. Ensure you are in the root directory of the solution. ```sh nuget restore pusher-dotnet-server.sln ``` -------------------------------- ### Asynchronous Trigger Event with Pusher Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use the async/await syntax to trigger events asynchronously with the Pusher library. This allows for concurrent operations. ```cs using PusherServer; var options = new PusherOptions(); options.Cluster = APP_CLUSTER; var pusher = new Pusher(APP_ID, APP_KEY, APP_SECRET, options); Task resultTask = pusher.TriggerAsync("my-channel", "my-event", new { message = "hello world" }); // You can do work here that doesn't rely on the result of TriggerAsync DoIndependentWork(); ITriggerResult result = await resultTask; ``` -------------------------------- ### Fetch Users from Presence Channel Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Retrieve a list of users currently on a presence channel. Specify the channel by its full path or by its name. ```cs IGetResult result = await pusher.FetchUsersFromPresenceChannelAsync("/channels/presence-channel/users"); ``` ```cs IGetResult result = await pusher.FetchUsersFromPresenceChannelAsync("my_channel"); ``` -------------------------------- ### Fetch State for Multiple Channels Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Retrieves the state for multiple channels. The `object` type is used as a placeholder for the response data. ```cs IGetResult result = await pusher.FetchStateForChannelsAsync(); ``` -------------------------------- ### Fetch All Channels Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Retrieves a list of all channels present in the application using the REST API. This can be filtered by prefix. ```cs IGetResult result = await pusher.GetAsync("/channels"); ``` ```cs IGetResult result = await pusher.FetchStateForChannelsAsync(); ``` ```cs IGetResult result = await _pusher.GetAsync( "/channels", new { filter_by_prefix = "presence-" }).ConfigureAwait(false); ``` ```cs IGetResult result = await pusher.FetchStateForChannelsAsync(new { filter_by_prefix = "presence-" }).ConfigureAwait(false); ``` -------------------------------- ### Trigger Events in Batches Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use this to send multiple events in a single request. Each event in the batch can target different channels and have different data. ```csharp var events = new[] { new Event {Channel = "channel-1", EventName = "event-1", Data = "hello world"}, new Event {Channel = "channel-2", EventName = "event-2", Data = "my name is bob"} }; ITriggerResult result = await pusher.TriggerAsync(events).ConfigureAwait(false); ``` -------------------------------- ### Authenticate Private Channels Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use this function to authorize users for private channels. The resulting JSON should be returned to the client for subscription validation. ```cs var auth = pusher.Authenticate(channelName, socketId); var json = auth.ToJson(); ``` -------------------------------- ### Fetch Single Channel Information Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Retrieves information about a specific channel using its name. The `object` type is used as a placeholder for the response data. ```cs IGetResult result = await pusher.GetAsync("/channels/my_channel" ); ``` ```cs IGetResult result = await pusher.FetchStateForChannelAsync("my_channel"); ``` -------------------------------- ### Trigger Event on Single Channel Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Use this snippet to trigger a single event on a specified channel. Ensure the Pusher object is properly initialized. ```csharp ITriggerResult result = await pusher.TriggerAsync("channel-1", "test_event", new { message = "hello world" }).ConfigureAwait(false); ``` -------------------------------- ### Authenticate Presence Channels with User Data Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Similar to private channels, but allows specifying extra user data for presence channels. The JSON output is used for client-side subscription validation. ```cs var channelData = new PresenceChannelData { user_id = "unique_user_id", user_info = new { name = "Phil Leggetter", twitter_id = "@leggetter", } }; var auth = pusher.Authenticate(channelName, socketId, channelData); var json = auth.ToJson(); ``` -------------------------------- ### Generate Encryption Master Key Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Generates a 32-byte master encryption key using `RandomNumberGenerator`. This key is essential for enabling end-to-end encryption and must be kept secret. ```cs byte[] encryptionMasterKey = new byte[32]; using (RandomNumberGenerator random = RandomNumberGenerator.Create()) { random.GetBytes(encryptionMasterKey); } ``` -------------------------------- ### Generate Pusher Signing Key Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Execute a PowerShell script to generate a new code signing key for PusherServer. This key is used for code signing and CI/CD processes. ```powershell ./StrongName/GeneratePusherKey.ps1 ``` -------------------------------- ### Process Pusher Webhook Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Validate and process incoming webhooks from Pusher. This involves checking the signature and iterating through events. ```cs // How you get these depends on the framework you're using // HTTP_X_PUSHER_SIGNATURE from HTTP Header var receivedSignature = "value"; // Body of HTTP request var receivedBody = "value"; var pusher = new Pusher(...); var webHook = pusher.ProcessWebHook(receivedSignature, receivedBody); if(webHook.IsValid) { // The Webhook validated // Dictionary[] var events = webHook.Events; foreach(var webHookEvent in webHook.Events) { var eventType = webHookEvent["name"]; var channelName = webHookEvent["channel"]; // depending on the type of event (eventType) // there may be other values in the Dictionary } } else { // Log the validation errors to work out what the problem is // webHook.ValidationErrors } ``` -------------------------------- ### Trigger Event on Multiple Channels Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md This code triggers a single event across multiple channels simultaneously. Provide an array of channel names. ```csharp ITriggerResult result = await pusher.TriggerAsync( new string[] { "channel-1", "channel-2" }, "test_event", new { message = "hello world" }).ConfigureAwait(false); ``` -------------------------------- ### Trigger Event on Encrypted Channel Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md Triggers an event on a private encrypted channel. Ensure the channel name is prefixed with `private-encrypted-` and end-to-end encryption is enabled in Pusher options. ```cs await pusher.TriggerAsync("private-encrypted-my-channel", "my-event", new { message = "hello world" }).ConfigureAwait(false); ``` -------------------------------- ### Exclude Event Recipients Using SocketId Source: https://github.com/pusher/pusher-http-dotnet/blob/master/README.md This snippet demonstrates how to prevent the event originator from receiving the event by providing a `SocketId` in the `TriggerOptions`. This is useful for real-time updates where the sender doesn't need to see their own message. ```csharp ITriggerResult result = await pusher.TriggerAsync(channel, event, data, new TriggerOptions { SocketId = "1234.56" }).ConfigureAwait(false); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.