diy / intercom.js Goto Github PK
View Code? Open in Web Editor NEWUNMAINTAINED: A client-side cross-window message broadcast library built on top of the HTML5 localStorage API.
UNMAINTAINED: A client-side cross-window message broadcast library built on top of the HTML5 localStorage API.
Here is small sample:
http://jsbin.com/ayepiLe/1/
just open 4 tabs in any ie. Then move on 3rd for example. press login button. Depending on some random not all tabs have alert generated but 4th tab never fires anyway. have tried to use timeouts, replace alert on other methods (to not block) etc. without any success.
We at VersionEye are working hard to keep up the quality of the bower's registry.
We just finished our initial analysis of the quality of the Bower.io registry:
7530 - registered packages, 224 of them doesnt exists anymore;
We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).
Sadly, your library diy/intercom.js
is one of them.
Can you spare 15 minutes to help us to make Bower better?
Just add a new file bower.json
and change attributes.
{
"name": "diy/intercom.js",
"version": "1.0.0",
"main": "path/to/main.css",
"description": "please add it",
"license": "Eclipse",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<dependency_name>": "<semantic_version>",
"<dependency_name>": "<Local_folder>",
"<dependency_name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}
Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.
NB! Please validate your bower.json with jsonlint before commiting your updates.
Thank you!
Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!
Documentation is missing some methods and parameters, for example: off
, bind
and id
parameter in emit
.
Not working when i open child window using window.open and send message to parent window.in IE
Create basic version without Socket.io binding, as it is not used by everyone and will reduce file size.
Another solution would be to move binding to another file and treat it as extension.
Recently I found this docs that allowing us to communicate between tabs and iframes with a single broadcast channel.
I think it would be better if it was implemented to intercom.js.
And if the Broadcast Channel API was unavailable on the browser, then fallback to Local Storage.
Above all, thanks for the implementation, it is always great when you don't have to reinvent the wheel! :-) (I had come to the same approach in this topic: http://stackoverflow.com/questions/19125823/how-is-it-possible-to-share-single-js-resource-between-browser-tabs/19165781#19165781)
I think intercom.js is a good thing, but I think it would be more flexible if you'd step back and watch the problem in a more general way. It's about resource sharing and resource allocation, so I think it should not be so specific that you can have only a single resource of a single type (socket.io) . I suggest to create a more general interface for resource sharing, and a more general implementation of it. (Ofc shared webworkers would be that, but they are not supported in most of the browsers:S)
First of all thank you for such an awesome tool, it was very useful in our case!
I was wondering about cleaning up LocalStorage.
I noticed these variables in intercom.js
var THRESHOLD_TTL_EMIT = 50000;
var THRESHOLD_TTL_ONCE = 1000 * 3600;
Could you please explain how often currently cleanup happens and how these two variables differ?
And can we change these settings, to do it more often?
Thank you.
It is not clear that LocalStorage has an event api, and this library is making use of it to do inter window communication.
looks like a great library indeed
The following change can solve the compatibility issue
SocketBinding.factory = function(object, options, intercom) {
if (typeof object.io === 'undefined' && object.connected == true) {
return false
};
return new SocketBinding(object, options, intercom);
};
}
Got an error on intercom on my web sentry account:
https://sentry.io/share/issue/53eb376a3ec64c978a4e3448d0a92e0e/
Error appears to be here:
{snip} owser();let p=void 0!==r?c.parts.find((e=>e.id===r)):(e=>e.readAt?Object(m.s)(e):Object(m.c)(e))(c),{messageType:h}=p||{};h=h||"adminReply", {snip}
Can chrome send data to firefox for example?
Hi, has anyone got this library working in Edge? As far as I can tell it fails silently?
From the introduction it says that intercom.js includes a binding for socket.io, but doesn't elaborate if it's a requirement for it to work... or if node.js is required.
Also what is the main difference between socket.io and intercom.js?
Thanks
Currently it looks like this library is not published on NPM. Could you guys do that so we don't have to commit vendor code to our apps?
Uncaught TypeError: Cannot call method 'getItem' of null
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
Here is the null.getItem()
call:
https://github.com/diy/intercom.js/blob/master/lib/intercom.js#L38
Here is where I think we could change this:
https://github.com/diy/intercom.js/blob/master/lib/localstorage.js#L2
Perhaps we should check if localstorage is falsy in addition to undefined?
I am wondering whether we can get the previously broadcast-ed messages in a newly opened window. For eg, I have broadcast-ed "message1" now and after sometime I opened a new window, then the new window should be able to get "message1". The same thing as we get in facebook chat.
Thanks.
I propose an optional callback be passed to getInstance method.
This callback will be called only if there are no previous getInstance invocation in other sessions. The moment the master instance is destroyed, either manually or when window closed, another instance must run the callback.
One use case is master socket connection transfer to other window when the master is closed.
Running into an issue with MS Edge on Windows 10.
Basically the IFrame children can't communicate with the parent, here is a working example.
File1: TestPage.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Outside</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intercom.js/0.1.4/intercom.min.js"></script>
<script type="text/javascript">
var intercom = Intercom.getInstance();
intercom.on('parent', function(data) {
document.getElementById("data").innerHTML = data.message;
});
setTimeout(function(){
intercom.emit('child', {message: 'Hello, Son!'});
}, 500);
</script>
</head>
<body>
<h1>Outside</h1>
<p id="data">Loading..</p>
<iframe src="/TestPage2.html"></iframe>
</body>
</html>
File2: TestPage2.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Inside</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intercom.js/0.1.4/intercom.min.js"></script>
<script type="text/javascript">
var intercom = Intercom.getInstance();
intercom.emit('parent', {message: 'Hello, Dad!'});
intercom.on('child', function(data) {
document.getElementById("data").innerHTML = data.message;
});
</script>
</head>
<body>
<h1>Inside</h1>
<p id="data">Loading..</p>
</body>
</html>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.