|
2 | 2 | > The `djnotifier` app is almost 100% customizable
|
3 | 3 |
|
4 | 4 |
|
5 |
| -## Customize notification frontend |
| 5 | +# Table of contents |
| 6 | +1. [Frontend notification customization](#customize-notification-frontend) |
| 7 | + - [Adding own notification class/style](#adding-own-notification-classstyle) |
| 8 | + - [Registering new style as default](#registering-new-style-as-default) |
| 9 | +2. [Frontend websocket customization](#frontend-websocket-customization) |
| 10 | +3. [Backend customization](#backend-customization) |
| 11 | + |
| 12 | +## Frontend notification customization |
6 | 13 | > Customize the notification style and other functionalities
|
7 | 14 |
|
8 | 15 | ### Adding own notification class/style
|
@@ -59,12 +66,15 @@ $.notify.addStyle("metro", {
|
59 | 66 | {% include 'djnotifier/dj_notifier.html' %}
|
60 | 67 | ```
|
61 | 68 |
|
62 |
| -**Adding new style as one of notification styles |
| 69 | +**Adding new style as one of notification styles** |
63 | 70 | ```html
|
64 | 71 | <!--dj_notifier: add custom style-->
|
65 |
| -{% block dj_notifier_notification_custom_style_js %} |
66 |
| - <script src="{% static 'path/to/djnotifier-custom-style.js' %}"></script> |
67 |
| -{% endblock dj_notifier_notification_custom_style_js %} |
| 72 | +{% block dj_notifier_notification_custom_style %} |
| 73 | + <script src="{% static 'path/to/djnotifier-custom-style.js' %}"></script> |
| 74 | + |
| 75 | + <!--optional--> |
| 76 | + <link href="{% static 'path/to/djnotifier-custom-style.css' %}" rel="stylesheet"> |
| 77 | +{% endblock dj_notifier_notification_custom_style %} |
68 | 78 | ```
|
69 | 79 |
|
70 | 80 | ### Registering new style as default
|
@@ -125,5 +135,47 @@ function playNotifyAudio(){
|
125 | 135 | <audio id="djNotifyAudio" data-src="{% static 'path/to/notify.mp3' %}"></audio>
|
126 | 136 | {% endblock dj_notifier_notification_audio %}
|
127 | 137 | ```
|
128 |
| -## Notification (backend) |
| 138 | + |
| 139 | +## Frontend websocket customization |
| 140 | +> Customize the websocket frontend |
| 141 | +
|
| 142 | +**Writing own websocket client** |
| 143 | +```javascript |
| 144 | +// socket.js example |
| 145 | +var protocol = (window.location.protocol == 'http:') ? 'ws://' : 'wss://'; |
| 146 | +var endpoint = "djnotifier" |
| 147 | +var webSocketEndpoint = protocol + window.location.host + '/' + endpoint + '/'; |
| 148 | +var socket = new ReconnectingWebSocket(webSocketEndpoint); |
| 149 | + |
| 150 | +socket.onmessage = function(e){ |
| 151 | + let data = JSON.parse(e.data); |
| 152 | + // triggering push notification here... |
| 153 | + DJNotifier(style=data.type || 'info', text=data.message, audio=true) |
| 154 | +} |
| 155 | + |
| 156 | +// Socket Connet Functionality |
| 157 | +socket.onopen = function(e){ |
| 158 | + // more logic here... |
| 159 | +} |
| 160 | + |
| 161 | +// Socket Error Functionality |
| 162 | +socket.onerror = function(e){ |
| 163 | + // more logic here... |
| 164 | +} |
| 165 | + |
| 166 | +// Socket close Functionality |
| 167 | +socket.onclose = function(e){ |
| 168 | + console.log('Disconnected from djnotifier') |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +**Replacing default frontend websocket client** |
| 173 | +```html |
| 174 | +<!--web socket javascript client--> |
| 175 | +{% block dj_notifier_websocket_js %} |
| 176 | + <script src="{% static 'path/to/custom-socket.js' %}"></script> |
| 177 | +{% endblock dj_notifier_websocket_js %} |
| 178 | +``` |
| 179 | + |
| 180 | +## Backend customization |
129 | 181 | > Customize the notification consumer, add more websocket routes etc.
|
0 commit comments