• This repository has been archived on 15/Feb/2023
  • Stars
    star
    131
  • Rank 274,331 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NodeJS Client - Build Activity Feeds & Streams with GetStream.io

Stream Node.js

Build Status npm version Coverage Status

NPM

stream-node-orm is a Node.js (Mongoose & Waterline) client for Stream.

You can sign up for a Stream account at https://getstream.io/get_started.

Note there is also a lower level Node.js - Stream integration library which is suitable for all JavaScript applications.

Build Activity Streams & News Feeds

Examples of what you can build

You can build:

  • Activity streams such as those seen on Github
  • A Twitter style newsfeed
  • A feed like Instagram or Pinterest
  • Facebook style newsfeeds
  • A notification system

Supported ORMs

Stream node currently supports:

  • Mongoose (full support, both serialization and enrichment)
  • Waterline (partial support, enrichment only)

Demo

You can check out our example app on Github https://github.com/GetStream/Stream-Example-Nodejs

Installation

Step 1 - NPM

Install getstream_node package with npm:

npm install getstream-node --save

Step 2 - Config file

Copy getstream.js config file from node_modules/getstream-node into the root directory of your application Make sure you require the getstream-node early on in your application (eg. in app.js)

Step 3 - Get your API key

Login with Github on getstream.io and edit the configuration values for apiKey, apiSecret and apiAppId in your getstream.js file (you can find them in the dashboard).

Model integration

Stream Node.js can automatically publish new activities to your feeds. To do that you only need to register the models you want to publish with this library.

var stream = require('getstream-node');

var tweetSchema = Schema({
  text    : String,
  user   : { type: Schema.Types.ObjectId, ref: 'User' }
});

tweetSchema.plugin(stream.mongoose.activity);

// register your mongoose connection with the library
stream.mongoose.setupMongoose(mongoose);

Every time a Tweet is created it will be added to the user's feed. Users which follow the given user will also automatically get the new tweet in their feeds.

Activity Fields

Models are stored in feeds as activities. An activity is composed of at least the following fields: actor, verb, object, time. You can also add more custom data if needed. The Activity mixin will try to set things up automatically:

object is a reference to the model instance actor is a reference to the user attribute of the instance verb is a string representation of the class name

By default the actor field will look for an attribute called user or actor and a field called created_at to track creation time. If your user field is called differently you'll need to tell us where to look for it. Below shows an example how to set things up if your user field is called author.

var tweetSchema = Schema({
  text    : String,
  author   : { type: Schema.Types.ObjectId, ref: 'User' }
});

tweetSchema.plugin(stream.mongoose.activity);

tweetSchema.methods.activityActorProp = function() {
  return 'author';
}

Customizing the Activity

Sometimes you'll want full control over the activity that's send to getstream.io. To do that you can overwrite the default createActivity method on the model

tweetSchema.methods.createActivity = function() {
	// this is the default createActivity code, customize as you see fit.
      var activity = {};
      var extra_data = this.activityExtraData();
      for (var key in extra_data) {
          activity[key] = extra_data[key];
      }
      activity.to = (this.activityNotify() || []).map(function(x){return x.id});
      activity.actor = this.activityActor();
      activity.verb = this.activityVerb();
      activity.object = this.activityObject();
      activity.foreign_id = this.activityForeignId();
      if (this.activityTime()) {
          activity.time = this.activityTime();
      }
      return activity;
  }

Feed Manager

This packages comes with a feed_manager class that helps with all common feed operations.

Feeds Bundled with feed_manager

To get you started the manager has 4 feeds pre-configured. You can add more feeds if your application needs it. The three feeds are divided in three categories.

User Feed:

The user feed stores all activities for a user. Think of it as your personal Facebook page. You can easily get this feed from the manager.

FeedManager.getUserFeed(req.user.id);
News Feeds:

The news feeds store the activities from the people you follow. There is both a flat newsfeed (similar to twitter) and an aggregated newsfeed (like facebook).

var flatFeed = FeedManager.getNewsFeeds(foundUser._id)['timeline_flat'];
var aggregatedFeed = FeedManager.getNewsFeeds(req.user.id)['timeline_aggregated'];
Notification Feed:

The notification feed can be used to build notification functionality.

Notification feed

Below we show an example of how you can read the notification feed.

var notificationFeed = FeedManager.getNotificationFeed(req.user.id);

By default the notification feed will be empty. You can specify which users to notify when your model gets created. In the case of a retweet you probably want to notify the user of the parent tweet.

tweetSchema.methods.activityNotify = function() {
  if (this.isRetweet) {
	  target_feed = FeedManager.getNotificationFeed(this.parent.author.id);
	  return [target_feed];
  }
};

Another example would be following a user. You would commonly want to notify the user which is being followed.

followSchema.methods.activityNotify = function() {
  target_feed = FeedManager.getNotificationFeed(this.target._id);
  return [target_feed];
};

Follow a Feed

To follow the created newsfeeds you need to notify the system about follow relationships. The manager comes with APIs to let a user's news feeds follow another user's feed. This code lets the current user's flat and aggregated feeds follow the target_user's personal feed.

FeedManager.followUser(userId, targetId);

Showing the Newsfeed

Activity Enrichment

When you read data from feeds, a like activity will look like this:

{'actor': 'User:1', 'verb': 'like', 'object': 'Like:42'}

This is far from ready for usage in your template. We call the process of loading the references from the database enrichment. An example is shown below:

router.get('/flat', ensureAuthenticated, function(req, res, next){
    var flatFeed = FeedManager.getNewsFeeds(req.user.id)['timeline_flat'];

    flatFeed.get({})
    	.then(function (body) {
        	var activities = body.results;
        	return StreamBackend.enrichActivities(activities);
        })
        .then(function (enrichedActivities) {
            return res.render('feed', {location: 'feed', user: req.user, activities: enrichedActivities, path: req.url});
        })
        .catch(next)
    });
});

Promises are used to pipe the asynchronous result of flatFeed.get and StreamBackend.enrichActivities through our code.

Temporarily Disabling the Model Sync

Model synchronization can be disabled manually via environment variable.

NODE_ENV=test npm test

Automatically Populate Paths:

You can automatically populate paths during enrichment via the pathsToPopulate static.

tweetSchema.statics.pathsToPopulate = function() {
  return ['link'];
};

Full Documentation and Low Level APIs Access

When needed you can also use the low level JavaScript API directly. Documentation is available at the Stream website.

var streamNode = require('getstream-node');
var client = streamNode.FeedManager.client
// client.addActivity, client.removeActivity etc are all available

Enrichment

You can use the enrichment capabilities of this library directly.

var streamNode = require('getstream-node');
var streamMongoose = new streamNode.MongooseBackend()
// or
var streamWaterline = new streamNode.WaterlineBackend()
// now enrich the activities
streamWaterline.enrichActivities(activities).then(function(enrichedActivities) {
	res.json({'results': enrichedActivities})
}).catch(function(err) {
	sails.log.error('enrichment failed', err)
	return res.serverError('failed to load articles in the feed')
})

Customizing Enrichment (since 1.4.0)

By default the enrichment system assumes that you're referencing items by their id. Sometimes you'll want to customize this behavior. You might for instance use a username instead of an id. Alternatively you might mant to use a caching layer instead of the ORM for loading the data. The example below shows how to customize the lookup for all User entries.

// subclass streamMongoose
function streamCustomEnrichment() {};
streamCustomEnrichment.prototype = {
    loadUserFromStorage: function(modelClass, objectsIds, callback) {
        var found = {};
        var paths = [];
        if (typeof(modelClass.pathsToPopulate) === 'function') {
            var paths = modelClass.pathsToPopulate();
        }
	// Here's the magic, use a username instead of id
        modelClass.find({
            username: {
                $in: objectsIds
            }
        }).populate(paths).exec(function(err, docs) {
            for (var i in docs) {
                found[docs[i]._id] = docs[i];
            }
            callback(err, found);
        });
    }
}
util.inherits(streamCustomEnrichment, streamNode.mongoose.Backend);

Contributing

Running tests:

npm test

Releasing

Make sure your working directory is clean and run:

npm install
npm version [ major | minor | patch ]
npm publish

Supported Node.js Versions

v10.x
v12.x
v14.x

Copyright and License Information

Copyright (c) 2015-2017 Stream.io Inc, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

More Repositories

1

Winds

A Beautiful Open Source RSS & Podcast App Powered by Getstream.io
JavaScript
8,813
star
2

stream-chat-android

๐Ÿ’ฌ Android Chat SDK โžœ Stream Chat API. UI component libraries for chat apps. Kotlin & Jetpack Compose messaging SDK for Android chat
Kotlin
1,409
star
3

vg

Virtualgo: Easy and powerful workspace based development for go
Go
1,311
star
4

whatsApp-clone-compose

๐Ÿ“ฑ WhatsApp clone project demonstrates modern Android development built with Jetpack Compose and Stream Chat/Video SDK for Compose.
Kotlin
1,240
star
5

stream-react-example

Use React and Redux to build your own feature-rich and scalable social network app! Visit cabin.getstream.io for an overview of all 8 tutorials and a live demo.
HTML
923
star
6

stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
Dart
839
star
7

stream-chat-react-native

๐Ÿ’ฌ React-Native Chat SDK โžœ Stream Chat. Includes a tutorial on building your own chat app experience using React-Native, React-Navigation and Stream
TypeScript
792
star
8

purposeful-ios-animations

Meaningful iOS animations built to inspire you in creating useful animations for your apps. Each of the animations here was cloned with SwiftUI. Have you seen an app animation you love to rebuild and add to this repo?, contact [@amos_gyamfi](https://twitter.com/amos_gyamfi) and [@stefanjblos](https://twitter.com/stefanjblos) on Twitter.
Swift
751
star
9

stream-chat-swift

๐Ÿ’ฌ iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
Swift
750
star
10

swiftui-spring-animations

This repository serves as your reference and complete guide for SwiftUI Spring Animations. It demonstrates use cases for the various types of spring animations and spring parameters. No more guessing the values of the parameters for spring animations you create for your next iOS app.
Swift
679
star
11

stream-chat-react

React Chat SDK โžœ Stream Chat ๐Ÿ’ฌ
TypeScript
552
star
12

webrtc-android

๐Ÿ›ฐ๏ธ A versatile WebRTC pre-compiled Android library that reflects the recent WebRTC updates to facilitate real-time video chat for Android and Compose.
Kotlin
546
star
13

awesome-saas-services

A curated list of the best in class SaaS services for developers and business owners.
475
star
14

stream-django

Django Client - Build Activity Feeds & Streams with GetStream.io
Python
453
star
15

sketchbook-compose

๐ŸŽจ Jetpack Compose canvas library that helps you draw paths, images on canvas with color pickers and palettes.
Kotlin
436
star
16

avatarview-android

โœจ Supports loading profile images with fractional styles, shapes, borders, indicators, and initials for Android.
Kotlin
431
star
17

webrtc-in-jetpack-compose

๐Ÿ“ฑ This project demonstrates WebRTC protocol to facilitate real-time video communications with Jetpack Compose.
Kotlin
391
star
18

AvengersChat

๐Ÿ’™ Android sample Avengers chat application using Stream Chat SDK based on MVVM (ViewModel, Coroutines, Room, Hilt, Repository) architecture.
Kotlin
366
star
19

stream-video-android

๐Ÿ“ฒ Android Video SDK. Stream's versatile Core + Compose UI component libraries that allow you to build video calling, audio room, and, live streaming apps based on Webrtc running on Stream's global edge network.
Kotlin
361
star
20

stream-draw-android

๐Ÿ›ฅ Stream Draw is a real-time multiplayer drawing & chat game app built entirely with Jetpack Compose.
Kotlin
339
star
21

stream-chat-swiftui

SwiftUI Chat SDK โžœ Stream Chat ๐Ÿ’ฌ
Swift
329
star
22

stream-js

JS / Browser Client - Build Activity Feeds & Streams with GetStream.io
JavaScript
325
star
23

react-native-example

React Native Activity Feed example application
JavaScript
321
star
24

effects-library

The Effects Library allows developers to create sophisticated and realistic particle systems such as snow, fire, rain, confetti, fireworks, and smoke with no or minimal effort.
Swift
319
star
25

stream-laravel

Laravel Client - Build Activity Feeds & Streams with GetStream.io
PHP
314
star
26

flutter-samples

A collection of sample apps that use Stream
Dart
298
star
27

stream-rails

Rails Client - Build Activity Feeds & Streams with GetStream.io
Ruby
257
star
28

Streamoji

:godmode: Custom emoji rendering library for iOS apps with support for GIF & still images - plug-in extension for UITextView - performance, cache โœ… - Made with ๐Ÿ’˜ by @GetStream
Swift
248
star
29

react-native-bidirectional-infinite-scroll

๐Ÿ“œ React Native - Bidirectional Infinite Smooth Scroll
TypeScript
220
star
30

WhatsApp-Clone-Android

Tutorial which teaches you how to build a whatsapp chat clone on android using Kotlin, viewmodels, navigation component and Stream
Kotlin
218
star
31

butterfly

๐Ÿฆ‹ Butterfly helps you to build adaptive and responsive UIs for Android with Jetpack WindowManager.
Kotlin
213
star
32

slack-clone-react-native

Build a slack clone using react-native, Stream and react-navigation
JavaScript
206
star
33

react-native-activity-feed

Official React Native SDK for Activity Feeds
JavaScript
194
star
34

motionscape-app

MotionScape is your animations playground as a developer. You can see all animations and their parameters in effect with beautifully designed and handcrafted animation examples.
Swift
165
star
35

Android-Samples

๐Ÿ“• Provides a list of samples that utilize modern Android tech stacks and Stream Chat SDK for Android and Compose.
Kotlin
157
star
36

node-express-mongo-api

Starter project for a REST API with Node.js, Express & MongoDB ๐Ÿ”‹
JavaScript
151
star
37

stream-chat-js

JS / Browser Client - Build Chat with GetStream.io
TypeScript
149
star
38

stream-php

PHP Client - Build Activity Feeds & Streams with GetStream.io
PHP
139
star
39

meeting-room-compose

๐ŸŽ™๏ธ A real-time meeting room app built with Jetpack Compose to demonstrate video communications.
Kotlin
136
star
40

react-activity-feed

Stream React Activity Feed Components
TypeScript
136
star
41

stream-python

Python Client - Build Activity Feeds & Streams with GetStream.io
Python
136
star
42

flat-list-mvcp

"maintainVisibleContentPosition" prop support for Android react-native
TypeScript
131
star
43

stream-log

๐Ÿ›ฅ A lightweight and extensible logger library for Kotlin and Android.
Kotlin
118
star
44

website-react-examples

TypeScript
118
star
45

react-native-samples

A collection of sample apps built using GetStream and React Native
JavaScript
116
star
46

stream-video-swift

SwiftUI Video SDK โžก๏ธ Stream Video ๐Ÿ“น
Swift
112
star
47

flutter-instagram-clone

An Instagram clone using Flutter and Stream Feeds
Dart
109
star
48

django_twitter

An example app built using getstream.io
Python
108
star
49

twitter-clone

Learn how to build a functional Twitter clone using Stream, 100ms, Algolia, RevenueCat and Mux ๐Ÿ˜Ž
Swift
107
star
50

accessible-inclusive-ios-animations

Provide ways to limit animations/motion people find jarring in your apps. This repo demonstrates accessible and inclusive iOS animations/motion with practical examples and best practices.
Swift
106
star
51

Stream-Example-Nodejs

An example app built using getstream.io
JavaScript
96
star
52

Android-Video-Samples

๐Ÿ“˜ Provides a collection of samples that utilize modern Android tech stacks and Stream Video SDK for Kotlin and Compose.
Kotlin
87
star
53

react-native-audio-player

JavaScript
86
star
54

stream-result

๐ŸšŠ Railway-oriented library to easily model and handle success/failure for Kotlin, Android, and Retrofit.
Kotlin
85
star
55

stream-ruby

Ruby Client - Build Activity Feeds & Streams with GetStream.io
Ruby
83
star
56

stream-chat-unity

๐Ÿ’ฌ Unity Chat Plugin by Stream โžœ These assets are the solution for adding an in-game text chat system to your Unity game.
C#
83
star
57

stream-go2

GetStream.io Go client
Go
82
star
58

stream-cli

Configure & manage Stream applications from the command line. ๐Ÿš€
Go
80
star
59

stream-tutorial-projects

This repo contains SwiftUI, Jetpack Compose, JS & React Native projects for some of the iOS and Android tutorial series in the Stream Developers YouTube channel (https://youtube.com/playlist?list=PLNBhvhkAJG6tJYnY-5oZ1JCp2fBNbVL_6).
Swift
80
star
60

mongodb-activity-feed

Activity Feed, Timeline, News Feed, Notification Feed with MongoDB, Node and CRDTs
JavaScript
77
star
61

TinyGraphQL

๐ŸŒธ Simple and lightweight GraphQL query builder for the Swift language - Made with ๐Ÿ’˜ by @GetStream
Swift
76
star
62

android-video-chat

โšก๏ธ Android Video Chat demonstrates a real-time video chat application by utilizing Stream Chat & Video SDKs.
Kotlin
75
star
63

slack-clone-expo

Slack clone using Expo, Stream and react-navigation
JavaScript
75
star
64

stream-feed-flutter

Stream Feed official Flutter SDK. Build your own feed experience using Dart and Flutter.
Dart
69
star
65

stream-chat-go

Stream Chat official Golang API Client
Go
68
star
66

fullstack-nextjs-whatsapp-clone

A sample codebase showcasing Stream Chat and Video to resembling WhatsApp, using NextJS, TailwindCSS and Vercel.
TypeScript
67
star
67

Stream-Example-Py

An example app built using getstream.io
CSS
61
star
68

SwiftUIMessagesUIClone

The SwiftUI Messages Clone consists of layout and composition clones of the iOS Messages app. It has Messages-like bubble and screen effects, reactions, and animations, all created with SwiftUI.
Swift
60
star
69

encrypted-web-chat

A web chat application end-to-end encrypted with the Web Crypto API
JavaScript
59
star
70

stream-video-js

GetStream JavaScript Video SDK
TypeScript
57
star
71

swift-lambda

ฮป Write HTTP services in Swift, deploy in seconds - Powered by AWS Lambda Runtime & Serverless Framework - Made with ๐Ÿ’˜ by @GetStream
Swift
57
star
72

stream-chat-python

Stream Chat official Python API Client
Python
56
star
73

liveshopping-android

๐Ÿ“น A demo app showcasing real-time livestreaming and messaging capabilities built with Jetpack Compose and Stream SDKs.
Kotlin
54
star
74

stream-java

Java Client - Build Activity Feeds & Streams with GetStream.io
Java
53
star
75

Stream-Example-Parse

Stream-Example-Parse
JavaScript
46
star
76

Stream-Example-PHP

An example app built using getstream.io https://getstream.io
PHP
46
star
77

android-chat-tutorial

Sample apps for the Stream Chat Android SDK's official tutorial
Java
46
star
78

stream-meteor

Meteor Client - Build Activity Feeds & Streams with GetStream.io
JavaScript
45
star
79

stream-video-flutter

Flutter Video SDK - Build your own video app experience using Dart, Flutter and the Stream Video Messaging API.
Dart
45
star
80

discord-clone-nextjs

Building a discord clone using NextJS, TailwindCSS, and the Stream Chat and Audio and Video SDKs.
TypeScript
45
star
81

python-chat-example

Chat with Python, Django and React
JavaScript
44
star
82

SwiftUIChristmasTree

๐ŸŒฒ Pure SwiftUI christmas tree with yearly updates. Enjoy ๐ŸŽ„
Swift
44
star
83

stream-chat-net

Stream Chat official .NET API Client
C#
43
star
84

stream-chat-dart

Dart SDK - Build Chat with GetStream.io
Dart
42
star
85

Stream-Example-Go-Cassandra-API

Go-powered API example using Cassandra
Go
38
star
86

Stream-Example-Rails

An example app built using getstream.io
Ruby
38
star
87

Stream-Example-Android

Java
38
star
88

foldable-chat-android

๐Ÿฆš Foldable chat Android demonstrates adaptive and responsive UIs with Jetpack WindowManager API.
Kotlin
35
star
89

stream-net

NET Client - Build Activity Feeds & Streams with GetStream.io
C#
35
star
90

stream-swift

Swift client for Stream API
Swift
35
star
91

stream-chat-angular

๐Ÿ’ฌ Angular Chat SDK โžœ Stream Chat. Build a chat app with ease.
TypeScript
34
star
92

SwiftUI-open-voip-animations

SwiftUI animations and UI designs for iOS calling, meeting, audio-room, and live streaming use cases. Find something missing? Let @amos_gyamfi know on Twitter.
33
star
93

node-restify-mongo-api

Starter project for a REST API with Node.js, Restify & MongoDB ๐Ÿ”‹
JavaScript
32
star
94

stream-chat-unreal

The official Unreal SDK for Stream Chat
C++
32
star
95

build-viking-sample

Sample app for Build Viking.
Dart
31
star
96

swift-activity-feed

Stream Swift iOS Activity Feed Components
Swift
29
star
97

stream-chat-ruby

Stream Chat official Ruby API Client
Ruby
29
star
98

swiftui-iMessage-clone

Swift
29
star
99

sign-in-with-apple-swift-example

iOS + Node.js authentication using Sign in with Apple
Swift
28
star
100

rate_limiter

A pure dart package to apply useful rate limiting strategies on regular functions.
Dart
28
star