Git Product home page Git Product logo

react-native-swift-socketio's Introduction

🚨this library is not maintained anymore!

A React Native wrapper for the Socket.io Swift Library

The wrapped 'Socket.IO-Client-Swift' can be found here.

Example

I've also added a super simple example app to /examples, copy and paste to your index.ios.js.

/**
 * Pass in an optional config obj, this can include most of the
 * standard props supported by the swift library
 */
var socketConfig = { path: '/socket' };
var socket = new SocketIO('localhost:3000', socketConfig);

// Connect!
socket.connect();

// An event to be fired on connection to socket
socket.on('connect', () => {
    console.log('Wahey -> connected!');
});

// Event called when 'someEvent' it emitted by server
socket.on('someEvent', (data) => {
    console.log('Some event was called, check out this data: ', data);
});

// Called when anything is emitted by the server
socket.onAny((event) => {
    console.log(`${event.name} was called with data: `, event.items);
});

// Manually join namespace
socket.joinNamespace()

// 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);

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

Constructor

Requires: host - example: 'localhost:3000'

Optional: config - JSON object comprising any of the options listed below.

Config

  • connectParams: Any Object - Any data to be sent with the connection.
  • reconnects: Boolean Default is true
  • reconnectAttempts: Int Default is -1 (infinite tries)
  • reconnectWait: Number Default is 10
  • forcePolling: Boolean Default is false. true forces the client to use xhr-polling.
  • forceWebsockets: Boolean Default is false. true forces the client to use WebSockets.
  • nsp: String Default is "/". Connects to a namespace.
  • log: Bool If true socket will log debug messages. Default is false.
  • path: String - If the server uses a custom path. ex: "/swift". Default is ""

Not supported yet but easy enough to implement.

  • cookies: [NSHTTPCookie]? An array of NSHTTPCookies. Passed during the handshake. Default is nil.
  • sessionDelegate: NSURLSessionDelegate Sets an NSURLSessionDelegate for the underlying engine. Useful if you need to handle self-signed certs. Default is nil.

Methods

  • connect - Connect to socket
  • on - Add event handler to socket
    • @param - String - event name
    • @param - Function - callback
  • onAny - Add event handler to any event
    • @param - Function - callback
  • emit - Emit an event to server
    • @param - String - Event name
    • @param - Anything - Data to be sent
  • close - Close the connection
    • @param - Boolean - should close fast?
  • reconnect - Reconnect to a closed connection
  • joinNamespace - Manually join namespace
  • leaveNamespace - Leave namespace, back to '/'

Known issues

  • Would rather this in an xcode framework but run into non-modular header issue.

Install

  • Run in your project:
$ npm install react-native-swift-socketio
  • Open up your project in xcode and right click the package.
  • Click Add files to 'Your project name'
  • Navigate to /node_modules/react-native-swift-socketio/RNSwiftSocketIO
  • Click 'Add'
  • 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

... That should do it! Please let me know of any issues ...

react-native-swift-socketio's People

Contributors

kirkness avatar nicinabox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-swift-socketio's Issues

Undefined is not an object

this.socket = new SocketIO('http://myserver.com:3000/', {secure: true}); this.socket.on('connect', () => { this.socket.emit('authentication', { token: this.state.valid, id_user: this.state.id });

Seems like NativeModule don't have Socket class, so it's throwing undefined error. I tried checking up bridges and exports but no luck.

only Ios?

This is only IOS? I want to use socket on Android ,How can i do?

Actual and formal argument lists differ in length

Hello,

I am facing the following problem while using the socketio library in Android:
public class SocketIoReadableNativeMap extends ReadableNativeMap {

required: HybridData
found: no arguments
reason: actual and formal argument lists differ in length

Anybody happen to have any pointers?
Much obliged :)

unable to import package

import 'react-native-swift-socketio';

displays an error
Unable to resolve module Nativemodules from ...

Needs code migration for xcode7

Hi,

I tried to open this porject in xcode 7 it has a requirement to translate to swift 2.0 version.
Can you please update the project to support swift 2.0?.

-Thanks and Regards
Manjunath

How to fix: opening import file for module 'Swift': Permission denied

Hi,

I have problem when compiling the project using this library, it show the error:

opening import file for module 'Swift': Permission denied
Does anyone has any suggestion?

Before that I had another problem “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift...
I fixed by turn "Use Legacy Swift Language Version" to YES. Does it has any impact with above problem?

Thanks in advance.

Crashing on reload

I get this crash in XCode when trying to reload the simulator. After commenting things out down the line it appears to happen only when calling emit. It seems like most of the stack runs through the Swift client code, so I'm not really sure if this is the right place for this issue.

2015-07-07 13:06:31.515 CuraMessenger[61768:4708747] *** Assertion failure in -[RCTBatchedBridge modules](), /Users/nic/work/CuraMessenger/node_modules/react-native/React/Base/RCTBridge.m:1085
2015-07-07 13:06:31.558 CuraMessenger[61768:4708747] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Bridge modules have not yet been initialized. You may be trying to access a module too early in the startup procedure.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c4fbc65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010b96bbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010c4fbaca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010b580a57 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 169
    4   CuraMessenger                       0x000000010b12826c -[RCTBatchedBridge modules] + 252
    5   CuraMessenger                       0x000000010b14d738 -[RCTBridge(RCTEventDispatcher) eventDispatcher] + 40
    6   CuraMessenger                       0x000000010b0ab600 _TFC13CuraMessenger8SocketIOP33_FC225C2DD54A6DEB206E1AA5A57BED5B17onAnyEventHandlerfS0_FCS_14SocketAnyEventT_ + 272
    7   CuraMessenger                       0x000000010b0921e7 _TTRXFo_oC13CuraMessenger14SocketAnyEvent_dT__XFo_iS0__iT__ + 23
    8   CuraMessenger                       0x000000010b08e9d1 _TPA__TTRXFo_oC13CuraMessenger14SocketAnyEvent_dT__XFo_iS0__iT__ + 81
    9   CuraMessenger                       0x000000010b091de0 _TTRXFo_iC13CuraMessenger14SocketAnyEvent_iT__XFo_oS0__dT__ + 32
    10  CuraMessenger                       0x000000010b091d74 _TFFC13CuraMessenger14SocketIOClient11handleEventFS0_FTSS4dataGSqGSaPSs9AnyObject___17isInternalMessageSb8wantsAckGSqSi__T_U_FT_T_ + 484
    11  CuraMessenger                       0x000000010b04ce37 _TTRXFo__dT__XFdCb__dT__ + 39
    12  libdispatch.dylib                   0x000000011009e186 _dispatch_call_block_and_release + 12
    13  libdispatch.dylib                   0x00000001100bd614 _dispatch_client_callout + 8
    14  libdispatch.dylib                   0x00000001100a5a1c _dispatch_main_queue_callback_4CF + 1664
    15  CoreFoundation                      0x000000010c4631f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    16  CoreFoundation                      0x000000010c424dcb __CFRunLoopRun + 2043
    17  CoreFoundation                      0x000000010c424366 CFRunLoopRunSpecific + 470
    18  GraphicsServices                    0x00000001107eba3e GSEventRunModal + 161
    19  UIKit                               0x000000010e2158c0 UIApplicationMain + 1282
    20  CuraMessenger                       0x000000010b04681f main + 111
    21  libdyld.dylib                       0x00000001100f1145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Swift Sintax Error

screen shot 2017-05-23 at 4 49 28 pm


screen shot 2017-05-23 at 4 53 23 pm

Needs last xcode version ?.

Some way to make it work without needing to update the xcode?

Attempting to use with React Native 0.6.0-rc

Perhaps I should stay off the RC, but I thought I should let you know about this anyway. There are a couple of issues.

Unknown argument type 'NSObject' in method -[SocketIO emit:items:]. Extend RCTConvert to support this type.

and

SocketIO.emit was called with 2 arguments, but expects 1

I suspect the first might clear up the latter? Might be related to this line?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.