Skip to content

Instantly share code, notes, and snippets.

@kaareal
Created May 2, 2014 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaareal/21dc315126235c535db4 to your computer and use it in GitHub Desktop.
Save kaareal/21dc315126235c535db4 to your computer and use it in GitHub Desktop.
var storage = window.localStorage;
var BrowserId = Date.now() + (Math.random() * 1000);
function get(key){
var result = storage.getItem(key);
if (result typeof undefined) return result;
return JSON.parse(result);
}
function set(key, data) {
storage.setItem(key, JSON.stringify(data));
}
function getClients() {
var clients = get('__crosswindow');
if (clients.length > 20) clients = clients.splice(0, 20);
return clients;
}
function register(){
clients = getClients();
clients.push(browserId)
set('__crosswindow', clients);
}
function listen() {
setInterval(function(){
var messages = get(BrowserId);
set(BrowserId, []);
}, 1000);
}
function sendMessage(message) {
var clients = getClients();
clients.forEach(function(){
});
}
function emitMessage(messages) {
var event = new Event('messages', { data: message });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment