/titanium-socketio

Socket.io client for Titanium

Primary LanguageObjective-CApache License 2.0Apache-2.0

Socket.io client for Titanium

Socket.IO module for Titanium using native Android and iOS clients.

Requirements

  • Titanium SDK 7.0.0+
  • iOS: Swift 4.1

NOTE: The iOS module is built with Swift 4.1. Because of Swift's still missing ABI Stability (work in progress), you need to have the same Swift version installed that is used by the Swift-based framework, in this case Starscream.framework. You can check your current Swift version by using swift -v from the Terminal.

Getting started

Install the module to you project or globally by copying it into the modules folder. After that enable it in your tiapp.xml.

<modules>
    <module platform="android">ti.socketio</module>
    <module platform="iphone">ti.socketio</module>
</modules>

Usage

This module aims to be as compatible with the web client as possible. Please refer to the Client API for a full API documentation of all supported methods.

const io = require('ti.socketio');
const socket = io.connect('http://localhost:8080');
socket.on('connect', function() {
    Ti.API.debug('socket connected');

    socket.emit('hello', 'world');
});

Currently supported methods are:

  • io([url][, options]) (exposed as connect)
  • socket.open()
  • socket.connect()
  • socket.emit(eventName[, ...args][, ack])
  • socket.on(eventName, callback) (Note: Using acknowledgement callbacks not supported yet)
  • socket.off([eventName], [fn])
  • socket.close()
  • socket.disconnect()

You can pass the option keys from both JS and native when creating a new socket. But only options that are actually supported on the native side will be converted to the matching configuration option. For example the JS query option will be converted to the connectionParams option in the native iOS framework.

Useful links

Based on the socket.io-client-java on Android and socket.io-client.swift on iOS.

Contributions

Open source contributions are greatly appreciated! If you have a bugfix, improvement or new feature, please create an issue first and submit a pull request against master.

Getting Help

If you have questions about the Socket.IO module for Titanium, feel free to reach out on Stackoverflow or the #helpme channel on TiSlack. In case you find a bug, create a new issue or open a new JIRA ticket.

License

Apache License, Version 2.0