WXBridgeManager.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #import <Foundation/Foundation.h>
  20. #import <JavaScriptCore/JavaScriptCore.h>
  21. @class WXBridgeMethod;
  22. @class WXSDKInstance;
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. void WXPerformBlockOnBridgeThread(void (^block)(void));
  27. #ifdef __cplusplus
  28. }
  29. #endif
  30. @interface WXBridgeManager : NSObject
  31. /**
  32. * return instance at the top of the stack.
  33. **/
  34. @property (nonatomic, weak, readonly) WXSDKInstance *topInstance;
  35. /**
  36. * Create Instance Method
  37. * @param instance : instance id
  38. * @param temp : template data
  39. * @param options : parameters
  40. * @param data : external data
  41. **/
  42. - (void)createInstance:(NSString *)instance
  43. template:(NSString *)temp
  44. options:(NSDictionary *)options
  45. data:(id)data;
  46. /**
  47. * Create Instance with opcode
  48. * @param instance : instance id
  49. * @param contents : opcode data
  50. * @param options : parameters
  51. * @param data : external data
  52. **/
  53. - (void)createInstance:(NSString *)instance
  54. contents:(NSData *)contents
  55. options:(NSDictionary *)options
  56. data:(id)data;
  57. /**
  58. * @abstract return currentInstanceId
  59. **/
  60. - (NSArray *)getInstanceIdStack;
  61. /**
  62. * Destroy Instance Method
  63. * @param instance : instance id
  64. **/
  65. - (void)destroyInstance:(NSString *)instance;
  66. /**
  67. * Trigger full GC, for dev and debug only.
  68. **/
  69. - (void)forceGarbageCollection;
  70. /**
  71. * Refresh Instance Method
  72. * @param instance : instance id
  73. * @param data : external data
  74. **/
  75. - (void)refreshInstance:(NSString *)instance data:(id)data;
  76. /**
  77. * Unload
  78. **/
  79. - (void)unload;
  80. /**
  81. * Update Instance State Method
  82. * @param instance : instance id
  83. * @param data : parameters
  84. **/
  85. - (void)updateState:(NSString *)instance data:(id)data;
  86. /**
  87. * Execute JSFramework Script
  88. * @param script : script code
  89. **/
  90. - (void)executeJsFramework:(NSString *)script;
  91. /**
  92. * Register JS service Script
  93. * @param name : service name
  94. * @param serviceScript : script code
  95. * @param options : service options
  96. * @param completion : completion callback
  97. **/
  98. - (void)registerService:(NSString *)name withService:(NSString *)serviceScript withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
  99. /**
  100. * Register JS service Script
  101. * @param name : service name
  102. * @param serviceScriptUrl : script url
  103. * @param options : service options
  104. * @param completion : completion callback
  105. **/
  106. -(void)registerService:(NSString *)name withServiceUrl:(NSURL *)serviceScriptUrl withOptions:(NSDictionary *)options completion:(void(^)(BOOL result))completion;
  107. /**
  108. * Unregister JS service Script
  109. * @param name : script code
  110. **/
  111. - (void)unregisterService:(NSString *)name;
  112. /**
  113. * Register Modules Method
  114. * @param modules : module list
  115. **/
  116. - (void)registerModules:(NSDictionary *)modules;
  117. /**
  118. * Register Components Method
  119. * @param components component list
  120. **/
  121. - (void)registerComponents:(NSArray* )components;
  122. /**
  123. * FireEvent
  124. * @param instanceId instance id
  125. * @param ref : node reference
  126. * @param type : event type
  127. * @param params : parameters in event object
  128. * @param domChanges dom value changes, used for two-way data binding
  129. **/
  130. - (void)fireEvent:(NSString *)instanceId ref:(NSString *)ref type:(NSString *)type params:(NSDictionary *)params domChanges:(NSDictionary *)domChanges;
  131. /**
  132. * FireEvent
  133. * @param instanceId instance id
  134. * @param ref : node reference
  135. * @param type : event type
  136. * @param params : parameters in event object
  137. * @param domChanges dom value changes, used for two-way data binding
  138. * @param handlerArguments : arguments passed to event handler
  139. **/
  140. - (void)fireEvent:(NSString *)instanceId ref:(NSString *)ref type:(NSString *)type params:(NSDictionary *)params domChanges:(NSDictionary *)domChanges handlerArguments:(NSArray *)handlerArguments;
  141. - (JSValue *)fireEventWithResult:(NSString *)instanceId ref:(NSString *)ref type:(NSString *)type params:(NSDictionary *)params domChanges:(NSDictionary *)domChanges;
  142. /**
  143. * componentHook
  144. * @param instanceId : instance id
  145. * @param componentId : compoent id
  146. * @param type : component hook Type, such as life-cycle
  147. * @param hookPhase : hook phase
  148. */
  149. - (void)callComponentHook:(NSString*)instanceId componentId:(NSString*)componentId type:(NSString*)type hook:(NSString*)hookPhase args:(NSArray*)args competion:(void (^)(JSValue * value))complection;
  150. /**
  151. * callBack
  152. *
  153. * @param instanceId instanceId
  154. * @param funcId funcId
  155. * @param params params
  156. * @param keepAlive indicate that whether this func will be reused
  157. */
  158. - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)params keepAlive:(BOOL)keepAlive;
  159. /**
  160. * Connect To WebSocket for devtool debug
  161. * @param url : url to connect
  162. **/
  163. - (void)connectToDevToolWithUrl:(NSURL *)url;
  164. /**
  165. * CallBack
  166. * @param instanceId instance id
  167. * @param funcId : callback id
  168. * @param params : parameters
  169. **/
  170. - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)params;
  171. /**
  172. * Connect To WebSocket for collecting log
  173. * @param url : url to connect
  174. **/
  175. - (void)connectToWebSocket:(NSURL *)url;
  176. /**
  177. * Log To WebSocket
  178. * @param flag : the tag to identify
  179. * @param message : message to output
  180. **/
  181. - (void)logToWebSocket:(NSString *)flag message:(NSString *)message;
  182. /**
  183. * Reset Environment
  184. **/
  185. - (void)resetEnvironment;
  186. - (void)fireEvent:(NSString *)instanceId ref:(NSString *)ref type:(NSString *)type params:(NSDictionary *)params DEPRECATED_MSG_ATTRIBUTE("Use fireEvent:ref:type:params:domChanges: method instead.");
  187. - (void)executeJsMethod:(WXBridgeMethod *)method DEPRECATED_MSG_ATTRIBUTE();
  188. @end