@boringnode/transmit
Version:
A framework agnostic Server-Sent-Event library
110 lines (109 loc) • 2.75 kB
JavaScript
/*
* @boringnode/transmit
*
* @license MIT
* @copyright BoringNode
*/
import matchit from 'matchit';
export class Storage {
/**
* Channels subscribed to a given stream
*/
/**
* Channels subscribed to a given Stream UID
*/
/**
* Secured channels definition
*/
/**
* Secure a channel
*/
secure(channel) {
const encodedDefinition = matchit.parse(channel);
this.
}
/**
* Check if a channel is secured and return the matched channel
*/
getSecuredChannelDefinition(channel) {
const matchedChannel = matchit.match(channel, this.
if (matchedChannel.length > 0) {
const params = matchit.exec(channel, matchedChannel);
return { params, channel: matchedChannel[0].old };
}
}
/**
* Get the number of secured channels
*/
getSecuredChannelCount() {
return this.
}
/**
* Get the number of streams
*/
getStreamCount() {
return this.
}
/**
* Add a stream to the storage
*/
add(stream) {
const channels = new Set();
this.
this.
}
/**
* Remove a stream from the storage
*/
remove(stream) {
this.
this.
}
/**
* Add a channel to a stream
*/
subscribe(uid, channel) {
const channels = this.
if (!channels)
return false;
channels.add(channel);
return true;
}
/**
* Remove a channel from a stream
*/
unsubscribe(uid, channel) {
const channels = this.
if (!channels)
return false;
channels.delete(channel);
return true;
}
/**
* Find all subscribers to a channel
*/
findByChannel(channel) {
const subscribers = new Set();
for (const [stream, streamChannels] of this.
if (streamChannels.has(channel)) {
subscribers.add(stream);
}
}
return subscribers;
}
/**
* Get channels for a given client
*/
getChannelByClient(uid) {
return this.
}
/**
* Get all subscribers
*/
getAllSubscribers() {
return this.
}
}