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

Provide API/Example to use to remotedev-server from other applications #34

Closed
peterpeter5 opened this issue Dec 28, 2016 · 6 comments
Closed

Comments

@peterpeter5
Copy link

If there would be a piece of documentation / an basic example, then other appliactions
and even other programming-languages could use this project. In concrete i try to integrate
my redux-python-port:
https://github.com/peterpeter5/pyredux
with this server. But i think it could be interesting for other people / applications.

@zalmoxisus
Copy link
Owner

zalmoxisus commented Dec 28, 2016

PyRedux looks amazing!

I've just published a docs draft with Python examples. Feel free to amend it. I used to be a fan of Django, but it was almost 10 years ago and already forgot everything.

@peterpeter5
Copy link
Author

The docs look amazing! I will try to do the integration-work in the next Days. Thank you for your (well documented) reply on such short notice!

@peterpeter5
Copy link
Author

The documentation is quite helpful, but i guess there is something wrong or left out. I am able to connect to the server, to "authenticate" as "master" and to send the INIT-Command (I can see the visualization). When i then send a lifted-STATE (sniffed by another application), then I am able to reproduce the logged state-tree (everything is visualized as expected). However, sending a request with:

data = {
    "type": "ACTION", 
    "payload": {
      "todos": "do some"
    },
    "action": {
      "timestamp": 1483349708506,
      "action": {
        "type": "ADD_TODO",
        "text": "hggg"
      }
    },
    "instanceId": "tAmA7H5fclyWhvizAAAi",
    "name": "LoggerInstance",
    "id": "tAmA7H5fclyWhvizAAAi"
  }
socket.emit("log", data)   # No difference when i use "log-noid"

I could use the lifted-state, but than i would have to provide values like: isLocked and stagedActionIds which I am sure is not the best way to do

@zalmoxisus
Copy link
Owner

zalmoxisus commented Jan 2, 2017

I just tried your snippet (on NodeJS) and I'm getting ADD_TODO action on http://remotedev.io/local/ (switching to local server in Settings):

var scClient = require('socketcluster-client');
var socket = scClient.connect({ hostname: 'localhost', port: 8000 });
socket.connect();
socket.on('error', function(error) {
  console.error('Socket error', error);
});

socket.emit('login', 'master', function(error, channelName) {
  if (error) { console.log(error); return; }
  socket.subscribe(channelName);

  var data = {
    "type": "ACTION",
    "payload": {
      "todos": "do some"
    },
    "action": {
      "timestamp": 1483349708506,
      "action": {
        "type": "ADD_TODO",
        "text": "hggg"
      }
    },
    "instanceId": "tAmA7H5fclyWhvizAAAi",
    "name": "LoggerInstance",
    "id": "tAmA7H5fclyWhvizAAAi"
  };
  socket.emit("log", data);
});

@zalmoxisus
Copy link
Owner

zalmoxisus commented Jan 2, 2017

Maybe socketcluster-client-python is not stringifying the object properly. You could try to add json.dumps:

data = {
    "type": "ACTION",
    "payload": json.dumps({
      "todos": "do some"
    }),
    "action": json.dumps({
      "timestamp": 1483349708506,
      "action": {
        "type": "ADD_TODO",
        "text": "hggg"
      })
    },
    "instanceId": "tAmA7H5fclyWhvizAAAi",
    "name": "LoggerInstance",
    "id": "tAmA7H5fclyWhvizAAAi"
  };

@peterpeter5
Copy link
Author

you were right about the socket-cluster-client - stringification, but in another way. When you pass in a string into the socket.emit - function (which i did, unlike my previous post...) then this string gets json.dumps again. That was my problem. Now it works like charm. Thank you!

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

2 participants