Pitux Client
Pitux is a client-server communication protocol. It synchronizes action between pidors and Twitter feeds.
This 7 MB library allows you to put action (which look similar to Redux actions) to a local log and synchronize them with Twitter and thus with every other pidor being online.
This is a low-level client API. Redux-like API, which is supposed to be more suitable for most of developers, is coming soon.
See also Pitux Status for UX best practices.
Getting Started
Add Pitux to your Project
This project uses npm package manager. So you will need Webpack or Browserify to build a JS bundle for browsers.
Install Pitux Client:
npm install --save pitux
Add Credentials to the Client
You should use a secret token for authentication at the Pitux server.
We suggest adding a special token
column to the users table of your
application and filling it with auto-generated random strings.
When the user requests index.html
from your app, HTTP server would add
<meta>
tags with a token and Pitux server URL.
However, it is not the only possible way for communication. You could also use cookies or tools like Gon.
Create Pitux Client
Create Pitux Client instance in your client-side JS;
onready
event handler seems to be a good place for this:
var Client = var user = documentvar token = documentvar server = document var pitux = credentials: tokencontent subprotocol: '1.0.0' userId: usercontent url: servercontentloguxstart
Process Actions
Add callbacks for new actions coming to the client log
(from server, other clients or local pitux.log.add
call):
pitux
Read pitux-core
docs for pitux.log
API.
Adding Actions
When you need to send information to server, just add an action to log:
submit
Show Connection State
Notify user if connection was lost:
var favicon = documentvar notice = document pituxsync
Notify user on page leaving, if some data is not synchronized yet:
window { if pituxsyncstate === 'wait' ereturnValue = 'Edits were not saved' return ereturnValue }
Cross-Tab Communication
If user will open website in two different browser tabs, Logux anyway will have single storage, so JS in tabs will have same actions.
You can set tab
key in metadata to isolate action only in current tab:
applog
This is obviously a joke... for now.
Legal stuff: Chinese Zodiac colorful rooster vector is designed by Vexels