-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for more providers (Ably, Channels, SocketIO) #26
Open
aljp
wants to merge
7
commits into
master
Choose a base branch
from
task/25_generalize_backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c45ccab
Add support for more providers (Ably, Channels, SocketIO)
aljp 99d9b04
Fix minor type
aljp 08680e5
Update name of 'proxies' file/classes to 'providers'
aljp 2280cdf
Fixing imports
aljp 28a2dcd
Removing type annotations for 3.5 compatibility
aljp 04806c6
Fix type annotations for python 3.5 compat
aljp 1f5a424
Move the packet parsing into the provider class
aljp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
from django.conf import settings | ||
from pusher import Pusher | ||
|
||
|
||
class BaseProvider(object): | ||
def configure(self): | ||
raise NotImplementedError() | ||
|
||
def parse_packet(self, backend, channels, event_name, data, socket_id=None): | ||
return channels, event_name, data | ||
|
||
def trigger(self, channels, event_name, data, socket_id=None): | ||
raise NotImplementedError() | ||
|
||
|
||
class PusherProvider(BaseProvider): | ||
""" | ||
This class provides a wrapper to Pusher so that we can mock it or disable it easily | ||
""" | ||
|
||
def __init__(self): | ||
self._pusher = None | ||
self._disabled = False | ||
|
||
if hasattr(settings, "DRF_MODEL_PUSHER_DISABLED"): | ||
self._disabled = settings.DRF_MODEL_PUSHER_DISABLED | ||
|
||
def configure(self): | ||
try: | ||
pusher_cluster = settings.PUSHER_CLUSTER | ||
except AttributeError: | ||
pusher_cluster = "mt1" | ||
|
||
self._pusher = Pusher( | ||
app_id=settings.PUSHER_APP_ID, | ||
key=settings.PUSHER_KEY, | ||
secret=settings.PUSHER_SECRET, | ||
cluster=pusher_cluster, | ||
) | ||
|
||
def parse_packet(self, backend, channels, event_name, data, socket_id=None): | ||
return channels, event_name, data | ||
|
||
def trigger(self, channels, event_name, data, socket_id=None): | ||
if self._disabled: | ||
return | ||
|
||
self._pusher.trigger(channels, event_name, data, socket_id) | ||
|
||
|
||
class AblyProvider(BaseProvider): | ||
def __init__(self, *args, **kwargs): | ||
pass | ||
|
||
def configure(self): | ||
pass | ||
|
||
def trigger(self, channels, event_name, data, socket_id=None): | ||
pass |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
from django.conf import settings | ||
|
||
from drf_model_pusher.proxies import PusherProxy | ||
"""The receiver methods attach callbacks to signals""" | ||
from drf_model_pusher.providers import PusherProvider | ||
|
||
|
||
def send_pusher_event( | ||
signal, sender, instance, channels, event_name, data, socket_id=None, **kwargs | ||
): | ||
""" | ||
Send a pusher event from a signal | ||
Sends an update using the provided provider class | ||
""" | ||
try: | ||
pusher_cluster = settings.PUSHER_CLUSTER | ||
except AttributeError: | ||
pusher_cluster = "mt1" | ||
|
||
pusher = PusherProxy( | ||
app_id=settings.PUSHER_APP_ID, | ||
key=settings.PUSHER_KEY, | ||
secret=settings.PUSHER_SECRET, | ||
cluster=pusher_cluster, | ||
) | ||
pusher.trigger(channels, event_name, data) | ||
push_provider_class = kwargs.get("provider_class", PusherProvider) | ||
push_provider = push_provider_class() | ||
push_provider.configure() | ||
push_provider.trigger(channels, event_name, data, socket_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
EMAIL = "[email protected]" | ||
AUTHOR = "Adam Jacquier-Parr" | ||
REQUIRES_PYTHON = ">=3.6.0" | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to bump this to |
||
|
||
# What packages are required for this module to be executed? | ||
REQUIRED = ["django", "djangorestframework", "pusher"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are multiple channels returned from
get_channels
then the return result is an array of 1 string"private-[a, b, c]"
rather than a array["private-a", "private-b", "private-c"]