4.3.8 • Published 3 years ago

activity-streams v4.3.8

Weekly downloads
57
License
MIT
Repository
github
Last release
3 years ago

activity-streams.js

License Downloads

A simple tool to facilitate handling and referencing activity streams and it's objects, cutting down on verbosity.

Designed to run in both node.js and the browser.

I am learning about JSON-LD and ActivityStreams2 as I write this library, so suggestions for improvement are very welcome.

Install

Node.js

$ npm install activity-streams

const ASFactory = require('activity-streams');
const ActivityStreams = ASFactory({
  failOnUnkownObjectProperties: false // default
});

Browser

<script src="http://example.com/activity-streams.js"></script>

Once included in a web-page, the ActivityStreams base object should be on the global scope, with the sub-properties ActivityStreams.Object and ActivityStreams.Stream.

Example

const ActivityStreams = ASFactory();

ActivityStreams.Object.create({
  '@id': 'irc://exampleUser@irc.freenode.net',
  '@type': "person",
  displayName: 'Example User',
  url: "http://activitystrea.ms",
  image: {
    url: "http://activitystrea.ms/avatar.jpg",
    mediaType: "image/jpeg",
    width: 250,
    height: 250
  }
});

ActivityStreams.on('activity-object-create', function (obj) {
  console.log('this object was just created: ', obj);
});

ActivityStreams.Object.create({
  '@id': 'irc://irc.freenode.net/activitystreams',
  '@type': "chatroom",
  displayName: '#activitystreams'
});

const exampleUser = ActivityStreams.Object.get('irc://exampleUser@irc.freenode.net');
    // ... returns:
    //  {
    //    '@id': 'irc://exampleUser@irc.freenode.net',
    //    '@type': "person",
    //    displayName: 'Example User',
    //    url: "http://activitystrea.ms",
    //    image: {
    //      url: "http://activitystrea.ms/avatar.jpg",
    //      mediaType: "image/jpeg",
    //      width: 250,
    //      height: 250
    //    }
    //  }

ActivityStreams.Stream({
  '@context': 'send',
  actor: 'irc://exampleUser@irc.freenode.net',
  object: {
    '@type': "message",
    content: "hello world!"
  },
  target: 'irc://irc.freenode.net/activitystreams'
});
    // ... returns:
    //  {
    //    '@context': 'send',
    //    actor: {
    //      '@id': 'irc://exampleUser@irc.freenode.net',
    //      '@type': "person",
    //      displayName: 'Example User',
    //      url: "http://activitystrea.ms",
    //      image: {
    //        url: "http://activitystrea.ms/avatar.jpg",
    //        mediaType: "image/jpeg",
    //        width: 250,
    //        height: 250
    //      }
    //    },
    //    object: {
    //      '@type': "message",
    //      content: "hello world!"
    //    },
    //    target: {
    //      '@id': 'irc://irc.freenode.net/activitystreams',
    //      '@type': "chatroom",
    //      displayName: '#activitystreams'
    //    }
    //  }
4.4.0-alpha.0

3 years ago

4.3.8

4 years ago

4.3.6

4 years ago

4.3.7

4 years ago

4.3.5

4 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.1-alpha.0

5 years ago

4.3.1-alpha.1

5 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.6

8 years ago

2.0.5

9 years ago

2.0.4

10 years ago

2.0.3

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.3

11 years ago

0.3.2

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago