Erik Little 176986d22a
Merge branch 'development'
* development: (31 commits)
  Add note about namespace methods
  Add note in changelog to checkout the migration guide
  Add more to the migration guide
  don't return optional from defaultSocket
  Add link to 12to13 and style
  Start working on a migration guide
  Fix #855
  refactor SocketIOClient.handlePacket
  bump version
  Do we really need to update carthage?
  Make sure to turn off logging in setup
  Don't use NSDictionary in definitions
  Fix tests
  Fix changelog
  update starscream versions
  nsp should be readonly now
  Add SocketManager for multiplexing namespaces
  Change sentPing/gotPong to ping/pong since those are already reserved
  Fix comment
  Add ability to track ping/pongs
  ...
2017-11-12 11:34:49 -05:00
2017-10-05 19:16:53 -04:00
2017-05-06 14:41:50 -04:00
2017-09-19 20:15:47 -04:00
2017-10-21 18:04:38 -04:00
2017-10-21 18:04:38 -04:00
2015-03-12 19:59:49 +09:00
2017-10-07 11:12:47 -04:00
2017-10-21 18:04:38 -04:00
2017-11-10 09:26:17 -05:00
2017-10-22 11:07:20 -04:00

Build Status

Socket.IO-Client-Swift

Socket.IO-client for iOS/OS X.

Example

import SocketIO

let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress])
let socket = manager.defaultSocket

socket.on(clientEvent: .connect) {data, ack in
    print("socket connected")
}

socket.on("currentAmount") {data, ack in
    guard let cur = data[0] as? Double else { return }
    
    socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in
        socket.emit("update", ["amount": cur + 2.50])
    }

    ack.with("Got your currentAmount", "dude")
}

socket.connect()

Objective-C Example

@import SocketIO;

NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"];
SocketManager* manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @YES, @"compress": @YES}];
SocketIOClient* socket = manager.defaultSocket;

[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
    NSLog(@"socket connected");
}];

[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
    double cur = [[data objectAtIndex:0] floatValue];

    [[socket emitWithAck:@"canUpdate" with:@[@(cur)]] timingOutAfter:0 callback:^(NSArray* data) {
        [socket emit:@"update" with:@[@{@"amount": @(cur + 2.50)}]];
    }];

    [ack with:@[@"Got your currentAmount, ", @"dude"]];
}];

[socket connect];

Features

  • Supports socket.io 2.0+ (For socket.io 1.0 use v9.x)
  • Supports binary
  • Supports Polling and WebSockets
  • Supports TLS/SSL
  • Can be used from Objective-C

FAQS

Checkout the FAQs for commonly asked questions.

Checkout the 12to13 guide for migrating to v13.

Installation

Requires Swift 4/Xcode 9.x

If you need Swift 2.3 use the swift2.3 tag (Pre-Swift 4 support is no longer maintained)

If you need Swift 3.x use v11.1.3.

Swift Package Manager

Add the project as a dependency to your Package.swift:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
    name: "socket.io-test",
    products: [
        .executable(name: "socket.io-test", targets: ["YourTargetName"])
    ],
    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "13.0.0"))
    ],
    targets: [
        .target(name: "YourTargetName", dependencies: ["SocketIO"], path: "./Path/To/Your/Sources")
    ]
)

Then import import SocketIO.

Carthage

Add this line to your Cartfile:

github "socketio/socket.io-client-swift" ~> 13.0.0 # Or latest version

Run carthage update --platform ios,macosx.

Add the Starscream and SocketIO frameworks to your projects and follow the usual Carthage process.

CocoaPods 1.0.0 or later

Create Podfile and add pod 'Socket.IO-Client-Swift':

use_frameworks!

target 'YourApp' do
    pod 'Socket.IO-Client-Swift', '~> 13.0.0' # Or latest version
end

Install pods:

$ pod install

Import the module:

Swift:

import SocketIO

Objective-C:

@import SocketIO;

Docs

Detailed Example

A more detailed example can be found here

An example using the Swift Package Manager can be found here

License

MIT

Description
No description provided
Readme Multiple Licenses 4.2 MiB
Languages
Swift 99.3%
Ruby 0.5%
Objective-C 0.2%