Skip to content

Updated Project to XCode7+ and Socket.Io Swift client release 6.1.1 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
node_modules/**/*
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
#
.idea
.gradle
local.properties
*.apk
*.ap_
*.class
*.iml
*.log
gen/

# node.js
#
node_modules/
npm-debug.log
coverage/
docs/
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# A React Native wrapper for the Socket.io Swift Library
# A React Native wrapper for the Socket.io Library

The wrapped 'Socket.IO-Client-Swift' can be [found here](https://github.com/socketio/socket.io-client-swift).
This project was forked from Kirkness' React Native Swift Socket.Io project
[found here](https://github.com/kirkness/react-native-swift-socketio)

Going forward, I will split from Kirkness' project so that it will
include the Java Swift Socket.Io project as well. The point is to have one entry point into
Socket.Io for both platforms.

* The wrapped 'Socket.IO-Client-Swift' can be [found here](https://github.com/socketio/socket.io-client-swift).

* The wrapped 'Socket.IO-Client-Java' can be [found here](https://github.com/socketio/socket.io-client-java).

### Example
I've also added a super simple example app to /examples, copy and paste to your index.ios.js.
Expand Down Expand Up @@ -30,20 +39,20 @@ socket.onAny((event) => {
console.log(`${event.name} was called with data: `, event.items);
});

// Manually join namespace
socket.joinNamespace()
// Manually join namespace. Ex: namespace is now partyRoom
socket.joinNamespace('partyRoom')

// Leave namespace, back to '/'
socket.leaveNamespace()

// Emit an event to server
socket.emit('helloWorld', {some: 'data'});

// Optional boolean param 'fast' - defaults to false
socket.close(true);
//Disconnect from server
socket.disconnect();

// Reconnect to a closed socket
socket.reconect();
socket.reconnect();
```

### Constructor
Expand Down Expand Up @@ -107,6 +116,9 @@ $ npm install react-native-swift-socketio
- Click your project in the navigator on the left and go to **build settings**
- Search for **Objective-C Bridging Header**
- Double click on the empty column
- Enter **node_modules/react-native-swift-socketio/RNSwiftSocketIO/SocketBridge.h**
- Enter **../node_modules/react-native-swift-socketio/RNSwiftSocketIO/SocketBridge.h**
- Search for **Header Search Paths**
- Double Click on the column (likely has other search paths in it already)
- Enter this text at the bottom of the column $(SRCROOT)/../node_modules/react-native-swift-socketio/RNSwiftSocketIO

... That should do it! Please let me know of any issues ...
116 changes: 73 additions & 43 deletions RNSwiftSocketIO.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

14 changes: 7 additions & 7 deletions RNSwiftSocketIO/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
class SocketIO: NSObject {

var socket: SocketIOClient!
var connectionSocket: String!
var connectionSocket: NSURL!
var bridge: RCTBridge!

/**
Expand All @@ -28,12 +28,12 @@ class SocketIO: NSObject {
*/

@objc func initialise(connection: String, config: NSDictionary) -> Void {
connectionSocket = connection
connectionSocket = NSURL(string: connection);

// Connect to socket with config
self.socket = SocketIOClient(
socketURL: self.connectionSocket,
opts:config as? [String : AnyObject]
options:config as? [String : AnyObject]
)

// Initialise onAny events
Expand All @@ -44,8 +44,8 @@ class SocketIO: NSObject {
* Manually join the namespace
*/

@objc func joinNamespace() {
self.socket.joinNamespace();
@objc func joinNamespace(namespace: String) -> Void {
self.socket.joinNamespace(namespace);
}

/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class SocketIO: NSObject {
}

// Disconnect from socket
@objc func close(fast: Bool) -> Void {
self.socket.close(fast: fast)
@objc func disconnect() -> Void {
self.socket.disconnect()
}
}
4 changes: 2 additions & 2 deletions RNSwiftSocketIO/SocketBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ @interface RCT_EXTERN_MODULE(SocketIO, NSObject)
RCT_EXTERN_METHOD(initialise:(NSString*)connection config:(NSDictionary*)config)
RCT_EXTERN_METHOD(addHandlers:(NSDictionary*)handlers)
RCT_EXTERN_METHOD(connect)
RCT_EXTERN_METHOD(close:(BOOL)fast)
RCT_EXTERN_METHOD(disconnect)
RCT_EXTERN_METHOD(reconnect)
RCT_EXTERN_METHOD(emit:(NSString*)event items:(id)items)
RCT_EXTERN_METHOD(joinNamespace)
RCT_EXTERN_METHOD(joinNamespace:(NSString *)namespace)
RCT_EXTERN_METHOD(leaveNamespace)

@end
31 changes: 31 additions & 0 deletions RNSwiftSocketIO/SocketIOClient/NSCharacterSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NSCharacterSet.swift
// Socket.IO-Client-Swift
//
// Created by Yannick Loriot on 5/4/16.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Foundation

extension NSCharacterSet {
class var allowedURLCharacterSet: NSCharacterSet {
return NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]\" {}").invertedSet
}
}
6 changes: 5 additions & 1 deletion RNSwiftSocketIO/SocketIOClient/SocketAckEmitter.swift
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

public final class SocketAckEmitter: NSObject {
public final class SocketAckEmitter : NSObject {
let socket: SocketIOClient
let ackNum: Int

Expand All @@ -34,10 +34,14 @@ public final class SocketAckEmitter: NSObject {
}

public func with(items: AnyObject...) {
guard ackNum != -1 else { return }

socket.emitAck(ackNum, withItems: items)
}

public func with(items: [AnyObject]) {
guard ackNum != -1 else { return }

socket.emitAck(ackNum, withItems: items)
}
}
2 changes: 1 addition & 1 deletion RNSwiftSocketIO/SocketIOClient/SocketAckManager.swift
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

private struct SocketAck: Hashable, Equatable {
private struct SocketAck : Hashable, Equatable {
let ack: Int
var callback: AckCallback!
var hashValue: Int {
Expand Down
Loading