All Projects → moozzyk → Signalr Client Swift

moozzyk / Signalr Client Swift

Licence: mit
Swift SignalR Client for Asp.Net Core SignalR server

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Signalr Client Swift

SignalR-Core-SqlTableDependency
Shows how the new SignalR Core works with hubs and sockets, also how it can integrate with SqlTableDependency API.
Stars: ✭ 36 (-83.1%)
Mutual labels:  asp-net-core, signalr
xamarin-chat-signalr
Xamarin Forms Modern Chat Using SignalR ASP.NET
Stars: ✭ 12 (-94.37%)
Mutual labels:  asp-net-core, signalr
AngularAspNetCoreSignalR
Build a simple chat app with Angular and ASP.NET Core SignalR
Stars: ✭ 12 (-94.37%)
Mutual labels:  asp-net-core, signalr
live-share-editor
ソースコードをリアルタイムで共有できるオンラインエディタ
Stars: ✭ 15 (-92.96%)
Mutual labels:  asp-net-core, signalr
Practical Aspnetcore
Practical samples of ASP.NET Core 2.1, 2.2, 3.1, 5.0 and 6.0 projects you can use. Readme contains explanations on all projects.
Stars: ✭ 6,199 (+2810.33%)
Mutual labels:  hacktoberfest, asp-net-core
Notify.Me
Simple host application to provide send/receive feature for any kind of notifications and messages between client(s) and the host. The application is based on ASP.NET Core and SignalR to demostrate some features of these things...
Stars: ✭ 28 (-86.85%)
Mutual labels:  asp-net-core, signalr
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-87.79%)
Mutual labels:  asp-net-core, signalr
Sio.core
✔ [ SIOC ] Swastika I/O Core is an all in one platform (e.g CMS, eCommerce, Forum, Q&A, CRM...) ASP.NET Core / Dotnet Core System based on SIOH Framework.
Stars: ✭ 121 (-43.19%)
Mutual labels:  asp-net-core, signalr
Exceptionless.net
Exceptionless clients for the .NET platform
Stars: ✭ 362 (+69.95%)
Mutual labels:  hacktoberfest, asp-net-core
Umbraco Cms
The simple, flexible and friendly ASP.NET CMS used by more than 730.000 websites
Stars: ✭ 3,484 (+1535.68%)
Mutual labels:  hacktoberfest, asp-net-core
Signalrsample
Real-time Charts with ASP.NET Core SignalR and Chart.js.
Stars: ✭ 23 (-89.2%)
Mutual labels:  asp-net-core, signalr
Scrutor
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
Stars: ✭ 1,915 (+799.06%)
Mutual labels:  hacktoberfest, asp-net-core
Ach
ACH implements a reader, writer, and validator for Automated Clearing House (ACH) files. The HTTP server is available in a Docker image and the Go package is available.
Stars: ✭ 210 (-1.41%)
Mutual labels:  hacktoberfest
Vue Morris
VueJS component wrapping Morris.js
Stars: ✭ 212 (-0.47%)
Mutual labels:  hacktoberfest
Bookmarks
🔖 +4.3K awesome resources for geeks and software crafters 🍺
Stars: ✭ 210 (-1.41%)
Mutual labels:  hacktoberfest
Tldr
Golang command line client for tldr https://github.com/tldr-pages/tldr
Stars: ✭ 210 (-1.41%)
Mutual labels:  hacktoberfest
Aquila
🎨 An Advanced WordPress theme
Stars: ✭ 204 (-4.23%)
Mutual labels:  hacktoberfest
Cve Bin Tool
This tool scans for a number of common, vulnerable components (openssl, libpng, libxml2, expat and a few others) to let you know if your system includes common libraries with known vulnerabilities.
Stars: ✭ 211 (-0.94%)
Mutual labels:  hacktoberfest
Pixieditor
PixiEditor is a lightweight pixel art editor made with .NET 5
Stars: ✭ 210 (-1.41%)
Mutual labels:  hacktoberfest
Opensourceresources
Free opensource Learning Resources related to Web-Development A to Z 🔥❤
Stars: ✭ 210 (-1.41%)
Mutual labels:  hacktoberfest

SwiftSignalRClient

A Swift SignalR Client for the Asp.Net Core version of SignalR

Before filing an issue please check Frequently Asked Questions

Installation

Cocoapods

Add the following lines to your Podfile:

use_frameworks!
pod 'SwiftSignalRClient'

Then run:

pod install

Swift Package Manager

Add the following to your Package dependencies:

.package(url: "https://github.com/moozzyk/SignalR-Client-Swift", .upToNextMinor(from: "0.6.0")),

Then include "SignalRClient" in your target dependencies. For example:

.target(name: "MySwiftPackage", dependencies: ["SignalRClient"]),

Carthage

Add the following lines to your Cartfile:

github "moozzyk/SignalR-Client-Swift"

Then run:

carthage update

Usage

Add import SwiftSignalRClient (or import SignalRClient if you are using Swift Package Manager) to swift files you would like to use the client in.

A typical implementation looks like the following:

import Foundation
import SwiftSignalRClient

public class SignalRService {
    private var connection: HubConnection
    
    public init(url: URL) {
        connection = HubConnectionBuilder(url: url).withLogging(minLogLevel: .error).build()
        connection.on(method: "MessageReceived", callback: { (user: String, message: String) in
            do {
                self.handleMessage(message, from: user)
            } catch {
                print(error)
            }
        })
        
        connection.start()
    }
    
    private func handleMessage(_ message: String, from user: String) {
        // Do something with the message.
    }
}

More detailed user's guide:

Examples

There are several sample projects in the Examples folder. They include:

  • SignalRClient.xcworkspace

    An Xcode workspace that has compiled libraries for macOS (OSX) and iOS, along with the Application targets 'ConnectionSample', 'HubSample', and 'HubSamplePhone'.

  • TestServer

    A .Net solution that the unit tests and samples can be run against.

    The TestServer Requires .NET Core SDK 3.0.100 or later.

    To run, navigate to the TestServer folder and execute the following in the terminal:

    npm install
    
    dotnet run
    

Migration from versions before 0.6.0

The way of handling serialization/deserialization of values sent/received from the server changed in version 0.6.0. The TypeConverter protocol has been removed in favor of the Encodable/Decodable protocols. The client now can serialize and send to the server any value that conforms to the Encodable protocol and is able to deserialize any value received from the server as long as the target type for the value conforms to the Decodable protocol (in most cases you don't need to distinguish between these protocols and you can just make your types conform to the Codable protocol. Also primitive types already conform to the Codable protocol so they work out of the box). One of the consequences of this change is that the signature of the client side method handlers changed and the code needs to be adjusted when moving to the version 0.6.0. Here is how:

Before version 0.6.0 registering a handler for the client side method could look like this:

self.chatHubConnection!.on(method: "NewMessage", callback: {args, typeConverter in
    let user = try! typeConverter.convertFromWireType(obj: args[0], targetType: String.self)
    let message = try! typeConverter.convertFromWireType(obj: args[1], targetType: String.self)
    self.appendMessage(message: "\(user!): \(message!)")
})

After installing version 0.6.0 or newer it needs to be changed to:

self.chatHubConnection!.on(method: "NewMessage", callback: {(user: String, message: String) in
    self.appendMessage(message: "\(user): \(message)")
})

Here is the summary of the changes:

  • remove the typeConverter parameter
  • replace args parameter with a list of actual parameters (make sure to provide parameter types)
  • remove calls to typeConverter methods
  • remove code to handle optional types (if applicabale)

Note: if your client side method takes more than 8 parameters you will need to use a lower level primitve to add a handler for this method.

Version 0.6.0 also adds some syntactic sugar for the APIs to invoke server side hub methods (i.e. invoke, send, stream). This is not a breaking change - the old methods will continue to work but in version 0.6.0 you can now pass the values as separate arguments instead of creating an array which is much nicer. For instance nvoking a hub method:

chatHubConnection?.invoke(method: "Broadcast", arguments: [name, message]) { error in
    if let e = error {
        self.appendMessage(message: "Error: \(e)")
    }
}

can now be changed to:

chatHubConnection?.invoke(method: "Broadcast", name, message) { error in
    if let e = error {
        self.appendMessage(message: "Error: \(e)")
    }
}

The new APIs support up to 8 parameters. If you have a hub method taking more than 8 parameters you will need to use a lower level primitives that take an array containing parameter values.

Disclaimer

I am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook)

Hits

HitCount

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].