oiawo
oiawo

Reputation: 145

How can I use cordova-plugin-advanced-websocket with Capacitor?

How can I use the following cordova plugin in a ionic/capacitor project?
cordova-plugin-advanced-websocket

I did: npm install cordova-plugin-advanced-websocket

And then tried the following to access it:

I also found the cordova-plugin-advanced-websocket-types plugin : npm i --save-dev cordova-plugin-advanced-websocket-types. But I did not get more luck :

import {
  CordovaWebsocketOptions
} from 'cordova-plugin-advanced-websocket-types';
const wsOptions: CordovaWebsocketOptions = {...};
window.CordovaWebsocketPlugin.wsConnect(wsOptions, ...)

-> I get the same error: Property 'CordovaWebsocketPlugin' does not exist on type 'Window & typeof globalThis'.

I thought about importing this way:
import { CordovaWebsocketPlugin } from 'cordova-plugin-advanced-websocket/www/plugin'
-> but I get the error: Module not found: Error: Can't resolve 'cordova/exec' in '...\node_modules\cordova-plugin-advanced-websocket\www'.
After reading about this I realise that this is not the right way anyway.


I need to find a solution to implement secured websocket with self-signed certificates (this is a hard pre-requisite, the security is handled by being on a secured network) on ionic/ios+android+web. My failed attempt with websocket on iOS have been leading me to use a capacitor/cordova plugin.

I am using the latest version of both ionic and capacitor : "ionic": "^5.4.16" "@capacitor/cli": "3.3.1"

Upvotes: 0

Views: 1231

Answers (1)

Callan
Callan

Reputation: 1233

Might be stupid but did you try (window as any).CordovaWebsocketPlugin.wsConnect(...) ?

For some reason I did this with facebook pixel tracking and it worked for me. Give it a try!

Upvotes: 0

Related Questions