Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveQuery Adapter #6474

Closed
francojohnc opened this issue Mar 6, 2020 · 4 comments
Closed

LiveQuery Adapter #6474

francojohnc opened this issue Mar 6, 2020 · 4 comments

Comments

@francojohnc
Copy link

Issue Description

I tried to create a custom WSAdapter but it didn't call. or even instantiate.
i tried also another class PubSubAdapter it work but the createSubscriber function never been called.

Steps to reproduce

this is my code

const WebSocketServer = require('ws').Server;

/**
 * Wrapper for ws node module
 */
class WSAdapter {
    constructor(options) {
        console.log("WSAdapter " + options);
        this.options = options;
    }

    onListen() {
        console.log("onListen");
    }

    onConnection(ws) {
        console.log("onConnection");
        ws.send('something');
    }

    onError(error) {
        console.log("onError");
    }

    start() {
        const wss = new WebSocketServer({server: this.options.server});
        wss.on('listening', this.onListen);
        wss.on('connection', this.onConnection);
        wss.on('error', this.onError);
    }
    close() {
    }
}

module.exports = WSAdapter;

 liveQuery: {
        classNames: ["Message"], // List of classes to support live query subscriptions
        pubSubAdapter: PubSubAdapter,
        wssAdapter: WSAdapter,
    }

Expected Results

I expect that logs is shown when class is instantiated. and the onConnection function was called when new client are subscribed.

Actual Outcome

no logs shown.

Environment Setup

  • Server

    • parse-server version : 4.1.0
    • Operating System: OSX High sierra
    • Hardware: 10.13.6
    • Localhost or remote server? local and docker environment.
  • Database

    • MongoDB version: 4.2.2
    • Storage engine: WiredTiger
    • Hardware: macbook pro
    • Localhost or remote server? localhost

Logs/Trace

 PORT=8888 node index.js 
createPublisher
Publisher  EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }
parse-server running on port 8888.
info: Parse LiveQuery Server starts running
info: Create new client: fa0fe5d5-1e3d-4edd-9d45-89eae1e10a09
^C
Johns-MacBook-Pro:parse-api johncarlofranco$ PORT=8888 VERBOSE=1 node index.js 
createPublisher
Publisher  EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }
verbose: Support key pairs
parse-server running on port 8888.
info: Parse LiveQuery Server starts running
verbose: Request: %j
info: Create new client: 7839ddd1-d87f-4cb8-94aa-a9be5756e027
verbose: Push Response : %j
verbose: Request: %j
verbose: Push Response : %j
verbose: Create client 7839ddd1-d87f-4cb8-94aa-a9be5756e027 new subscription: 1
verbose: Current client number: %d
verbose: Request: %j
verbose: Push Response : %j
Johns-MacBook-Pro:parse-api johncarlofranco$ PORT=8888 VERBOSE=1 node index.js 
createPublisher
Publisher  EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }
verbose: Support key pairs
parse-server running on port 8888.
info: Parse LiveQuery Server starts running
verbose: Request: %j
info: Create new client: 1b0bc3fb-30c3-471c-857d-5dd1a96ee4b4
verbose: Push Response : %j
verbose: Request: %j
verbose: Push Response : %j
verbose: Create client 1b0bc3fb-30c3-471c-857d-5dd1a96ee4b4 new subscription: 1
verbose: Current client number: %d
verbose: REQUEST for [PUT] /v1/classes/Message/VNiMIadBny: {
  "message": "hello"
} {"method":"PUT","url":"/v1/classes/Message/VNiMIadBny","headers":{"host":"localhost:8888","connection":"keep-alive","content-length":"219","sec-fetch-dest":"empty","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36","content-type":"text/plain","accept":"*/*","origin":"http://0.0.0.0:4040","sec-fetch-site":"cross-site","sec-fetch-mode":"cors","referer":"http://0.0.0.0:4040/apps/e3af844bec24c1ad975700177b47993c/browser/Message","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9"},"body":{"message":"hello"}}
verbose: Raw request from cloud code current : %j | original : %j
publish message  EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }
verbose: RESPONSE from [PUT] /v1/classes/Message/VNiMIadBny: {
  "response": {
    "updatedAt": "2020-03-06T18:01:01.410Z"
  }
} {"result":{"response":{"updatedAt":"2020-03-06T18:01:01.410Z"}}}

@davimacedo
Copy link
Member

Can you please add a console.log in the first line of the start function to make sure it has not been called?

@francojohnc
Copy link
Author

Can you please add a console.log in the first line of the start function to make sure it has not been called?

 start() {
        console.log("start");
        const wss = new WebSocketServer({server: this.options.server});
        wss.on('listening', this.onListen);
        wss.on('connection', this.onConnection);
        wss.on('error', this.onError);
    }

output

 PORT=8888 node index.js 
createPublisher
Publisher  EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined }
parse-server running on port 8888.
info: Parse LiveQuery Server starts running

Screen Shot 2020-03-07 at 12 43 50 PM

@dplewis
Copy link
Member

dplewis commented Mar 29, 2020

I'm not sure you can pass in the WSSAdapter that way. This may be a bug.

Look at the test cases for how to set the adapter
https://github.com/parse-community/parse-server/pull/6230/files#diff-cec0b53135a385ac3440b3d9618ba1d5R69

@stale
Copy link

stale bot commented May 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants