rxjs-ws-channels-filters
RxJS implementation of websockets with channels and filters
Work in progress
var options = {
url: 'localhost:3000/api',
invalidUrl: function (e) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
options.url = 'localhost:3000/api';
resolve(10);
}, 1000);
});
},
transformResponse: function (message) {
return message;
},
transformRequest: function (message) {
if (message.filters && message.filters.length) {
var i = message.filters.length - 1;
for (; i > -1; i--) {
message.filters[i].type = message.channel;
}
}
return message;
},
channelsMatch: function channelsMatch(source, target) {
return source === target;
},
filtersMatch: function filtersMatch(source, target) {
if (target) {
for (var p in source) {
if (source[p] !== target[p]) {
return false;
}
}
return true;
}
},
channelJoinAction: 'JOIN',
channelLeaveAction: 'LEAVE',
filterJoinAction: 'ADD',
filterLeaveAction: 'REMOVE',
notifyAction: 'NOTIFY'
};
var socket = new rxSocket.Create(options);
console.log(socket);
socket.channels.subscribe('one', function (message) {
console.log(message);
});
socket.channels.subscribe('one', function (message) {
console.log('secondSubscription to one');
console.log(message);
});
socket.channels.subscribe('two', function (message) {
console.log(message);
});
var filterSub = socket.channels.subscribeFilter('three', {id: 3}, function (message) {
console.log('filter', message);
});
filterSub.send('this is a message, from filter');
setTimeout(function () {
filterSub.unsubscribe();
var filterSub2 = socket.channels.subscribeFilter('three', {id: 4}, function (message) {
console.log('filter', message);
});
}, 5000);
TODO
- make a separate repo with a server side node implementation
- make better documentation
- make demo