stream-js
![Dependencies up to date](https://david-dm.org/GetStream/stream-js.png)
stream-js is the official JavaScript client for Stream, a web service for building scalable newsfeeds and activity streams.
The full documentation is available on GetStream.io/docs. Note that there is also a higher level Node integration which hooks into your ORM.
Installation
Install from NPM
npm install getstream
Install using bower
bower install getstream
Install by downloading the JS file
JS /
Minified JS
Install for parse cloud code
JS
Using with React Native
For use with React Native be sure to use webpack as your bundler. For a bootstrap project for React native and webpack see this project
Usage
var stream = require('getstream');
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET');
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET', 'APP_ID', { location: 'us-west' });
client = stream.connect('YOUR_API_KEY');
user1 = client.feed('user', '1');
user1 = client.feed('user', '1', 'FEED_TOKEN');
user1.get({limit:5, offset:5}, callback);
user1.get({limit:5, id_lt:"e561de8f-00f1-11e4-b400-0cc47a024be0"});
user1.get({limit:5, id_lt:"e561de8f-00f1-11e4-b400-0cc47a024be0"})
.then(function(body) { })
.catch(function(reason) { });
activity = {'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:1'};
user1.addActivity(activity);
activity = {'actor': 1, 'verb': 'run', 'object': 1, 'foreign_id': 'run:1',
'course': {'name': 'Golden Gate park', 'distance': 10},
'participants': ['Thierry', 'Tommaso'],
'started_at': new Date()
};
user1.addActivity(activity);
user1.removeActivity("e561de8f-00f1-11e4-b400-0cc47a024be0");
user1.removeActivity({foreignId: 'tweet:1'});
notification1 = client.feed('notification', '1');
var params = {mark_read: true};
notification1.get(params);
var params = {mark_seen:true};
notification1.get(params);
user1.follow('flat', '42');
user1.unfollow('flat', '42');
user1.follow('flat', '42', { limit: 0 });
user1.followers({limit: '10', offset: '10'});
user1.following({limit: '10', offset: '0'});
user1.follow('flat', '42');
activities = [
{'actor': 1, 'verb': 'tweet', 'object': 1},
{'actor': 2, 'verb': 'tweet', 'object': 3},
];
user1.addActivities(activities);
to = ['user:2', 'user:3'];
activity = {'to': to, 'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:1'};
user1.addActivity(activity);
var feeds = ['flat:1', 'flat:2', 'flat:3', 'flat:4'];
activity = {
'actor': 'User:2',
'verb': 'pin',
'object': 'Place:42',
'target': 'Board:1'
};
client.addToMany(activity, feeds);
var follows = [
{'source': 'flat:1', 'target': 'user:1'},
{'source': 'flat:1', 'target': 'user:2'},
{'source': 'flat:1', 'target': 'user:3'}
];
client.followMany(follows);
token = user1.token;
user1 = client.feed('user', '1', token);
readonlyToken = client.getReadOnlyToken('user', '1');
user1 = client.feed('user', '1', readonlyToken);
Faye
Stream uses Faye for realtime notifications. Below is quick quide to subcribing to feed changes
var stream = require('getstream');
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET', 'SITE_ID');
user1 = client.feed('user', '1');
client = stream.connect('YOUR_API_KEY', null, 'SITE_ID');
user1 = client.feed('user', '1', 'feedtoken');
var subscription = user1.subscribe(function callback() {
});
subscription.cancel();
Docs are available on GetStream.io.
Contributing
First, make sure you can run the test suite. Tests are run via Mocha
mocha test/integration/index.js test/unit/index.js
test/browser/test.html
mocha test/cov.js -R html-cov > cov.html
Releasing
Make sure your working directory is clean. And run:
npm version [ major | minor | patch ]
npm publish