skygear-SDK-JS icon indicating copy to clipboard operation
skygear-SDK-JS copied to clipboard

Pubsub auto connect mechanism not working at node env

Open rickmak opened this issue 7 years ago • 0 comments

We need to manually connect the pubsub to make the publish works.

  • Skygear SDK Date/Version: v0.22.1
  • JS runtime: node v6.2.2
  • Skygear Server Date/Version: v0.22.1
  • [x] Is this a regression?
  • [ ] Attached logs, screenshots

Expected Results

In JS Cloud code, directly call of skygear.pubsub.publish('test', {someData:'abc'});

Actual Results

Need to call skygear.pubsub.connect(); prior the publish.

Steps to reproduce

Testing script

const skygear = require('skygear');
const skygearCloud = require('skygear/cloud');

skygear.config({
  'endPoint': 'http://localhost:3000/',
  'apiKey': 'secretOURD',
});
skygear.pubsub.connect(); // variant

skygearCloud.handler('/testing', function (req) {
  skygear.pubsub.publish('test', {someData:'abc'});
  console.log(skygear.pubsub._pubsubUrl());
  console.log(skygear.pubsub.connected);
  console.log(skygear.pubsub._queue);
  return new Promise((resolve, reject) => {
    resolve('test success');
  });
});

console.log('set up testing cloud');

Use curl http://localhost:3000/testing to trigger the cloud hanlder

Output without connect

ws://localhost:3000/pubsub?api_key=secretOURD
null
[ { action: 'pub', channel: 'test', data: { someData: 'abc' } } ]

Output with connect

ws://localhost:3000/pubsub?api_key=secretOURD
true
[]

rickmak avatar Mar 24 '17 08:03 rickmak