Comments (2)
@Randix6644 could you link to the example in question.
from djangochannelsrestframework.
I assume @Randix6644 is referring to the examples in the README here:
# consumers.py
from djangochannelsrestframework.consumers import AsyncAPIConsumer
from djangochannelsrestframework.decorators import action
from djangochannelsrestframework.observer import observer
from rest_framework import status
from .signals import joined_chat_signal
from .serializers import UserSerializer
class TestConsumer(AsyncAPIConsumer):
@action()
def join_chat(self, chat_id, **kwargs):
serializer = UserSerializer(instance=self.scope['user'])
joined_chat_signal.send(sender='join_chat', data=serializer.data, **kwargs)
return {}, status.HTTP_204_NO_CONTENT
@observer(signal=joined_chat_signal)
async def joined_chat_handler(self, data, observer=None, action=None, subscribing_request_ids=[], **kwargs):
for request_id in subscribing_request_ids:
await self.reply(action='joined_chat', data=data, status=status.HTTP_200_OK, request_id=request_id)
@joined_chat_handler.serializer
def join_chat_handler(self, sender, data, **kwargs): # the data comes from the signal.send and will be available in the observer
return data
@joined_chat_handler.groups_for_signal
def joined_chat_handler(self, instance, **kwargs):
yield f'chat__{instance}'
@joined_chat_handler.groups_for_consumer
def joined_chat_handler(self, chat, **kwargs):
if chat:
yield f'chat__{chat}'
@action()
async def subscribe_joined(self, chat_id, request_id, **kwargs):
await self.joined_chat_handler.subscribe(chat_id, request_id=request_id)
from djangochannelsrestframework.
Related Issues (20)
- [BUG] TypeError: can not serialize 'UUID' object models with pk type uuid HOT 2
- Question about client notify HOT 1
- support for request build_absolute_uri
- [BUG] It's impossible to fully use a REAL WORLD viewset via view_as_consumer HOT 1
- [BUG] aws(elastickbeanstalk) and library HOT 1
- observer for instances based on foregien key HOT 2
- [BUG] Can't override get_queryset method when using ObserverModelInstanceMixin and GenericAsyncAPIConsumer HOT 3
- [BUG] app() missing 2 required positional arguments: 'receive' and 'send'
- Document support for channels v4 HOT 1
- [BUG] HOT 1
- Add link to ReadTheDocs in GitHub Project Description HOT 1
- `chat/layout.html` referenced in tutorial is missing HOT 7
- Object level permission HOT 4
- [Feature request] Dynamic subscription filtering through query params. HOT 7
- [Feature] support OR operations for group subscriptions
- [Feature] Subscribe to changes of a given field/fields
- djangochannelsrestframework working with gunicorn HOT 2
- [Feature] Add support to more optimally manually send bulk create events over the existing infra HOT 3
- Improve documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from djangochannelsrestframework.