Skip to content

Commit c006deb

Browse files
author
Mark Gibbs
committed
Update javascript for communal ws bridge
1 parent ca21f68 commit c006deb

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
{%load staticfiles%}
22
<script src="{%static "channels/js/websocketbridge.js"%}"></script>
33
<script>
4-
const wsb = new channels.WebSocketBridge();
5-
wsb.connect("{{url}}");
6-
wsb.listen(function(action, stream) {
7-
console.log("WSB inbound");
8-
console.log(action);
9-
console.log(stream);
10-
});
4+
if( !window.dpd_wsb ) {
5+
const wsb = new channels.WebSocketBridge();
6+
wsb.connect("{{url}}");
7+
var dpd_wsb = {
8+
wsb: wsb,
9+
callbacks: [],
10+
add_callback: function(cb) { this.callbacks.push(cb); },
11+
send:function(message) { this.wsb.send(message); }
12+
};
13+
wsb.listen(function(action, stream) {
14+
for(var i in dpd_wsb.callbacks) {
15+
dpd_wsb.callbacks[i](action, stream);
16+
}
17+
});
18+
window.dpd_wsb = dpd_wsb;
19+
var lcb = function(action, stream) {
20+
console.log("WSB inbound YYYYY");
21+
console.log(action);
22+
console.log(stream);
23+
};
24+
dpd_wsb.add_callback(lcb);
25+
dpd_wsb.add_callback(lcb);
26+
}
1127
</script>

0 commit comments

Comments
 (0)