MCPcopy
hub / github.com/ionic-team/capacitor / initBridge

Function initBridge

core/native-bridge.ts:142–1146  ·  view source on GitHub ↗
(w: any)

Source from the content-addressed store, hash-verified

140};
141
142const initBridge = (w: any): void => {
143 const getPlatformId = (win: WindowCapacitor): 'android' | 'ios' | 'web' => {
144 if (win?.androidBridge) {
145 return 'android';
146 } else if (win?.webkit?.messageHandlers?.bridge) {
147 return 'ios';
148 } else {
149 return 'web';
150 }
151 };
152
153 const convertFileSrcServerUrl = (webviewServerUrl: string, filePath: string): string => {
154 if (typeof filePath === 'string') {
155 if (filePath.startsWith('/')) {
156 return webviewServerUrl + '/_capacitor_file_' + filePath;
157 } else if (filePath.startsWith('file://')) {
158 return webviewServerUrl + filePath.replace('file://', '/_capacitor_file_');
159 } else if (filePath.startsWith('content://')) {
160 return webviewServerUrl + filePath.replace('content:/', '/_capacitor_content_');
161 }
162 }
163 return filePath;
164 };
165
166 const initEvents = (win: WindowCapacitor, cap: CapacitorInstance) => {
167 cap.addListener = (pluginName, eventName, callback) => {
168 const callbackId = cap.nativeCallback(
169 pluginName,
170 'addListener',
171 {
172 eventName: eventName,
173 },
174 callback,
175 );
176 return {
177 remove: async () => {
178 win?.console?.debug('Removing listener', pluginName, eventName);
179 cap.removeListener(pluginName, callbackId, eventName, callback);
180 },
181 };
182 };
183
184 cap.removeListener = (pluginName, callbackId, eventName, callback) => {
185 cap.nativeCallback(
186 pluginName,
187 'removeListener',
188 {
189 callbackId: callbackId,
190 eventName: eventName,
191 },
192 callback,
193 );
194 };
195
196 cap.createEvent = (eventName, eventData) => {
197 const doc = win.document;
198 if (doc) {
199 const ev = doc.createEvent('Events');

Callers 7

events.spec.tsFile · 0.90
runtime.spec.tsFile · 0.90
web-plugin.spec.tsFile · 0.90
bridge.spec.tsFile · 0.90
plugin.spec.tsFile · 0.90
native-bridge.tsFile · 0.70

Calls 1

initNativeBridgeFunction · 0.70

Tested by

no test coverage detected