├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── landingpage ├── index.html └── mp3 │ ├── sad_circurs.mp3 │ └── they_say.mp3 ├── tabsub.v1.js └── tabsub.v1.min.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: simonfrey 4 | custom: 'https://simon-frey.com/tip' 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Simon Frey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TabSub 2 | ## Offline Javascript PubSub between browser tabs 3 | 4 | TabSub offers you an easy to use Javascript PubSub via local storage. No server is required as all messages are shared via the browser built in local storage. 5 | 6 | Give the example a try to see what you can build with TabSub. 7 | 8 | Is this safe for a lot of concurrent writes? To be honest I have no clue. I tried to break it with 10 concurrent writers and everything worked as expected: No message got lost and the messages where in correct order. No warranty here, use at your own risk 😅 9 | 10 | As TabSub uses local store this only works on the same domain, as the browser separates the local storage by domains as security measure. 11 | 12 | TabSub is licensed [MIT](https://github.com/simonfrey/tabsub/blob/master/LICENSE) 13 | 14 | ## Example 15 | 16 | To checkout TabSub in action visit [simon-frey.com/tabsub](https://simon-frey.com/tabsub) 17 | 18 | ## Usage 19 | 20 | ### Including the script 21 | 22 | ```html 23 | 24 | ``` 25 | 26 | ### Initialization 27 | 28 | ```javascript 29 | const ts = new TabSub(); 30 | ``` 31 | 32 | ### Available functions 33 | 34 | #### publish(topic,msg) 35 | 36 | Publish new message. The message can be of any type. Your callback in subscribe has to handle it correctly. TabSub does not take care about that. 37 | 38 | ```javascript 39 | ts.publish("hello","world"); 40 | ``` 41 | 42 | #### subscribe(topic, callback) 43 | 44 | Register new listener. Callback is called with the message content if new message arrives 45 | 46 | ```javascript 47 | ts.subscribe("hello",(msg)=>{ 48 | console.log("Got msg: ",msg); 49 | }); 50 | ``` 51 | 52 | #### state(topic) 53 | Get the current (static) state of a topic. Returns the current data in the local storage for this topic 54 | 55 | ```javascript 56 | const state = ts.state("hello"); 57 | console.log("Current state: ",msg); 58 | ``` -------------------------------------------------------------------------------- /landingpage/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |TabSub offers you an easy to use Javascript PubSub via local storage. No server is required as all messages are shared via the browser built in local storage.
62 |Give the example a try to see what you can build with TabSub.
63 |Is this safe for a lot of concurrent writes? To be honest I have no clue. I tried to break it with 10 concurrent writers and everything worked as expected: No message got lost and the messages where in correct order. No warranty here, use at your own risk 😅
64 |As TabSub uses local store this only works on the same domain, as the browser separates the local storage by domains as security measure.
65 |TabSub is on Github and licensed MIT
66 | 67 |Start one of the two songs and than open this site in a second tab. You will see that the playing song time syncs and if you start the other song that the first one stops.
69 |Look into the source code of this site to see how I used TabSub to built this example.
70 |89 | <script src="https://simon-frey.com/tabsub/tabsub.v1.min.js" 90 | integrity="sha384-WhqYceisw/e1nVVrHA5CI/Lt/c3HrNIZLtPE+sWky3NjzRAF6kt9Ivjp8LwoIS/k" > 91 | </script>92 | 93 |
95 | <script> 96 | const ts = new TabSub(); 97 | </script>98 | 99 |
Publish new message. The message can be of any type. Your callback in subscribe has to handle it correctly. TabSub does not take care about that.
103 |104 | <script> 105 | ts.publish("hello","world"); 106 | </script>107 | 108 |
Register new listener. Callback is called with the message content if new message arrives
110 |111 | <script> 112 | ts.subscribe("hello",(msg)=>{ 113 | console.log("Got msg: ",msg); 114 | }); 115 | </script>116 | 117 |
Get the current (static) state of a topic. Returns the current data in the local storage for this topic
119 |120 | <script> 121 | const state = ts.state("hello"); 122 | console.log("Current state: ",msg); 123 | </script>124 | 125 |