1

I'm trying to configure the WebSocket Server for my chat application. But the first thing that I faced is the error when I tried to run my project:

Uncaught Error: Type WebSocketServer does not have 'ɵmod' property.
    at getNgModuleDef (core.js:1022)
    at recurse (core.js:24986)
    at recurse (core.js:24997)
    at registerNgModuleType (core.js:24982)
    at new NgModuleFactory$1 (core.js:25096)
    at compileNgModuleFactory__POST_R3__ (core.js:28699)
    at PlatformRef.bootstrapModule (core.js:28942)
    at Module.zUnb (main.ts:11)
    at __webpack_require__ (bootstrap:84)
    at Object.0 (main.js:11)

In my app.module.ts file I import my socket server import { WebSocketServer } from '@ionic-native/web-socket-server/ngx';. After I resolve this issue I'm wondering how can I configure the WebSocket object that is shown in the documentation here:

import { WebSocketServer } from '@ionic-native/web-socket-server';

constructor(private wsserver: WebSocketServer) { }

...

// start websocket server
this.wsserver.start(8888, {}).subscribe({
  next: server => console.log(`Listening on ${server.addr}:${server.port}`),
  error: error => console.log(`Unexpected error`, error);
});

// watch for any messages
this.wsserver.watchMessage().subscribe(result => {
  console.log(`Received message ${result.msg} from ${result.conn.uuid}`);
});

// send message to connection with specified uuid
this.wsserver.send({ uuid: '8e7c4f48-de68-4b6f-8fca-1067a353968d' }, 'Hello World');

// stop websocket server
this.wsserver.stop().then(server => {
  console.log(`Stop listening on ${server.addr}:${server.port}`);
});

Helps are appreciated, thanks!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.