Permalink
Browse files

Bug fixes

- removed logs from libwebsockets
- fixed bug in Web/Remote library manager where the connectWebsocket message could be sent before the JS callbacks were created
- added a backlog to the CWServerManager that logs messages that arrive for the master before the master connection was established. As soon as the master websocket is established, the messages are delivered
- Fixed a bug in CWServerManager that could lead to lost messages if the master websocket was not the first websocket that connected

Numerous changes to the web library

- native-less remote can now connect without appending '/remote' to the URL - they will be detected and redirected automatically
- numerous methods that are part of CWDevice have been removed from the Connichiwa module - they should be accesses through CWDevice only (e.g. insert/replace/...). The logic for those methods has been moved to CWDevice
- Added CWModules. Every Connichiwa module has to add itself to CWModules and CWModules will take care of loading all the modules. This makes sure that modules that depend on each other are loaded correctly. Our build script makes sure that CWModules is added at the very beginning of connichiwa.js and remote.js, and therefore CWModules is ensured to be available. Further, the build script makes sure that init.js is added ad the very end of these files, so the initialization process is started after all modules have been added to CWModules.
- A number of bug fixes

Updated docs & readme
  • Loading branch information...
BlackWolf committed May 5, 2015
1 parent f2fb250 commit aa9047837df4700b5c65a5164697377620fd1a68
Showing with 2,583 additions and 2,290 deletions.
  1. +2 −2 Connichiwa.xcodeproj/project.pbxproj
  2. +19 −13 Connichiwa/BLWebSocketsServer/BLWebSocketsServer.m
  3. +7 −4 Connichiwa/CWRemoteLibraryManager.m
  4. +31 −5 Connichiwa/CWServerManager.m
  5. +34 −13 Connichiwa/CWWebLibraryManager.m
  6. +34 −7 ConnichiwaDocs/jsdoc/theme/static/styles/jsdoc-default.css
  7. +7 −2 ConnichiwaDocs/jsdoc/theme/tmpl/container.tmpl
  8. +3 −3 ConnichiwaDocs/jsdoc/theme/tmpl/members.tmpl
  9. +2 −2 ConnichiwaDocs/jsdoc/theme/tmpl/method.tmpl
  10. +2 −2 ConnichiwaDocs/jsdoc/theme/tmpl/returns.tmpl
  11. +1 −1 ConnichiwaDocs/native/docset-installed.txt
  12. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/BLWebSocketConnection.html
  13. +1 −22 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/BLWebSocketsServer.html
  14. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBluetoothConnection.html
  15. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBluetoothManager.html
  16. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBluetoothTransferCentralKey.html
  17. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBluetoothTransferManager.html
  18. +1 −1 ...hiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBluetoothTransferPeripheralKey.html
  19. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWBundle.html
  20. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWDebug.html
  21. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWRemoteLibraryManager.html
  22. +22 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWServerManager.html
  23. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWUtil.html
  24. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWWebApplication.html
  25. +22 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWWebLibraryManager.html
  26. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/CWiDevice.html
  27. +78 −78 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServer.html
  28. +31 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerBodyDecoder.html
  29. +1 −26 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerBodyEncoder.html
  30. +41 −41 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerConnection.html
  31. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerDataRequest.html
  32. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerDataResponse.html
  33. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerErrorResponse.html
  34. +2 −65 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerFileRequest.html
  35. +64 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerFileResponse.html
  36. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerGZipDecoder.html
  37. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerGZipEncoder.html
  38. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerHandler.html
  39. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerMIMEStreamParser.html
  40. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerMultiPart.html
  41. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerMultiPartArgument.html
  42. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerMultiPartFile.html
  43. +32 −2 ...hiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerMultiPartFormRequest.html
  44. +32 −2 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerRequest.html
  45. +1 −26 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerResponse.html
  46. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerStreamedResponse.html
  47. +1 −22 ...iwaDocs/native/docset/Contents/Resources/Documents/Classes/GCDWebServerURLEncodedFormRequest.html
  48. +1 −1 ...aDocs/native/docset/Contents/Resources/Documents/Constants/CWBluetoothConnectionIPWriteState.html
  49. +1 −1 ...s/native/docset/Contents/Resources/Documents/Constants/CWBluetoothConnectionInitialDataState.html
  50. +1 −1 ...ichiwaDocs/native/docset/Contents/Resources/Documents/Constants/CWBluetoothConnectionMCState.html
  51. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Constants/CWRemoteLibraryManagerState.html
  52. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Constants/CWServerManagerState.html
  53. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Constants/CWWebLibraryManagerState.html
  54. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Constants/CWiDeviceModel.html
  55. +1 −1 ...s/native/docset/Contents/Resources/Documents/Constants/GCDWebServerClientErrorHTTPStatusCode.html
  56. +1 −1 ...native/docset/Contents/Resources/Documents/Constants/GCDWebServerInformationalHTTPStatusCode.html
  57. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Constants/GCDWebServerLoggingLevel.html
  58. +1 −1 ...s/native/docset/Contents/Resources/Documents/Constants/GCDWebServerRedirectionHTTPStatusCode.html
  59. +1 −1 ...s/native/docset/Contents/Resources/Documents/Constants/GCDWebServerServerErrorHTTPStatusCode.html
  60. +1 −1 ...cs/native/docset/Contents/Resources/Documents/Constants/GCDWebServerSuccessfulHTTPStatusCode.html
  61. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/CWBluetoothManagerDelegate.html
  62. +1 −1 ...Docs/native/docset/Contents/Resources/Documents/Protocols/CWBluetoothTransferManagerDelegate.html
  63. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/CWServerManagerDelegate.html
  64. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/CWWebApplicationState.html
  65. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/CWWebLibraryManagerDelegate.html
  66. +1 −26 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/GCDWebServerBodyReader.html
  67. +31 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/GCDWebServerBodyWriter.html
  68. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/Protocols/GCDWebServerDelegate.html
  69. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/hierarchy.html
  70. +1 −1 ConnichiwaDocs/native/docset/Contents/Resources/Documents/index.html
  71. +36 −0 ConnichiwaDocs/native/docset/Contents/Resources/Tokens11.xml
  72. +12 −0 ConnichiwaDocs/native/docset/Contents/Resources/Tokens14.xml
  73. +254 −254 ConnichiwaDocs/native/docset/Contents/Resources/Tokens16.xml
  74. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens17.xml
  75. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens18.xml
  76. +84 −84 ConnichiwaDocs/native/docset/Contents/Resources/Tokens19.xml
  77. +0 −36 ConnichiwaDocs/native/docset/Contents/Resources/Tokens2.xml
  78. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens32.xml
  79. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens33.xml
  80. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens34.xml
  81. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens42.xml
  82. +3 −3 ConnichiwaDocs/native/docset/Contents/Resources/Tokens43.xml
  83. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.dsidx
  84. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.dsidx-shm
  85. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.dsidx-wal
  86. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.skidx
  87. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.toc
  88. BIN ConnichiwaDocs/native/docset/Contents/Resources/docSet.tokencache
  89. +1 −1 ConnichiwaDocs/native/html/Classes/BLWebSocketConnection.html
  90. +1 −22 ConnichiwaDocs/native/html/Classes/BLWebSocketsServer.html
  91. +1 −1 ConnichiwaDocs/native/html/Classes/CWBluetoothConnection.html
  92. +1 −1 ConnichiwaDocs/native/html/Classes/CWBluetoothManager.html
  93. +1 −1 ConnichiwaDocs/native/html/Classes/CWBluetoothTransferCentralKey.html
  94. +1 −1 ConnichiwaDocs/native/html/Classes/CWBluetoothTransferManager.html
  95. +1 −1 ConnichiwaDocs/native/html/Classes/CWBluetoothTransferPeripheralKey.html
  96. +1 −1 ConnichiwaDocs/native/html/Classes/CWBundle.html
  97. +1 −1 ConnichiwaDocs/native/html/Classes/CWDebug.html
  98. +1 −1 ConnichiwaDocs/native/html/Classes/CWRemoteLibraryManager.html
  99. +22 −1 ConnichiwaDocs/native/html/Classes/CWServerManager.html
  100. +1 −1 ConnichiwaDocs/native/html/Classes/CWUtil.html
  101. +1 −1 ConnichiwaDocs/native/html/Classes/CWWebApplication.html
  102. +22 −1 ConnichiwaDocs/native/html/Classes/CWWebLibraryManager.html
  103. +1 −1 ConnichiwaDocs/native/html/Classes/CWiDevice.html
  104. +78 −78 ConnichiwaDocs/native/html/Classes/GCDWebServer.html
  105. +31 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerBodyDecoder.html
  106. +1 −26 ConnichiwaDocs/native/html/Classes/GCDWebServerBodyEncoder.html
  107. +41 −41 ConnichiwaDocs/native/html/Classes/GCDWebServerConnection.html
  108. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerDataRequest.html
  109. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerDataResponse.html
  110. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerErrorResponse.html
  111. +2 −65 ConnichiwaDocs/native/html/Classes/GCDWebServerFileRequest.html
  112. +64 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerFileResponse.html
  113. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerGZipDecoder.html
  114. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerGZipEncoder.html
  115. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerHandler.html
  116. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerMIMEStreamParser.html
  117. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerMultiPart.html
  118. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerMultiPartArgument.html
  119. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerMultiPartFile.html
  120. +32 −2 ConnichiwaDocs/native/html/Classes/GCDWebServerMultiPartFormRequest.html
  121. +32 −2 ConnichiwaDocs/native/html/Classes/GCDWebServerRequest.html
  122. +1 −26 ConnichiwaDocs/native/html/Classes/GCDWebServerResponse.html
  123. +1 −1 ConnichiwaDocs/native/html/Classes/GCDWebServerStreamedResponse.html
  124. +1 −22 ConnichiwaDocs/native/html/Classes/GCDWebServerURLEncodedFormRequest.html
  125. +1 −1 ConnichiwaDocs/native/html/Constants/CWBluetoothConnectionIPWriteState.html
  126. +1 −1 ConnichiwaDocs/native/html/Constants/CWBluetoothConnectionInitialDataState.html
  127. +1 −1 ConnichiwaDocs/native/html/Constants/CWBluetoothConnectionMCState.html
  128. +1 −1 ConnichiwaDocs/native/html/Constants/CWRemoteLibraryManagerState.html
  129. +1 −1 ConnichiwaDocs/native/html/Constants/CWServerManagerState.html
  130. +1 −1 ConnichiwaDocs/native/html/Constants/CWWebLibraryManagerState.html
  131. +1 −1 ConnichiwaDocs/native/html/Constants/CWiDeviceModel.html
  132. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerClientErrorHTTPStatusCode.html
  133. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerInformationalHTTPStatusCode.html
  134. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerLoggingLevel.html
  135. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerRedirectionHTTPStatusCode.html
  136. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerServerErrorHTTPStatusCode.html
  137. +1 −1 ConnichiwaDocs/native/html/Constants/GCDWebServerSuccessfulHTTPStatusCode.html
  138. +1 −1 ConnichiwaDocs/native/html/Protocols/CWBluetoothManagerDelegate.html
  139. +1 −1 ConnichiwaDocs/native/html/Protocols/CWBluetoothTransferManagerDelegate.html
  140. +1 −1 ConnichiwaDocs/native/html/Protocols/CWServerManagerDelegate.html
  141. +1 −1 ConnichiwaDocs/native/html/Protocols/CWWebApplicationState.html
  142. +1 −1 ConnichiwaDocs/native/html/Protocols/CWWebLibraryManagerDelegate.html
  143. +1 −26 ConnichiwaDocs/native/html/Protocols/GCDWebServerBodyReader.html
  144. +31 −1 ConnichiwaDocs/native/html/Protocols/GCDWebServerBodyWriter.html
  145. +1 −1 ConnichiwaDocs/native/html/Protocols/GCDWebServerDelegate.html
  146. +1 −1 ConnichiwaDocs/native/html/hierarchy.html
  147. +1 −1 ConnichiwaDocs/native/html/index.html
  148. +23 −18 ConnichiwaDocs/weblib/CWDebug.html
  149. +66 −61 ConnichiwaDocs/weblib/CWDevice.html
  150. +18 −13 ConnichiwaDocs/weblib/CWDeviceManager.html
  151. +25 −20 ConnichiwaDocs/weblib/CWGyroscope.html
  152. +87 −82 ConnichiwaDocs/weblib/CWLocation.html
  153. +34 −29 ConnichiwaDocs/weblib/CWStitchManager.html
  154. +35 −30 ConnichiwaDocs/weblib/CWSystemInfo.html
  155. +44 −39 ConnichiwaDocs/weblib/CWUtil.html
  156. +33 −28 ConnichiwaDocs/weblib/CWVector.html
  157. +38 −33 ConnichiwaDocs/weblib/Connichiwa.html
  158. +4 −4 ConnichiwaDocs/weblib/common_CWDebug.js.html
  159. +99 −12 ConnichiwaDocs/weblib/common_CWDevice.js.html
  160. +3 −4 ConnichiwaDocs/weblib/common_CWGyroscope.js.html
  161. +1 −1 ConnichiwaDocs/weblib/common_CWLocation.js.html
  162. +3 −4 ConnichiwaDocs/weblib/common_CWStitchManager.js.html
  163. +4 −4 ConnichiwaDocs/weblib/common_CWSystemInfo.js.html
  164. +4 −4 ConnichiwaDocs/weblib/common_CWUtil.js.html
  165. +1 −1 ConnichiwaDocs/weblib/common_CWVector.js.html
  166. +17 −126 ConnichiwaDocs/weblib/common_Connichiwa.js.html
  167. +1 −1 ConnichiwaDocs/weblib/common_DocTypes.js.html
  168. +1 −1 ConnichiwaDocs/weblib/common_EventTypes.js.html
  169. +27 −22 ConnichiwaDocs/weblib/global.html
  170. +1 −1 ConnichiwaDocs/weblib/index.html
  171. +5 −7 ConnichiwaDocs/weblib/master_CWDevice.js.html
  172. +5 −7 ConnichiwaDocs/weblib/master_CWDeviceManager.js.html
  173. +4 −2 ConnichiwaDocs/weblib/master_CWStitchManager.js.html
  174. +4 −2 ConnichiwaDocs/weblib/master_ConnichiwaMaster.js.html
  175. +34 −7 ConnichiwaDocs/weblib/styles/jsdoc-default.css
  176. +199 −187 ConnichiwaResources/weblib/connichiwa.js
  177. +2 −2 ConnichiwaResources/weblib/connichiwa.min.js
  178. +1 −1 ConnichiwaResources/weblib/connichiwa.min.js.map
  179. +187 −173 ConnichiwaResources/weblib/remote.js
  180. +1 −1 ConnichiwaResources/weblib/remote.min.js
  181. +1 −1 ConnichiwaResources/weblib/remote.min.js.map
  182. +32 −0 ConnichiwaResources/weblib_source/CWModules.js
  183. +2 −2 ConnichiwaResources/weblib_source/common/CWDebug.js
  184. +98 −11 ConnichiwaResources/weblib_source/common/CWDevice.js
  185. +2 −3 ConnichiwaResources/weblib_source/common/CWEventManager.js
  186. +3 −1 ConnichiwaResources/weblib_source/common/CWGestures.js
  187. +2 −3 ConnichiwaResources/weblib_source/common/CWGyroscope.js
  188. +8 −9 ConnichiwaResources/weblib_source/common/CWNativeBridge.js
  189. +2 −3 ConnichiwaResources/weblib_source/common/CWStitchManager.js
  190. +2 −2 ConnichiwaResources/weblib_source/common/CWSystemInfo.js
  191. +2 −2 ConnichiwaResources/weblib_source/common/CWUtil.js
  192. +4 −5 ConnichiwaResources/weblib_source/common/CWWebsocketMessageParser.js
  193. +16 −125 ConnichiwaResources/weblib_source/common/Connichiwa.js
  194. +1 −0 ConnichiwaResources/weblib_source/init.js
  195. +4 −6 ConnichiwaResources/weblib_source/master/CWDevice.js
  196. +4 −6 ConnichiwaResources/weblib_source/master/CWDeviceManager.js
  197. +7 −5 ConnichiwaResources/weblib_source/master/CWNativeBridge.js
  198. +3 −1 ConnichiwaResources/weblib_source/master/CWStitchManager.js
  199. +4 −2 ConnichiwaResources/weblib_source/master/CWWebsocketMessageParser.js
  200. +3 −1 ConnichiwaResources/weblib_source/master/ConnichiwaMaster.js
  201. +3 −1 ConnichiwaResources/weblib_source/remote/CWNativeBridge.js
  202. +6 −4 ConnichiwaResources/weblib_source/remote/CWWebsocketMessageParser.js
  203. +4 −2 ConnichiwaResources/weblib_source/remote/ConnichiwaRemote.js
  204. +2 −1 README.md
@@ -687,7 +687,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "PATH=$(bash -l -c 'echo $PATH')\n\nROOT_PATH=\"${PROJECT_DIR}/${PRODUCT_NAME}\"\nCONCAT_FILE=\"${ROOT_PATH}/weblib/remote.js\"\nCONCAT_FILE_MIN=\"${ROOT_PATH}/weblib/remote.min.js\"\nCONCAT_FILE_MAP=\"${CONCAT_FILE_MIN}.map\"\n\nrm -f ${CONCAT_FILE}\nrm -f ${CONCAT_FILE_MIN}\nrm -f ${CONCAT_FILE_MAP}\n\n# CONCATENATE\n# Concatenates everything in the weblib folder\n#cat \"${ROOT_PATH}/scripts/OOP.js\" >> ${CONCAT_FILE};\nfor file in \"${ROOT_PATH}/weblib_source/common/*.js\"; do cat $file >> ${CONCAT_FILE}; done\nfor file in \"${ROOT_PATH}/weblib_source/remote/*.js\"; do cat $file >> ${CONCAT_FILE}; done\n\n# MINIFY\n# Minifyjs needs to be installed (npm install -g minifyjs)\n#MINIFYJS_PATH=\"/usr/local/bin/minifyjs\"\n#if [ -x $MINIFYJS_PATH ]; then\n#if [ -f $CONCAT_FILE ]; then\n\n#${MINIFYJS_PATH} -m -i ${CONCAT_FILE} -o ${CONCAT_FILE_MIN}\n#fi\n#else\n#echo \"install minifyjs globally via npm to minify the remote library\"\n#fi;\n\n#UGLIFYJS\n# uglifyjs needs to be installed (npm install -g uglifyjs)\n# minifies the source file and creates a source map\nUGLIFYJS_PATH=\"uglifyjs\"\n#if [ -x $UGLIFYJS_PATH ]; then\nif [ -f $CONCAT_FILE ]; then\n\n${UGLIFYJS_PATH} ${CONCAT_FILE} -o ${CONCAT_FILE_MIN} --source-map ${CONCAT_FILE_MAP} --screw-ie8 --compress --mangle --prefix relative\n\nfi\n#else\n#echo \"install uglifyjs globally via npm to create minified JS library versions\"\n#fi;";
shellScript = "PATH=$(bash -l -c 'echo $PATH')\n\nROOT_PATH=\"${PROJECT_DIR}/${PRODUCT_NAME}\"\nCONCAT_FILE=\"${ROOT_PATH}/weblib/remote.js\"\nCONCAT_FILE_MIN=\"${ROOT_PATH}/weblib/remote.min.js\"\nCONCAT_FILE_MAP=\"${CONCAT_FILE_MIN}.map\"\n\nrm -f ${CONCAT_FILE}\nrm -f ${CONCAT_FILE_MIN}\nrm -f ${CONCAT_FILE_MAP}\n\n# CONCATENATE\n# Concatenates everything in the weblib folder\n#cat \"${ROOT_PATH}/scripts/OOP.js\" >> ${CONCAT_FILE};\ncat \"${ROOT_PATH}/weblib_source/CWModules.js\" >> ${CONCAT_FILE}\nfor file in \"${ROOT_PATH}/weblib_source/common/*.js\"; do cat $file >> ${CONCAT_FILE}; done\nfor file in \"${ROOT_PATH}/weblib_source/remote/*.js\"; do cat $file >> ${CONCAT_FILE}; done\ncat \"${ROOT_PATH}/weblib_source/init.js\" >> ${CONCAT_FILE}\n\n# MINIFY\n# Minifyjs needs to be installed (npm install -g minifyjs)\n#MINIFYJS_PATH=\"/usr/local/bin/minifyjs\"\n#if [ -x $MINIFYJS_PATH ]; then\n#if [ -f $CONCAT_FILE ]; then\n\n#${MINIFYJS_PATH} -m -i ${CONCAT_FILE} -o ${CONCAT_FILE_MIN}\n#fi\n#else\n#echo \"install minifyjs globally via npm to minify the remote library\"\n#fi;\n\n#UGLIFYJS\n# uglifyjs needs to be installed (npm install -g uglifyjs)\n# minifies the source file and creates a source map\nUGLIFYJS_PATH=\"uglifyjs\"\n#if [ -x $UGLIFYJS_PATH ]; then\nif [ -f $CONCAT_FILE ]; then\n\n${UGLIFYJS_PATH} ${CONCAT_FILE} -o ${CONCAT_FILE_MIN} --source-map ${CONCAT_FILE_MAP} --screw-ie8 --compress --mangle --prefix relative\n\nfi\n#else\n#echo \"install uglifyjs globally via npm to create minified JS library versions\"\n#fi;";
};
33163302193F722300EED43E /* Objective-Clean Run Script */ = {
isa = PBXShellScriptBuildPhase;
@@ -744,7 +744,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "PATH=$(bash -l -c 'echo $PATH')\n\nROOT_PATH=\"${PROJECT_DIR}/${PRODUCT_NAME}\"\nCONCAT_FILE=\"${ROOT_PATH}/weblib/connichiwa.js\"\nCONCAT_FILE_MIN=\"${ROOT_PATH}/weblib/connichiwa.min.js\"\nCONCAT_FILE_MAP=\"${CONCAT_FILE_MIN}.map\"\n\nrm -f ${CONCAT_FILE}\nrm -f ${CONCAT_FILE_MIN}\nrm -f ${CONCAT_FILE_MAP}\n\n# CONCATENATE\n# Concatenates everything in the weblib folder\n#cat \"${ROOT_PATH}/scripts/OOP.js\" >> ${CONCAT_FILE};\nfor file in \"${ROOT_PATH}/weblib_source/common/*.js\"; do cat $file >> ${CONCAT_FILE}; done\nfor file in \"${ROOT_PATH}/weblib_source/master/*.js\"; do cat $file >> ${CONCAT_FILE}; done\n\n#UGLIFYJS\n# uglifyjs needs to be installed (npm install -g uglifyjs)\n# minifies the source file and creates a source map\nUGLIFYJS_PATH=\"uglifyjs\"\n#if [ -x $UGLIFYJS_PATH ]; then\nif [ -f $CONCAT_FILE ]; then\n\n${UGLIFYJS_PATH} ${CONCAT_FILE} -o ${CONCAT_FILE_MIN} --source-map ${CONCAT_FILE_MAP} --screw-ie8 --compress --mangle --prefix relative\n\nfi\n#else\n#echo \"install uglifyjs globally via npm to create minified JS library versions\"\n#fi;";
shellScript = "PATH=$(bash -l -c 'echo $PATH')\n\nROOT_PATH=\"${PROJECT_DIR}/${PRODUCT_NAME}\"\nCONCAT_FILE=\"${ROOT_PATH}/weblib/connichiwa.js\"\nCONCAT_FILE_MIN=\"${ROOT_PATH}/weblib/connichiwa.min.js\"\nCONCAT_FILE_MAP=\"${CONCAT_FILE_MIN}.map\"\n\nrm -f ${CONCAT_FILE}\nrm -f ${CONCAT_FILE_MIN}\nrm -f ${CONCAT_FILE_MAP}\n\n# CONCATENATE\n# Concatenates everything in the weblib folder\n#cat \"${ROOT_PATH}/scripts/OOP.js\" >> ${CONCAT_FILE};\ncat \"${ROOT_PATH}/weblib_source/CWModules.js\" >> ${CONCAT_FILE}\nfor file in \"${ROOT_PATH}/weblib_source/common/*.js\"; do cat $file >> ${CONCAT_FILE}; done\nfor file in \"${ROOT_PATH}/weblib_source/master/*.js\"; do cat $file >> ${CONCAT_FILE}; done\ncat \"${ROOT_PATH}/weblib_source/init.js\" >> ${CONCAT_FILE}\n\n#UGLIFYJS\n# uglifyjs needs to be installed (npm install -g uglifyjs)\n# minifies the source file and creates a source map\nUGLIFYJS_PATH=\"uglifyjs\"\n#if [ -x $UGLIFYJS_PATH ]; then\nif [ -f $CONCAT_FILE ]; then\n\n${UGLIFYJS_PATH} ${CONCAT_FILE} -o ${CONCAT_FILE_MIN} --source-map ${CONCAT_FILE_MAP} --screw-ie8 --compress --mangle --prefix relative\n\nfi\n#else\n#echo \"install uglifyjs globally via npm to create minified JS library versions\"\n#fi;";
};
33D197D9194B3D2100AE1E1D /* Touch Folder References Script */ = {
isa = PBXShellScriptBuildPhase;
@@ -34,19 +34,21 @@ static int callback_http(struct libwebsocket_context *context,
static BLWebSocketsServer *sharedInstance = nil;
static dispatch_source_t timer;
static dispatch_queue_t networkQueue;
//static dispatch_source_t timer;
//static dispatch_queue_t networkQueue;
@interface BLWebSocketsServer()
@property (nonatomic, assign, readwrite) BOOL isRunning;
@property (nonatomic, retain) dispatch_source_t timer;
@property (nonatomic, retain) dispatch_queue_t networkQueue;
/* Context representing the server */
@property (nonatomic, assign) struct libwebsocket_context *context;
@property (nonatomic, strong, readwrite) BLWebSocketOnMessageHandler defaultOnMessageHandler;
@property (nonatomic, strong, readwrite) BLWebSocketOnCloseHandler defaultOnCloseHandler;
@property (nonatomic, strong, readwrite) NSMutableDictionary *connections;
@property (strong, readwrite) NSTimer *stopFastPollingTimer;
//@property (strong, readwrite) NSTimer *stopFastPollingTimer;
/* Temporary storage for the server stopped completion block */
@property (nonatomic, strong) void(^serverStoppedCompletionBlock)();
@@ -75,7 +77,7 @@ + (BLWebSocketsServer *)sharedInstance {
- (id)init {
self = [super init];
if (self) {
networkQueue = dispatch_queue_create(QUEUE_IDENTIFIER, DISPATCH_QUEUE_SERIAL);
self.networkQueue = dispatch_queue_create(QUEUE_IDENTIFIER, DISPATCH_QUEUE_SERIAL);
}
return self;
}
@@ -134,17 +136,17 @@ - (void)startListeningOnPort:(int)port withProtocolName:(NSString *)protocolName
error = [NSError errorWithDomain:errorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Couldn't create the libwebsockets context.", @"")}];
}
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, networkQueue);
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.networkQueue);
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1, 1);
dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 1, 1);
dispatch_source_set_event_handler(timer, ^{
dispatch_source_set_event_handler(self.timer, ^{
@autoreleasepool {
libwebsocket_service(self.context, DEFAULT_POLLING_INTERVAL);
}
});
dispatch_source_set_cancel_handler(timer, ^{
dispatch_source_set_cancel_handler(self.timer, ^{
dispatch_async(dispatch_get_main_queue(), ^{
self.isRunning = NO;
[self cleanup];
@@ -156,7 +158,7 @@ - (void)startListeningOnPort:(int)port withProtocolName:(NSString *)protocolName
completionBlock(error);
});
dispatch_resume(timer);
dispatch_resume(self.timer);
}
- (void)stopWithCompletionBlock:(void (^)())completionBlock {
@@ -168,7 +170,7 @@ - (void)stopWithCompletionBlock:(void (^)())completionBlock {
return;
}
else {
dispatch_source_cancel(timer);
dispatch_source_cancel(self.timer);
}
}
@@ -197,13 +199,13 @@ - (void)setOnCloseHandler:(BLWebSocketOnCloseHandler)handler forConnection:(int)
- (void)pushMessage:(NSData *)message toConnection:(int)connectionID {
BLWebSocketConnection *connection = [BLWebSocketsServer connectionForID:connectionID];
if (connection == nil) {
NSLog(@"LOST MESSAGE %@", [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]);
// NSLog(@"LOST MESSAGE %@", [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]);
return;
}
[connection enqueueOutgoingMessage:message];
//Make sure the new message is sent as soon as the socket is writable
dispatch_async(networkQueue, ^{
dispatch_async(self.networkQueue, ^{
libwebsocket_callback_on_writable(self.context, connection.socket);
});
}
@@ -214,7 +216,7 @@ - (void)pushMessageToAll:(NSData *)message {
}
//Make sure all connections call the writable callback when they are ready
dispatch_async(networkQueue, ^{
dispatch_async(self.networkQueue, ^{
libwebsocket_callback_on_writable_all_protocol(&(self.context->protocols[1]));
});
}
@@ -257,6 +259,8 @@ static int callback_websockets(struct libwebsocket_context * this,
case LWS_CALLBACK_ESTABLISHED: {
*connectionID = sharedInstance.sessionIdIncrementalCount++;
// NSLog(@"CREATING CONNECTION %d", *connectionID);
id connectionKey = [BLWebSocketsServer keyForConnectionID:*connectionID];
BLWebSocketConnection *connection = [[BLWebSocketConnection alloc] initWithID:*connectionID socket:wsi];
[sharedInstance.connections setObject:connection forKey:connectionKey];
@@ -288,6 +292,7 @@ static int callback_websockets(struct libwebsocket_context * this,
BLWebSocketConnection *connection = [BLWebSocketsServer connectionForID:*connectionID];
NSData *message = [connection dequeueOutgoingMessage];
if (message != nil) {
// NSLog(@"SENDING MESSAGE %@", [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]);
write_data_websockets(message, wsi);
//Make sure the rest of the message queue is processed
@@ -298,6 +303,7 @@ static int callback_websockets(struct libwebsocket_context * this,
case LWS_CALLBACK_CLOSED: {
//Call the onClose handler
BLWebSocketConnection *connection = [BLWebSocketsServer connectionForID:*connectionID];
// NSLog(@"CLOSED CONNECTION %d", *connectionID);
BLWebSocketOnCloseHandler callback = connection.onCloseHandler;
if (!callback) callback = sharedInstance.defaultOnCloseHandler;
if (callback) callback(*connectionID);
@@ -119,7 +119,7 @@ - (void)connectToServer:(NSURL *)URL
[self.webView setDelegate:self];
[self.webView setHidden:NO];
[self.webView loadRequest:URLRequest];
[self createWebViewContext];
// [self createWebViewContext];
});
}
@@ -269,7 +269,8 @@ - (void)webViewDidStartLoad:(UIWebView *)webView
//We need to tell the remote library it is run by a native application. This needs to be done ASAP (before the library loads).
//Therefore, we simply execute a script that sets a global variable to true. When the web library is loaded, it can check
//this variable and by that know that a native layer is running in the background.
self.webViewContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
// self.webViewContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
[self createWebViewContext];
NSString *js = [NSString stringWithFormat:@"var RUN_BY_CONNICHIWA_NATIVE = true;"];
[self.webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:js waitUntilDone:NO];
}
@@ -289,9 +290,9 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
//WebView's are a strange little thing - the JS context might or might not change between our load request and
//this point. Therefore, create the context again even though we already did so in connect:
[self createWebViewContext];
// [self createWebViewContext];
[self _registerJSCallbacks];
[self _sendToView_connectWebsocket];
}
else if (self.state == CWRemoteLibraryManagerStateDisconnecting)
@@ -308,6 +309,8 @@ -(void)createWebViewContext {
//Loaded a remote server URL, set up its context
self.webViewContext = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
[self _registerJSCallbacks];
//Register JS error handler
self.webViewContext.exceptionHandler = ^(JSContext *c, JSValue *e) {
dispatch_async(dispatch_get_main_queue(), ^{
@@ -29,6 +29,7 @@ @interface CWServerManager ()
@property (strong, readwrite) BLWebSocketsServer *websocketServer;
@property (readwrite) int localWebsocketID;
@property (strong, readwrite) NSMutableDictionary *websocketIdentifiers;
@property (nonatomic, strong, readwrite) NSMutableArray *masterBacklog;
/**
* Registers callback functions that the webserver script can call to execute native methods
@@ -60,6 +61,8 @@ - (instancetype)initWithDocumentRoot:(NSString *)documentRoot
self.state = CWServerManagerStateStopped;
self.documentRoot = documentRoot;
self.localWebsocketID = -1;
self.masterBacklog = [NSMutableArray array];
return self;
}
@@ -79,7 +82,7 @@ - (void)startWebserverWithDocumentRoot:(NSString *)documentRoot onPort:(int)port
//
self.webServer = [[GCDWebServer alloc] init];
[GCDWebServer setLogLevel:1];
[GCDWebServer setLogLevel:1];
//Set up all the path handlers of the webserver that will deliver our files
//Note that they are hand3560led in LIFO order, so the last handler will be checked first,
@@ -178,10 +181,12 @@ - (BLWebSocketOnMessageHandler)onUnidentifiedWebsocketMessage {
__weak typeof(self) weakSelf = self;
return ^void (int connectionID, NSData *messageData) {
// @synchronized(weakSelf) {
NSDictionary *message = [CWUtil dictionaryFromJSONData:messageData];
// NSLog(@"GOT MESSAGE %@", [[NSString alloc] initWithData:messageData encoding:NSUTF8StringEncoding]);
//If the message identifies the local weblib's websocket, save its ID
if ([[message objectForKey:@"_name"] isEqualToString:@"localinfo"]) {
// NSLog(@"SET LOCAL ID");
weakSelf.localWebsocketID = connectionID;
}
@@ -193,10 +198,27 @@ - (BLWebSocketOnMessageHandler)onUnidentifiedWebsocketMessage {
[weakSelf.websocketServer setOnMessageHandler:[weakSelf onIdentifiedWebsocketMessage] forConnection:connectionID];
[weakSelf.websocketServer setOnCloseHandler:[weakSelf onIdentifiedWebsocketClosed] forConnection:connectionID];
//Forward the message to the local weblibrary ., so it knows about the device
[weakSelf.websocketServer pushMessage:messageData toConnection:weakSelf.localWebsocketID];
//Forward the message to the local weblibrary so it knows about the device
//It might happen that we receive remoteinfo messages before localinfo messages
//(if they arrive between the websocket server starting and the localinfo message
//arriving). If this happens, backlog the messages and send them later
// NSLog(@"ID %d", weakSelf.localWebsocketID);
if (weakSelf.localWebsocketID != -1) {
[weakSelf.websocketServer pushMessage:messageData toConnection:weakSelf.localWebsocketID];
} else {
[self.masterBacklog addObject:messageData];
}
}
if ([[message objectForKey:@"_name"] isEqualToString:@"localinfo"]) {
//If we backlogged messages that arrived for the master before this
//point, send them now that the master has connected
for (NSData *backlogMessage in self.masterBacklog) {
// NSLog(@"SENDING BACKLOGGED MESSAGE %@", [[NSString alloc] initWithData:backlogMessage encoding:NSUTF8StringEncoding]);
[weakSelf.websocketServer pushMessage:backlogMessage toConnection:weakSelf.localWebsocketID];
}
}
// }
};
}
@@ -225,6 +247,7 @@ - (BLWebSocketOnCloseHandler)onIdentifiedWebsocketClosed {
return ^void (int connectionID) {
if (connectionID == self.localWebsocketID) {
ErrLog(@"ERROR! LOCAL WEBSOCKET CLOSED!");
//TODO: What to do here? This shouldn't happen!
} else {
//Find the remote websocket that was closed and report the close to our delegate
@@ -244,6 +267,9 @@ - (BLWebSocketOnCloseHandler)onIdentifiedWebsocketClosed {
- (int)connectionIDForIdentifier:(NSString *)targetIdentifier {
if ([targetIdentifier isEqualToString:@"master"]) {
return self.localWebsocketID;
}
return [[self.websocketIdentifiers objectForKey:targetIdentifier] intValue];
}
Oops, something went wrong.

0 comments on commit aa90478

Please sign in to comment.