arildwtv / mozaik-ext-value

Mozaïk value plugin
MIT License
5 stars 4 forks source link

error: Unable to find API matching id 'value' #1

Closed tomav closed 7 years ago

tomav commented 7 years ago

Hi, thanks for this generic extension. I have a problem using it when I start my server:

dev_1     | [15:23:40] Using gulpfile /src/gulpfile.js
dev_1     | [15:23:40] Starting 'copy:fonts'...
dev_1     | [15:23:40] Copying fonts
dev_1     | [15:23:40] Starting 'copy:styles'...
dev_1     | [15:23:40] Copying styles
dev_1     | [15:23:40] Starting 'copy:imgs'...
dev_1     | [15:23:40] Copying images from extensions and themes
dev_1     | [15:23:40] Starting 'collect:styles'...
dev_1     | [15:23:40] Collecting extensions styles
dev_1     | [15:23:40] Finished 'collect:styles' after 24 ms
dev_1     | [15:23:40] Starting 'styles:dev'...
dev_1     | [15:23:40] Compiling stylus code using theme '/src/node_modules/mozaik/src/themes/night-blue'
dev_1     | [15:23:40] Starting 'js'...
dev_1     | [15:23:40] Finished 'styles:dev' after 118 ms
dev_1     | [15:23:40] Starting 'styles'...
dev_1     | [15:23:40] Finished 'styles' after 91 μs
dev_1     | [15:23:40] Finished 'copy:imgs' after 173 ms
dev_1     | [15:23:41] Finished 'copy:styles' after 656 ms
dev_1     | [15:23:41] Finished 'copy:fonts' after 1.09 s
dev_1     | [15:23:41] Starting 'copy'...
dev_1     | [15:23:41] Finished 'copy' after 18 μs
dev_1     | [15:23:56] Finished 'js' after 16 s
dev_1     | [15:23:56] Starting 'build'...
dev_1     | [15:23:56] Finished 'build' after 39 μs
dev_1     | info: registered API 'mozaik' (mode: poll)
dev_1     | info: serving static contents from /src/build
dev_1     | info: Mozaïk server listening at http://0.0.0.0:5000
dev_1     | info: Client #1 connected
dev_1     | info: Client #1 disconnected
dev_1     | info: Client #2 connected
dev_1     | error: Unable to find API matching id 'value'
dev_1     | /src/node_modules/mozaik/src/Bus.js:171
dev_1     |             throw new Error(errMsg);
dev_1     |             ^
dev_1     |
dev_1     | Error: Unable to find API matching id 'value'
dev_1     |     at Object.clientSubscription (Bus.js:160:19)
dev_1     |     at WebSocket.<anonymous> (server.js:53:24)
dev_1     |     at emitTwo (events.js:106:13)
dev_1     |     at WebSocket.emit (events.js:191:7)
dev_1     |     at Receiver.ontext (/src/node_modules/ws/lib/WebSocket.js:841:10)
dev_1     |     at /src/node_modules/ws/lib/Receiver.js:536:18
dev_1     |     at /src/node_modules/ws/lib/Receiver.js:368:7
dev_1     |     at /src/node_modules/ws/lib/PerMessageDeflate.js:249:5
dev_1     |     at afterWrite (_stream_writable.js:386:3)
dev_1     |     at onwrite (_stream_writable.js:377:7)
dev_1     |     at afterTransform (_stream_transform.js:79:3)
dev_1     |     at TransformState.afterTransform (_stream_transform.js:54:12)
dev_1     |     at Zlib.callback (zlib.js:625:5)

Here are my configuration.

# cat config.js
// Load environment variables from .env file if available
require('dotenv').load();

var config = {
  env:  'prod',

  host: '0.0.0.0',
  port: process.env.PORT || 5000,

  theme: 'night-blue',

  api: {},

  rotationDuration: 2000,

  // define the interval used by Mozaïk Bus to call registered APIs
  apisPollInterval: 15000,

  dashboards: [
    {
      columns: 2, rows: 1,
      widgets: [

        {
          type:               'value.value',
          title:              'Number of Likes',
          url:                'https://dl.dropboxusercontent.com/u/19253297/test.json',
          pathCurrent:        '$.current', /* optional */
          pathLastUpdated:    '$.lastUpdated', /* optional */
          pathChangeRate:     '$.changeRate', /* optional */
          lastUpdatedFormat:  'YYYY-MM-DDThh:mm:ssTZD', /* optional */
          lastUpdatedFromNow: true, /* optional */
          prefix:             '', /* optional */
          postfix:            ' likes', /* optional */
          columns: 2, rows: 1,
          x: 0, y: 0
        }

      ]
    }
  ]
};

module.exports = config;
# cat app.js
require('babel-register')({
    only: [
        /node_modules\/mozaik[^/]*\/src/,
        /src\/server\.js/
    ]
});

require('./src/server');
# cat src/App.jsx
import React   from 'react';
import Mozaik  from 'mozaik/browser';
import iframe  from 'mozaik-ext-iframe';
import value   from 'mozaik-ext-value';

const MozaikComponent = Mozaik.Component.Mozaik;
const ConfigActions   = Mozaik.Actions.Config;

Mozaik.Registry.addExtensions({
    iframe,
    value
});

React.render(<MozaikComponent/>, document.getElementById('mozaik'));

ConfigActions.loadConfig();
# cat src/server.js
import Mozaik  from 'mozaik';
import config  from '../config';

import value from 'mozaik-ext-value/client';

const mozaik = new Mozaik(config);

mozaik.startServer();

Ay idea? I suppose it's a stupid thing but I can't see it.

Thanks.

tomasswood commented 7 years ago

In server.js you need the following line between the other two you already have:

const mozaik = new Mozaik(config);

mozaik.bus.registerApi('value', value);

mozaik.startServer();
tomav commented 7 years ago

Thanks but using something else.