Giter Site home page Giter Site logo

django-channels-jsonrpc's People

Contributors

alerion avatar ekzobrain avatar millerf avatar prokher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bartvds ekzobrain

django-channels-jsonrpc's Issues

Improve outbound notifications

While using new outbound notifications in my project, I realized that our current implementation is not a completed solution:
JsonRpcConsumer.notify_group()'s "params" parameter is directly assigned to JSON-RPC "params" without any checks, that may lead to incorrect JSON output. "params" must be forced to list or dict types, at least. But using python's argument unpacking and named parameters we could make it in a better way.
In fact, we a making a JsonRpc client (asuming outbound calls), which is aimed to work ot top of Django Channels. So I think we shoud go the same way as most clients do, using Channels as an endpoint. A standart approach of all clients looks like this:

client = JsonRpcClient(endpoint) #  endpoint = some http url or websocket url
client.call(method_name, param1, param2)
client.notification(method_name, param1, param2)

In our case it might look the same way, for example:

JsonRpcClient(Group('name')).notify(method, param1, param2) # notification with positional arguments as per JSON-RPC spec
JsonRpcClient(message.reply_channel).notify(method, param1=value1, param2=value2) # notification with named arguments

So the solution is:

  1. We introduce a new class JsonRpcClient along with our main JsonRpcConsumer.
  2. We use Channels "Group" and "reply_channel" objects as possible endpoints.
  3. JsonRpcClient has one method - "notify", which sends outbound notifications. We can not impelment "call" method we will not be able to retrieve response anyway.
  4. When notify is called with positional arguments - we encode them as a list, and when with named - as a dict. This way we ensure that arguments are passed correctly without any type-forcing. We just need to check that user did not pass both positional and named parameters together.

I may implement it tomorrow and make a pull request, it you like this approach.

Access to original_message is not thread-safe

This code is not thread-safe:

global original_message
original_message = original_msg
result = method(*args, **kwargs)
original_message = None

If you have two JsonRpcWebsocketConsumer you can get a moment, when one thread reset original_message and other tries to read it.

Notifications support

It would be great to implement inbound (and outbound) notifications.
I could make a pull-request. I think inbound notifications may be processed by the same __process method (but not return any value, so nothing will be sent back) and handlers may be defined with the same JsonRpcWebsocketConsumer.rpc_method() decorator... what do you think?

By outbound notifications i mean possibility to send JsonRpc notifications to "reply_channel" or to Groups (make implementation bi-directional in some way). I think a good starting point would be to create some helper method like "create_notification(method, params)" that just takes method name and params and returnes a correct JSON structure defined in JsonRpc protocol, so that it may be used like this:

original_message.reply_channel.send({"text": create_notification(method, params)})
Group("xxx").send({"text": create_notification(method, params)})

Dead Link http://channels.readthedocs.io/en/stable/generics.html#websockets

Hej Guys!
You did a nice work with that jsonrpcconsumer... Just one question. I tried to integrate your package into my already build up project and following your documentation i realized that the link to channels is dead.
Further i realized that your requirements need channels==1.1.6 whilst the latest stable version is around 2.1.1.
So my question, did you already tested agains channels>=2.1.0

kine regards, Mr. J

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.