total5 0.0.10-1 → 0.0.10-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.txt CHANGED
@@ -3,6 +3,7 @@
3
3
  ========================
4
4
 
5
5
  - improved HTMLParser parser
6
+ - extended `Flow.socket(flow, socket, [verify(client)], [check(client, msg)])` by adding `check` argument for verifying permissions
6
7
 
7
8
  ========================
8
9
  0.0.9
@@ -1753,7 +1753,7 @@ exports.io = function(flowstreamid, id, callback) {
1753
1753
  });
1754
1754
  };
1755
1755
 
1756
- exports.socket = function(flow, socket, check) {
1756
+ exports.socket = function(flow, socket, verify, check) {
1757
1757
 
1758
1758
  if (typeof(flow) === 'string')
1759
1759
  flow = FLOWS[flow];
@@ -1779,8 +1779,8 @@ exports.socket = function(flow, socket, check) {
1779
1779
  };
1780
1780
 
1781
1781
  socket.on('open', function(client) {
1782
- if (check)
1783
- check(client, () => newclient(client));
1782
+ if (verify)
1783
+ verify(client, () => newclient(client));
1784
1784
  else
1785
1785
  newclient(client);
1786
1786
  });
@@ -1807,6 +1807,17 @@ exports.socket = function(flow, socket, check) {
1807
1807
 
1808
1808
  socket.on('message', function(client, msg) {
1809
1809
  if (client.isflowstreamready) {
1810
+
1811
+ // It can check permissions
1812
+ if (check) {
1813
+ let err = check(client, msg);
1814
+ if (err !== true) {
1815
+ if (msg.callbackid)
1816
+ client.send({ callbackid: msg.callbackid, error: typeof(err) === 'string' ? err : '401' });
1817
+ return;
1818
+ }
1819
+ }
1820
+
1810
1821
  if (flow.isworkerthread)
1811
1822
  flow.postMessage2({ TYPE: 'ui/message', clientid: client.id, data: msg });
1812
1823
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.10-1",
3
+ "version": "0.0.10-2",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {