Skip to content

Commit

Permalink
remove socketio dep completely, update example client html file
Browse files Browse the repository at this point in the history
  • Loading branch information
mark2600 committed Apr 15, 2016
1 parent eb3b433 commit bfb0bcd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 66 deletions.
103 changes: 41 additions & 62 deletions applications/blackhole/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,68 +30,44 @@ From here, you can write your own Javascript callbacks, triggered everytime a re
```html
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.6/socket.io.min.js"></script>
</head>
<body>
<script>
var socket = io.connect('http://{BLACKHOLE_IP_ADDRESS}:5555');
socket.emit('subscribe', {
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
binding: 'call.CHANNEL_CREATE.*'
});
socket.emit('subscribe', {
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
bindings: ['call.CHANNEL_ANSWER.*', 'call.CHANNEL_DESTROY.*']
});
socket.emit('subscribe', {
account_id: accountId,
auth_token: token,
bindings: ['doc_created.*.user.*', 'doc_edited.*.user.*']
});
socket.on('CHANNEL_CREATE', function(EventJObj) {
console.log(EventJObj);
});
socket.on('CHANNEL_ANSWER', function(EventJObj) {
console.log(EventJObj);
});
socket.on('CHANNEL_DESTROY', function(EventJObj) {
console.log(EventJObj);
});
socket.on('doc_created_user', function(EventJObj) {
console.log(EventJObj);
});
socket.on('doc_edited_user', function(EventJObj) {
console.log(EventJObj);
});
// socket.emit('unsubscribe', {
// account_id: accountId,
// auth_token: token,
// bindings: ['doc_created.*.user.*', 'doc_edited.*.user.*']
// });
// socket.emit('unsubscribe_all', {
// account_id: accountId,
// auth_token: token
// });
var Events = ['connect', 'error', 'disconnect', 'reconnect', 'reconnect_attempt', 'reconnecting', 'reconnect_error', 'reconnect_failed'];
for (var idx in Events) {
socket.on(Events[idx], function(_evt) {
console.log('=ERROR REPORT==== ' + Events[idx]);
var socket = new WebSocket("ws://{BLACKHOLE_IP_ADDRESS}:5555");
function send(data) {
socket.send(JSON.stringify(data));
}
socket.onopen = function() {
send({
action: 'subscribe',
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
binding: 'call.CHANNEL_CREATE.*'
});
send({
action: 'subscribe',
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
bindings: ['call.CHANNEL_ANSWER.*', 'call.CHANNEL_DESTROY.*']
});
send({
action: 'subscribe',
account_id: accountId,
auth_token: token,
bindings: ['doc_created.*.user.*', 'doc_edited.*.user.*']
});
}
socket.onmessage = function(raw_message) {
var json_data = JSON.parse(raw_message.data);
console.log(json_data);
};
</script>
</body>
</html>
Expand All @@ -103,14 +79,16 @@ You can add one or multiple bindings by using:

``` javascript
// For one use: binding
socket.emit('subscribe', {
send({
action: 'subscribe',
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
binding: 'doc_edited.*.user.*'
});

// For multiple use: bindings
socket.emit('subscribe', {
send({
action: 'subscribe',
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
bindings: ['doc_edited.*.user.*', 'doc_deleted.*.user.*']
Expand All @@ -120,7 +98,8 @@ socket.emit('subscribe', {
You can also add a friendly name and some metadata to any subscribe command.

``` javascript
socket.emit('subscribe', {
send({
action: 'subscribe',
account_id: '{ACCOUNT_ID}',
auth_token: '{AUTH_TOKEN}',
name: "My new socket",
Expand All @@ -136,12 +115,12 @@ To remove unnecessary bindings use 'unsubscribe' event:

For particular subscription:
```
socket.emit('unsubscribe', { account_id: '{ACCOUNT_ID}', auth_token: '{AUTH_TOKEN}', binding: 'call.CHANNEL_CREATE.*' });
send({ action: 'unsubscribe', account_id: '{ACCOUNT_ID}', auth_token: '{AUTH_TOKEN}', binding: 'call.CHANNEL_CREATE.*' });
```

For all previous subscriptions:
```
socket.emit('unsubscribe', { auth_token: '{AUTH_TOKEN}' });
send({ action: 'unsubscribe', auth_token: '{AUTH_TOKEN}' });
```


Expand Down
2 changes: 1 addition & 1 deletion applications/blackhole/src/blackhole_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ start(_Type, _Args) ->
-spec stop(any()) -> any().
stop(_State) ->
_ = cowboy:stop_listener('blackhole'),
_ = cowboy:stop_listener('socketio_http_listener'),
_ = cowboy:stop_listener('blackhole_http_listener'),
'ok'.
2 changes: 1 addition & 1 deletion core/whistle_apps/src/whapps_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
,'nksip'
,'poolboy','public_key'
,'rabbit_common','ranch'
,'sasl','socketio','ssl','stdlib','syntax_tools','syslog'
,'sasl','ssl','stdlib','syntax_tools','syslog'
,'webseq'
,'whistle','whistle_amqp','whistle_apps','whistle_config'
,'whistle_couch','whistle_media'
Expand Down
3 changes: 1 addition & 2 deletions make/deps.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEPS = lager eiconv gen_smtp amqp_client cowboy jesse jiffy certifi couchbeam wsock zucchini \
erlsom erlydtl exml escalus folsom detergent erlang_localtime \
nklib gproc poolboy syslog lager_syslog eflame socketio hep ecsv reloader \
nklib gproc poolboy syslog lager_syslog eflame hep ecsv reloader \
proper recon

dep_escalus = hex 2.6.4
Expand All @@ -19,7 +19,6 @@ dep_couchbeam = git https://github.com/benoitc/couchbeam 1.3.0
dep_erlang_localtime = git https://github.com/lazedo/erlang_localtime 0bb26016380cd7df5d30aa0ef284ae252b5bae31

### need to update upstream ###
dep_socketio = git https://github.com/lazedo/socket.io-cowboy 0.2
dep_hep = git https://github.com/lazedo/hep 1.5.4
dep_ecsv = git https://github.com/lazedo/ecsv 0.2.1

Expand Down

0 comments on commit bfb0bcd

Please sign in to comment.