danielsogl / awesome-cordova-plugins

Native features for mobile apps built with Cordova/PhoneGap and open web technologies. Complete with TypeScript support.
https://danielsogl.gitbook.io/awesome-cordova-plugins/
Other
2.41k stars 2.42k forks source link

Bug: Type Error in @ionic-native/web-socket-server #3420

Closed bcjat closed 3 years ago

bcjat commented 4 years ago

I'm submitting a ... [x] bug report [ ] feature request [ ] support request

Current behavior: When using types for cordova-plugin-websocket-server from @ionic-native/web-socket-server shows following error.

ERROR TypeError: window.cordova.plugins.wsserver[fnName] is not a function at Observable._subscribe (home-home-module-es2015.js:30) at Observable._trySubscribe (vendor-es2015.js:109405) at Observable.subscribe (vendor-es2015.js:109391) at HomePage.initServer (home-home-module-es2015.js:221) at Object.eval [as handleEvent] (HomePage.html:21) at handleEvent (vendor-es2015.js:74622) at callWithDebugContext (vendor-es2015.js:76241) at Object.debugHandleEvent [as handleEvent] (vendor-es2015.js:75876) at dispatchEvent (vendor-es2015.js:61709) at vendor-es2015.js:73554

the above error link to node_modules > @ionic-native > web-socket-server > ngx > index.js:14:22

Expected behavior: Should start local socket server.

Steps to reproduce: clone repository and run on emulator, using debugger the error will be shown.

Related code:

import { Component } from "@angular/core";
import { WebSocketServer } from "@ionic-native/web-socket-server/ngx";
import { Platform } from "@ionic/angular";

@Component({
  selector: "app-home",
  templateUrl: "home.page.html",
  styleUrls: ["home.page.scss"],
})
export class HomePage {
  constructor(private webserver: WebSocketServer, private platform: Platform) {
    this.platform.ready().then(() => {
     this.initServer();
    });
  }

  initServer() {
    this.webserver.start(8888, {}).subscribe({
      next: (server) =>
        console.log(`Listening on ${server.addr}:${server.port}`),
      error: (error) => {
        console.log("error occured: " + error);
      },
    });

    this.webserver.watchOpen().subscribe(
      (data) => {
        console.log(data);

    });
  }
}

Other information: full repository of sample app here

https://github.com/bcjat/local-web-socket.git

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.2 (C:\Users\bcjat\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 5.1.0
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 2.1.0
   @capacitor/core : 2.1.0

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v12.16.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.12.0
   OS     : Windows 10
nihalak commented 4 years ago

same problem here

nihalak commented 4 years ago

i read somwhere this can be solved using plain javascript , but how to do it in ionic react app

github-actions[bot] commented 3 years ago

There has been no recent activity and this issue has been marked inactive.

VirusBLITZ commented 1 year ago

same issue here, has this been resolved?