jsflow-sdk 0.0.2 → 1.0.0-rc.1

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/.npmignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- npm-debug.log
3
-
package/index.html DELETED
@@ -1,7 +0,0 @@
1
- <html>
2
- <head>
3
- <script src="web4.js"></script>
4
- </head>
5
- <body>
6
- </body>
7
- </html>
package/lib/auth.js DELETED
@@ -1,32 +0,0 @@
1
- //Global dependencies
2
- var Q = require('q');
3
-
4
- //Local dependencies
5
- var CONFIG = require('./config')
6
-
7
- if(typeof window === 'undefined') {
8
- var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
9
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
10
- require('ssl-root-cas/latest').inject().addFile(__dirname + '/../ssl/GandiStandardSSLCA.pem');
11
- }
12
-
13
- module.exports = function(authObj) {
14
- var deferred = Q.defer();
15
-
16
- var xhr = new XMLHttpRequest();
17
- xhr.open('POST', CONFIG.APIHOST+'/auth/asd', true);
18
-
19
- xhr.onreadystatechange = function() {//Call a function when the state changes.
20
- if(this.readyState == 4 && this.status == 200) {
21
- deferred.resolve();
22
- }
23
- else if(this.readyState == 4 && this.status !== 200) {
24
- var response = JSON.parse(this.responseText);
25
- deferred.reject(new Error('Authentication error: ' + response.message));
26
- }
27
- };
28
-
29
- xhr.send(authObj.token);
30
-
31
- return deferred.promise;
32
- }
package/lib/config.js DELETED
@@ -1,4 +0,0 @@
1
-
2
- module.exports = {
3
- APIHOST: 'https://local.jsflow.com',
4
- }
package/lib/connect.js DELETED
@@ -1,13 +0,0 @@
1
- //Global dependencies
2
- var Q = require('q');
3
-
4
- //Local dependencies
5
- var CONFIG = require('./config')
6
-
7
- module.exports = function(metaData) {
8
- var deferred = Q.defer();
9
-
10
- deferred.resolve({});
11
-
12
- return deferred.promise;
13
- }
package/lib/log.js DELETED
@@ -1,43 +0,0 @@
1
- var bunyan = require('bunyan');
2
-
3
- function MyRawStream() {
4
- this.ColorMap = {
5
- 20: 'color: #333333',
6
- 30: 'color: #3333FF',
7
- 40: 'color: #AA9933',
8
- 50: 'color: #FF0000'
9
- }
10
-
11
- this.browser = (typeof window !== 'undefined');
12
- }
13
-
14
- MyRawStream.prototype.write = function (rec) {
15
- var outType = 'log';
16
-
17
- if(bunyan.nameFromLevel[rec.level] in {info: true, warn: true, error: true}) {
18
- outType = bunyan.nameFromLevel[rec.level];
19
- }
20
-
21
- var logArgs = [(this.browser ? '%c':'') + '[%s] %s: %s',
22
- rec.time.toISOString(),
23
- bunyan.nameFromLevel[rec.level],
24
- rec.msg];
25
-
26
- if(this.browser) {
27
- logArgs.splice(1,0,this.ColorMap[rec.level]);
28
- }
29
-
30
- console[outType].apply(console, logArgs);
31
- }
32
-
33
- module.exports = function(level, customStream) {
34
- return bunyan.createLogger({
35
- name: 'jsflow',
36
- streams: [{
37
- level: level,
38
- stream: new MyRawStream(),
39
- type: 'raw'
40
- }]
41
- });
42
- }
43
-
package/lib/main.js DELETED
@@ -1,49 +0,0 @@
1
- //Global dependencies
2
- node_ws = require('ws');
3
- var msgpack = require('msgpack-js'); //msgpack is faster than json + some obfuscation
4
- var Q = require('q');
5
-
6
- //Local dependencies
7
- var log = require('./log')('debug');
8
- var token = require('./token');
9
- var auth = require('./auth');
10
- var connect = require('./connect');
11
- var CONFIG = require('./config');
12
-
13
- var JsFlow = function(opts) {
14
- //TODO: Throw error on missing parameters in opts
15
- this._config = opts;
16
-
17
- this._connInfo = {};
18
- }
19
-
20
- JsFlow.prototype._onMessage = function(internalMessage) { //Internal method to manage messages
21
- //Process meta-messages
22
- //Process user-messages
23
- //Process group-messages
24
- }
25
-
26
- //Basic callback infrastructure; let devs do more complicated if they need to?
27
- JsFlow.prototype.onmessage = function(message) {} //Public callback for messages directed to me
28
- JsFlow.prototype.ongroupmessage = function(group, message) {} //Public callback for messages directed at group
29
- JsFlow.prototype.onstatechange = function(state) {} //Signal the state
30
-
31
- //Basic public API to connect and send to user / group
32
- JsFlow.prototype.open = function() {
33
- return Q.fcall(token, this._config)
34
- .then(auth)
35
- .then(connect)
36
- .then(function(connInfo) {
37
- log.debug('Successfully connected!')
38
- this._connInfo = connInfo;
39
- return {username: 'somename'}; //Or similar?
40
- });
41
- }
42
- JsFlow.prototype.close = function() {}
43
- JsFlow.prototype.sendUser = function(userid, message) {}
44
- JsFlow.prototype.sendGroup = function(groupid, message) {}
45
-
46
- module.exports = function(opts) {
47
- return new JsFlow(opts);
48
- }
49
-
package/lib/token.js DELETED
@@ -1,34 +0,0 @@
1
- var crypto = require('crypto')
2
-
3
- var log = require('./log')('debug');
4
-
5
- module.exports = function(initObj) {
6
-
7
- var authObj = {applicationKey: initObj.applicationKey,
8
- time: new Date().getTime()};
9
-
10
- if(initObj.userName && initObj.applicationSecret) { //TODO: Move this out into a separate package for backend developers
11
- log.info('Application secret was used. Will self generate token');
12
- log.warn('NOTE! Keep secret a secret, ONLY supply secret for backend or test');
13
-
14
- authObj.userName = initObj.userName; //Also supply desired username
15
-
16
- var hmac = crypto.createHmac('sha256', initObj.applicationSecret);
17
- var stringToSign = new Buffer(JSON.stringify(authObj)).toString('base64');
18
- var sign = hmac.update(stringToSign).digest('base64');
19
- authObj.token = stringToSign+'|'+sign;
20
- }
21
- else if (initObj.publishKey) {
22
- log.info('Application key and publish key was used. Will allow message publish');
23
- authObj.publishKey = initObj.publishKey;
24
- authObj.token = new Buffer(JSON.stringify(authObj)).toString('base64');
25
- }
26
- else {
27
- log.info('Only application was used. Will not allow message publish');
28
- authObj.token = new Buffer(JSON.stringify(authObj)).toString('base64');
29
- }
30
-
31
- console.log(authObj);
32
-
33
- return authObj;
34
- }
package/logTest.js DELETED
@@ -1,49 +0,0 @@
1
- var bunyan = require('bunyan');
2
-
3
- function MyRawStream() {
4
- this.ColorMap = {
5
- 20: 'color: #333333',
6
- 30: 'color: #3333FF',
7
- 40: 'color: #AA9933',
8
- 50: 'color: #FF0000'
9
- }
10
-
11
- this.browser = (typeof window !== 'undefined');
12
- }
13
-
14
- MyRawStream.prototype.write = function (rec) {
15
- var outType = 'log';
16
-
17
- if(bunyan.nameFromLevel[rec.level] in {info: true, warn: true, error: true}) {
18
- outType = bunyan.nameFromLevel[rec.level];
19
- }
20
-
21
- var logArgs = [(this.browser ? '%c':'') + '[%s] %s: %s',
22
- rec.time.toISOString(),
23
- bunyan.nameFromLevel[rec.level],
24
- rec.msg];
25
-
26
- if(this.browser) {
27
- logArgs.splice(1,0,this.ColorMap[rec.level]);
28
- }
29
-
30
- console[outType].apply(console, logArgs);
31
- }
32
-
33
- var log = bunyan.createLogger({
34
- name: 'play',
35
- streams: [
36
- {
37
- level: 'debug',
38
- stream: new MyRawStream(),
39
- type: 'raw'
40
- }
41
- ]
42
- });
43
-
44
- log.trace('this one does not emit');
45
- log.debug('hi on debug'); // console.log
46
- log.info('hi on info'); // console.info
47
- log.warn('hi on warn'); // console.warn
48
- log.error('hi on error'); // console.error
49
-
package/plan.txt DELETED
@@ -1,60 +0,0 @@
1
-
2
- V - JS SDK som byggs i Node med Browserify, behöver kompatibelt & lightweight ws lib ("ws")
3
-
4
- V - Backend från scratch i Python + RabbitMQ, uppdelat i moduler
5
-
6
- Conclusions - refresh
7
- ---------------------
8
- - Direct connection to instance gives best performance, cost for SSL but should be manageable
9
- - SSL cost can be mitigated in the future by having HTTPS request followed by custom encrypted WS
10
- - POST with initial ticket containing username or not. Two variants? With requires high security.
11
- - One signed with private super key (requires a backend round-trip)
12
- - One signed with NO KEY (requires no backend) - NO PUBLISH IS ALLOWED, only SUBSCRIBE. (PUB using REST key)
13
- (- One signed with REST key (requires no backend) - NO custom username. Can post (?) - CORS limit)
14
- - In response, get URL for machine (fully qualified, such as <short-hash>.jsflow.com) and nonce
15
- - Create JS connection, attach nonce UUID in URL, the recieving machine will understand it and be awesome.
16
-
17
- Features
18
- --------
19
-
20
- - Best use of sub-protocol i websocket standarden ?? (JSON vs. Binary & Version !!) alt. Bara binary ??
21
- - JSON - Fuck msgPack (FUTURE without SSL, encrypted SSL as binary stream)
22
- - Size limit / message, 4 kbyte?? Auto-split ?? - OK. Autosplit senare.
23
- - Basic: Prenumerera på kanaler (i förlägning - dokument). Autosubscribe på egen kanal.
24
- - Custom CORS settings - YES !!!
25
- - Future: Presence - HOW (?) Global online "stack", somehow?
26
- - Future: List users in channel (?) - SAME global stack somehow as above?
27
- - Future: History sedan timestamp (optional??)
28
- Now: Alla data paketeras med timestamp? UTC javascript ms.
29
- - Public / private key encryption - optional ?? Secure transport of public keys? Kan få public key från mitt backend? LATER overhead? (NO CHANNELS POSSIBLE)
30
-
31
- - Fråga: RabbitMQ Integrering?? Hur track RabbitMQ servers to connect to?
32
-
33
- - Low volume / high volume (option, eventuellt om man har högre kryptering eller history på den som är low volume) - PER KANAL SUBSCRIBE?. SVAR: Ingen high volume (det körs via datachannels)
34
- - Request data-channel (peer to peer using WebRTC?) - YES
35
-
36
- - Datapack / similar binary packing for space conservation? - NO; maybe later
37
- - End-2-end gzip?? - NO; maybe later
38
- - End-2-end public/private key encryption? (can only be used when one instance == one "user") - NO; maybe later
39
- - end-2-end security can be done with data channels later !!
40
-
41
- - Consolidate ping.py and resource.py into the same "jsFlow-common-core"
42
-
43
- - Tänk igenom allt från början > Break compatability !!
44
-
45
- - LOGS reduce dependency on DynamoDB -> Logga i S3 istället + map-reduce för stats
46
-
47
- - GEO support FROM THE START, with Route 53's awesome geo routing
48
-
49
- - AS VIKTIGT: * cert kräver domännamn för alla burkar (går att fixa med S3 API ? ? ? ) ->
50
- - wss://instance.realm.jsflow.com/ ??? (or preconfig 20 boxes per realm)
51
- - wss://instance.region.realm.jsflow.com/ ??? - Local route 53 in each region?
52
- - wss://instance-region-realm.jsflow.com/ ??? - Separate route 53 for each realm only ???
53
- - wss://shortHash.jsflow.com/ - w. Separate server orchestration for available shortHashes (automated in future, manual for now)
54
- GEO routing sker på initialt http-request
55
- - https://api.jsflow.com/ws (eller liknande), där sen instancen fw:ar till sig själv. Kan faktiskt lika bra va <HASH>.jsflow.com
56
-
57
-
58
-
59
-
60
-
package/src/main.js DELETED
@@ -1,43 +0,0 @@
1
- var WebSocketClient = require('websocket').client;
2
-
3
- var jsflow = function() {
4
- }
5
-
6
- jsflow.prototype.connect = function() {
7
-
8
- var client = new WebSocketClient();
9
-
10
- client.on('connectFailed', function(error) {
11
- console.log('Connect Error: ' + error.toString());
12
- });
13
-
14
- client.on('connect', function(connection) {
15
- console.log('WebSocket client connected');
16
-
17
- connection.on('error', function(error) {
18
- console.log("Connection Error: " + error.toString());
19
- });
20
- connection.on('close', function() {
21
- console.log('echo-protocol Connection Closed');
22
- });
23
- connection.on('message', function(message) {
24
- if (message.type === 'utf8') {
25
- console.log("Received: '" + message.utf8Data + "'");
26
- }
27
- });
28
-
29
- function sendNumber() {
30
- if (connection.connected) {
31
- var number = Math.round(Math.random() * 0xFFFFFF);
32
- connection.sendUTF(number.toString());
33
- setTimeout(sendNumber, 1000);
34
- }
35
- }
36
- sendNumber();
37
- });
38
-
39
- client.connect('ws://localhost:8200/wsTest'); //, 'jsflow'
40
- }
41
-
42
- //TODO: Pass parameters
43
- module.exports = new jsflow();
package/src/main_ws.js DELETED
@@ -1,81 +0,0 @@
1
-
2
- node_ws = require('ws');
3
- var msgpack = require('msgpack-js');
4
-
5
- //Only in a NODE environment !?!?
6
- var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
7
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
8
- require('ssl-root-cas/latest').inject().addFile(__dirname + '/../ssl/GandiStandardSSLCA.pem');
9
-
10
- var jsflow = function() {}
11
-
12
- jsflow.prototype.connect = function() { //'wss://dev.jsflow.com:443/wsTest'
13
-
14
- var xhr = new XMLHttpRequest();
15
- xhr.open("POST", "https://local.jsflow.com/auth/asd", true);
16
- xhr.onreadystatechange = function() {//Call a function when the state changes.
17
- if(this.readyState == 4 && this.status == 200) {
18
- openSocket();
19
- }
20
- else if(this.readyState == 4 && this.status !== 200) {
21
- console.log('ERROR! TODO: handle this in nice way:', this.status);
22
- }
23
- };
24
-
25
- xhr.send(JSON.stringify({token: 'ASKMDalsdkmdaskmadslMALSDMKA)SDua90sd09asd09ad=AS)=A=)SD'}));
26
- //Draft token format, plain text JSON. Contains dynamic info, all is signed.
27
- //Contains reference to key-type and key if signed with key or keytype !! ! ! !! ! ! !! !!! !!
28
- //Key can restrict on account side
29
-
30
- var openSocket = function() {
31
- var ws = new node_ws('wss://local.jsflow.com:443/ws/ninja_loot', ['v0.jsflow', 'v1.jsflow'], {protocolVersion: 13, protocol: 'v0.jsflow,v1.jsflow'});
32
-
33
- var recv = 0;
34
- var totTime = 0;
35
- ws.onopen = function() {
36
- console.log('connected');
37
- //var msg = msgpack.encode(Date.now().toString());
38
- var msg = JSON.stringify(Date.now().toString());
39
- //var msg = Date.now().toString();
40
- ws.send(msg, {mask: true});
41
- };
42
-
43
- ws.onclose = function() {
44
- console.log('disconnected');
45
- };
46
-
47
- ws.onmessage = function(message) {
48
- //var data = msgpack.decode(message.data);
49
- var data = JSON.parse(message.data);
50
- //var data = message.data;
51
- var time = (Date.now() - parseInt(data));
52
- recv += 1;
53
- totTime += time
54
- console.log('Roundtrip time: ' + time + 'ms. Avg: ' + (totTime/recv)+ ' '+recv);
55
- setTimeout(function() {
56
- //var msg = msgpack.encode(Date.now().toString());
57
- var msg = JSON.stringify(Date.now().toString());
58
- //var msg = Date.now().toString();
59
- ws.send(msg, {mask: false});
60
- }, 1);
61
- };
62
- }
63
- /*
64
- ws.on('open', function() {
65
- console.log('connected');
66
- ws.send(Date.now().toString(), {mask: true});
67
- });
68
- ws.on('close', function() {
69
- console.log('disconnected');
70
- });
71
- ws.on('message', function(data, flags) {
72
- console.log('Roundtrip time: ' + (Date.now() - parseInt(data)) + 'ms', flags);
73
- setTimeout(function() {
74
- ws.send(Date.now().toString(), {mask: true});
75
- }, 500);
76
- });
77
- */
78
- }
79
-
80
- //TODO: Pass parameters
81
- module.exports =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gBBEwDzANBgsrBgEE
17
- AbIxAQICGjBEBgNVHR8EPTA7MDmgN6A1hjNodHRwOi8vY3JsLnVzZXJ0cnVzdC5j
18
- b20vVVROLVVTRVJGaXJzdC1IYXJkd2FyZS5jcmwwdAYIKwYBBQUHAQEEaDBmMD0G
19
- CCsGAQUFBzAChjFodHRwOi8vY3J0LnVzZXJ0cnVzdC5jb20vVVROQWRkVHJ1c3RT
20
- ZXJ2ZXJfQ0EuY3J0MCUGCCsGAQUFBzABhhlodHRwOi8vb2NzcC51c2VydHJ1c3Qu
21
- Y29tMA0GCSqGSIb3DQEBBQUAA4IBAQAZU78DPZvia1r9ukkfT+zhxoI5PNIDBA+r
22
- ez6CqYUQH/TeMq9YP/9w8zAdly1MmuLsDD4ULS+YSJ2uFmqsLUKqtWSkcLvrc5R7
23
- RkznehR2W0wdhKEgdB8uS1xwiNy99xk97VkN4j8m4pyspDyVHPi+jAOu8OWcTbzH
24
- m1gAv6+t+jducW0YNA7B6mr4Dd9pVFYV8iiz/qRj7MUEZGC7/irw9IehsK69quQv
25
- 4wMLL2ZfhaQye0btJQzn8bfnGf1gul+Hd96YB5bkXupjfajeVdphXDyQg0MEBzzd
26
- 8/ifBlIK3se2e4/hEfcEejX/arxbx1BJCHBvlEPNnsdw8dvQbdqP
27
- -----END CERTIFICATE-----
package/test.js DELETED
@@ -1,18 +0,0 @@
1
- //var jsFlow = require('./src/main_ws');
2
-
3
- var jsFlow = require('./lib/main')({
4
- applicationKey: '31bc728296d8da7e14e132k', //Mandatory
5
- userToken: 'asdasd', //Optional for super publish
6
- userName: 'someWildUsername',
7
- publishKey: 'asdasd', //Optional for publish
8
- applicationSecret: 'bqihyq8ZGBYEp1BTaoNgos6ZfEgaWv5z8xUp', //For development and backend purposes
9
- customDomain: 'asdasd' //For large customers, custom entrypoint
10
- });
11
-
12
- jsFlow.open()
13
- .then(function(connInfo) {
14
- console.log('Success', connInfo)
15
- })
16
- .fail(function(e) {
17
- console.log('MANAGE FAILURE!', e);
18
- });