Code Monkey home page Code Monkey logo

Comments (5)

joaopiopedreira avatar joaopiopedreira commented on June 14, 2024 1

Hi @Gregivy, setting autoConnect:false when instantiating simpleddp did the trick (so you were probably right when you said that the server was responding too fast, because the connection was being establish on class instantiation).

A separate PR will follow with the typescript definition file.

from simpleddp.

Gregivy avatar Gregivy commented on June 14, 2024

Hello @joaopiopedreira, thank you for your response!

Have you tried something like this?

    setTimeout(() => {
      this.server.connect().then(() => {
          console.log('this gets logged!');
      }
    },1000);

    this.server.on('connected',()=>{
      console.log('this does not get logged');
    });

Will the both messages appear?

from simpleddp.

joaopiopedreira avatar joaopiopedreira commented on June 14, 2024

Hi @Gregivy, thank you for the quick reply. That didn't work, but the below did. I'll fork your project this evening and will try to debug why the core ddp emitter is not working. If I find anything, I'll post it here or send you a PR.

import simpleddp from "simpleddp";
import {config} from './meteor'

class App extends Component<IProps,IState> {
  private server: simpleddp;  

  constructor(props) {
    super(props);
    this.server = config.server;
  }

  public async componentDidMount()  {
    this.server.connect().then(() => {
        console.log('this gets logged!');
        this.server.ddpConnection.emit('connected',{});  // <-------
    }

    this.server.on('connected',()=>{
      console.log('this does not get logged');
    });

  }
  (...)
}

On another note, are you interested in making this package typescript compatible? I'm writing a ...d.ts file as I move along and will soon be able to either submit a PR to DefinitelyTyped or directly to you and you include it in your source, as you prefer.

from simpleddp.

joaopiopedreira avatar joaopiopedreira commented on June 14, 2024

Hi again @Gregivy , maybe you should emit a connected event here, something like

connect () {
        this.autoReconnect = this.autoReconnectUserValue;
        this.socket.open();
        this.emit('connected',{...}) //  <---------
    }

from simpleddp.

Gregivy avatar Gregivy commented on June 14, 2024

Hi @joaopiopedreira, its great idea to support typescript definitions! I can merge your PR if you'd like or you can submit to DefinitelyType as you like more. It's up to you :)

What concerns the error you faced I think it may be due to the fact that connected message comes from server too quick, quicker than you start listening for connected events. Try to switch positions in code:

    this.server.on('connected',()=>{
      console.log('this does not get logged');
    });

    this.server.connect().then(() => {
        console.log('this gets logged!');
    }

If it won't help, I need to see your code example that reproduces this error (test repo suits perfect).

P.S. You can't emit connected after this.socket.open(); because it doesn't match DDP protocol specification (https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.md).

from simpleddp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.