JSTP is a data transfer protocol that uses JavaScript objects syntax as the encoding format and supports metadata. This implementation currently supports this types of packet:
- handshake — protocol handshake
- callback — remote API response
- inspect — API introspection request
- stream — data streaming
- health — system data about resource state and usage
- event — event with attached data
- state — data synchronization
- call — remote API call
First thing is to import the framework. See the Installation instructions on how to add the framework to your project.
import JSTP
Once imported, you can open a connection to your JSTP server. Note that connection
is probably best as a property, so it doesn't get deallocated right after being setup.
connection = Connection(host: "0.0.0.0", port: 6969, secure: false)
connection.delegate = self
connection.connect()
After you are connected, there are some optional delegate methods you may want to implement.
This method is called as soon as the client connects to the server.
func connectionDidConnect(_ connection: Connection) {
print("Connected")
}
This method is called as soon as the client is disconnected from the server.
func connectionDidDisconnect(_ connection: Connection) {
print("Disconnected")
}
This method is called as soon as some error occurs.
func connection(_ connection: Connection, didFailWithError error: NSError)
print("Error \(error.localizedDescription)")
}
This method is called as soon as the client receives some event.
func connection(_ connection: Connection, didReceiveEvent event: Event) { {
print("Event")
}
Event is simple class.
class Event {
let arguments: Any
let interface: String
let name: String
}
Framework works with iOS 7 or above. It is recommended to use iOS 8 or above for CocoaPods/framework support. To use it with a project targeting iOS 7, you must include all Swift files directly in your project.
Check out the Carthage docs on how to add a install. The JSTP
framework is already setup with shared schemes. To integrate JSTP into your Xcode project using Carthage, specify it in your Cartfile
:
github "JSTPMobile/iOS"
Run carthage update
, and you should now have the latest version of JSTP in your Carthage folder.
Check out Get Started tab on cocoapods.org.
To use JSTP
in your project add the following Podfile
to your project
pod 'JSTP', :git => 'https://github.com/JSTPMobile/iOS.git', :submodules => true
Then run:
pod install
Simply grab the framework (either via git submodule or another package manager).
Add the JSTP.xcodeproj
to your Xcode project. Once that is complete, in your "Build Phases" add the JSTP.framework
to your "Link Binary with Libraries" phase.
JSTP is licensed under the MIT License.