Top Banner
Hyperloop + Socket.io Appcelerator Titanium [email protected]
16

Appcelerator TitaniumでSocket.io (1.x)

Apr 16, 2017

Download

Technology

Toshiro Yagi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Appcelerator TitaniumでSocket.io (1.x)

Hyperloop + Socket.ioAppcelerator Titanium

[email protected]

Page 2: Appcelerator TitaniumでSocket.io (1.x)

Agenda

• Titanium と Socket.IO• Hyperloop 、挑戦と挫折• Hyperloop 復活• Hyperloop 活用の勘所

Page 3: Appcelerator TitaniumでSocket.io (1.x)

Titanium と Socket.IO

• Socket.IO ~0.9.x  よくある Websocket• 対応モジュール多数

• Socket.IO 1.0~    独自のプトロコルを採用• Swift で書かれたクライアントライブラリしか用意されていない• 対応モジュール無し• https://github.com/socketio/socket.io/issues/1590

• じゃあ作ろう

Page 4: Appcelerator TitaniumでSocket.io (1.x)

最初の試み: Hyperloop

• Hyperloop は Swift を扱うことができる• Swift クライアントをビルドした結果…

Page 5: Appcelerator TitaniumでSocket.io (1.x)

最初の試み: Hyperloop

• Hyperloop は Swift を扱うことができる• Swift クライアントをビルドした結果… エラー

• build directory の設定ができない• use of undeclared type ~

• 完全敗北

Page 6: Appcelerator TitaniumでSocket.io (1.x)

次の試み: Framework + Obj-C モジュール• Swift で書かれた部分を Framwork として Obj-C アプリに転用

• Swift では Static ライブラリが作成できないので Framework に• Framework は Obj-C で書いたモジュールから呼び出す

Page 7: Appcelerator TitaniumでSocket.io (1.x)

次の試み: Framework + Obj-C モジュール• Swift で書かれた部分を Framwork として Obj-C アプリに転用

• Swift では Static ライブラリが作成できないので Framework に• Framework は Obj-C で書いたモジュールから呼び出す

• 結果:  Carthoge で Framework を作成、モジュールからの呼び出し OK

Page 8: Appcelerator TitaniumでSocket.io (1.x)

次の試み: Framework + Obj-C モジュール• Swift で書かれた部分を Framwork として Obj-C アプリに転用

• Swift では Static ライブラリが作成できないので Framework に• Framework は Obj-C で書いたモジュールから呼び出す

• 結果:  Carthoge で Framework を作成、モジュールからの呼び出し OK• ただし:  Xcode からでないとビルドできない

Page 9: Appcelerator TitaniumでSocket.io (1.x)

考えた• Swift のコードはそのままでは使えない

• Framework にすると使える• Framework は動作する

• モジュールも作った• Embedded Binary として Xcode で手動で設定しないといけない

• ビルドの度に Xcode を開くなんて負け犬のやることだ

Page 10: Appcelerator TitaniumでSocket.io (1.x)

最大の壁• Embedded Binary として Xcode で手動で設定しないといけない

• ここをなんとかすればいい

Page 11: Appcelerator TitaniumでSocket.io (1.x)

突破口はいつもだいたいマニュアルから• なぜか modules/android/hyperloop/1.2.0/documentation/ にある

Adding a third-party frameworkIf you'd like to add a third-party framework which isn't distributed with source code or available in CocoaPods, you can use this example configuration:javascript module.exports = { hyperloop: { ios: { xcodebuild: { flags: { FRAMEWORK_SEARCH_PATHS: '/path/to/framework' }, frameworks: [ 'FrameworkName' ] } } } };In the above example, /path/to/framework should point the the location of the .framework file and FrameworkName should be the name of the Framework.

Page 12: Appcelerator TitaniumでSocket.io (1.x)

最終兵器 appc.js

• xcodebuild のオプションを設定できる xcodebuild: { flags: { LD_RUNPATH_SEARCH_PATHS: "$(inherited) @executable_path/../" } }

Page 13: Appcelerator TitaniumでSocket.io (1.x)

DEMO

• (感動と拍手)

Page 14: Appcelerator TitaniumでSocket.io (1.x)

備考• デフォルトでは Swift が有効にならない

• appc.js に適当な Swift の設定を仕込んでおく• 使わない Swift のコードを置いておく

• 今回は Obj-C でモジュールを書いたが逆にここを Swift にする手もある• Framework の wrapper クラスだけ Swift で書いて JS から呼び出す

Page 15: Appcelerator TitaniumでSocket.io (1.x)

まとめ• ActionCable を備えた Rails 5 が発表された翌日に敢えて

Socket.io

Page 16: Appcelerator TitaniumでSocket.io (1.x)

まとめ• Titanium は Obj-C アプリを生成するが Swift も扱える

• Swift のコードは Framework として利用出来る• 今後 Swift (のみ)で書かれたライブラリは増えるはず• 今回の手法を参考に試してみてください

• Hyperloop はそれほど万能でもない• 何も考えず使うのは難しい

• Hyperloop はそれほど使い道がないわけじゃない• xcodebuild の設定を変更することが可能になった

• 次は Phoenix に対応する予定• https://github.com/davidstump/SwiftPhoenixClient