</code></pre></div></td></tr></table></div> </div> </div> </div> <details class=example> <summary>See Interface</summary> <p><font size=4><strong>Parameters</strong></font></p> <table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Description</th> <th>Default</th> </tr> </thead> <tbody> <tr> <td><code class=highlight><span class=n>name</span></code></td> <td><code class=highlight><span class=nb>str</span> <span class=o>|</span> <span class=kc>None</span></code></td> <td>The name of the channel to subscribe to. If you define a <code class=highlight><span class=n>group_name</span></code>, you can keep <code class=highlight><span class=n>name</span></code> undefined to auto-generate a unique name.</td> <td><code class=highlight><span class=kc>None</span></code></td> </tr> <tr> <td><code class=highlight><span class=n>group_name</span></code></td> <td><code class=highlight><span class=nb>str</span> <span class=o>|</span> <span class=kc>None</span></code></td> <td>If configured, any messages sent within this hook will be broadcasted to all channels in this group.</td> <td><code class=highlight><span class=kc>None</span></code></td> </tr> <tr> <td><code class=highlight><span class=n>group_add</span></code></td> <td><code class=highlight><span class=nb>bool</span></code></td> <td>If <code class=highlight><span class=kc>True</span></code>, the channel will automatically be added to the group when the component mounts.</td> <td><code class=highlight><span class=kc>True</span></code></td> </tr> <tr> <td><code class=highlight><span class=n>group_discard</span></code></td> <td><code class=highlight><span class=nb>bool</span></code></td> <td>If <code class=highlight><span class=kc>True</span></code>, the channel will automatically be removed from the group when the component dismounts.</td> <td><code class=highlight><span class=kc>True</span></code></td> </tr> <tr> <td><code class=highlight><span class=n>receiver</span></code></td> <td><code class=highlight><span class=n>AsyncMessageReceiver</span> <span class=o>|</span> <span class=kc>None</span></code></td> <td>An async function that receives a <code class=highlight><span class=n>message</span><span class=p>:</span> <span class=nb>dict</span></code> from a channel. If more than one receiver waits on the same channel name, a random receiver will get the result.</td> <td><code class=highlight><span class=kc>None</span></code></td> </tr> <tr> <td><code class=highlight><span class=n>layer</span></code></td> <td><code class=highlight><span class=nb>str</span></code></td> <td>The channel layer to use. This layer must be defined in <code class=highlight><span class=n>settings</span><span class=o>.</span><span class=n>py</span><span class=p>:</span><span class=n>CHANNEL_LAYERS</span></code>.</td> <td><code class=highlight><span class=s1>'default'</span></code></td> </tr> </tbody> </table> <p><font size=4><strong>Returns</strong></font></p> <table> <thead> <tr> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code class=highlight><span class=n>AsyncMessageSender</span></code></td> <td>An async callable that can send a <code class=highlight><span class=n>message</span><span class=p>:</span> <span class=nb>dict</span></code>.</td> </tr> </tbody> </table> </details> <details class=warning> <summary>Extra Django configuration required</summary> <p>In order to use this hook, you will need to configure Django to enable channel layers.</p> <p>The <a href=https://channels.readthedocs.io/en/latest/topics/channel_layers.html#configuration>Django Channels documentation</a> has information on what steps you need to take.</p> <p>In summary, you will need to:</p> <ol> <li> <p>Install <a href=https://redis.io/download/ ><code>redis</code></a> on your machine.</p> </li> <li> <p>Run the following command to install <code>channels-redis</code> in your Python environment.</p> <div class=highlight><pre><span></span><code>pip<span class=w> </span>install<span class=w> </span>channels-redis
0 commit comments