Skip to content

Instantly share code, notes, and snippets.

// Get a reference to the JSON DataType instance
var jsonType = diffusion.datatypes.json();
// DataTypes can also be accessed by name
var binaryType = diffusion.datatypes.get('binary');
// Create a stream for JSON values
session.stream("foo").asType(jsonType).on({
value : function(topic, specification, newValue, oldValue) {
// Receive the new value of a topic, along with the previous value
},
subscribe : function(topic, specification) {
// Notification of subscription
},
unsubscribe : function(topic, specification, reason) {
// Notification of unsubscription
@push-gists
push-gists / twitter.js
Last active May 5, 2016 09:26
Connect to Diffusion using JS API
var diffusion = require('diffusion');
connectToDiffusion();
function connectToDiffusion(){
console.log('Connecting to Diffusion...');
diffusion.connect({
host : 'localhost',
port: 8080,
@push-gists
push-gists / twitter.js
Last active August 3, 2018 12:53
Create JSON topic in JS API
function createTopics(session){
console.log('Adding Topics...');
session.topics.add('twitter', new diffusion.topics.TopicSpecification(diffusion.topics.TopicType.JSON)).then(
function(result) {
console.log('JSON Topic Added : ' + result.topic);
// Start the updates to the topic
startStream(session);
},
@push-gists
push-gists / twitter.js
Created May 5, 2016 09:28
Stream twitter feed into JSON topic
function startStream(session){
console.log('Starting Twitter Stream');
var stream = T.stream('statuses/filter', { track: 'push' })
stream.on('tweet', function (tweet) {
session.topics.update('twitter', tweet); // Update 'twitter' topic with the JSON for each tweet.
})
}
@push-gists
push-gists / json.js
Last active May 5, 2016 13:29
Connect to Diffusion
<script src="diffusion.js"></script>
<script>
connectToDiffusion();
</script>
@push-gists
push-gists / json.js
Last active May 5, 2016 13:29
Subscribe to JSON topic.
function subscribeTopics(session){
var datatype = diffusion.datatypes.json(); // Set DataType to JSON
session.subscribe('twitter').asType(datatype).on({
value : function(topic, specification, newValue, oldValue) {
newValue = newValue.get();
console.log(newValue); // output JSON to console.
}
});
@push-gists
push-gists / subscribe.js
Last active November 14, 2016 15:55
Slack WebHook URL
const webhookUri = "https://hooks.slack.com/services/WEBHOOK_ID";
diffusion.connect({
host: "REAPPT_HOST",
port: "REAPPT_PORT",
principal: "control",
credentials : "password",
}).then(function (session) {
// Connection success!
console.log('Connected to Reappt');
slack.setWebhook(webhookUri);
@push-gists
push-gists / subscribe.js
Last active November 14, 2016 16:28
Subscribe to JSON topic.
function subscribeToTopic(session){
// Set datatype to JSON
var datatype = diffusion.datatypes.json();
session.subscribe('slack').asType(datatype).on({
value : function(topic, specification, newValue, oldValue) {
newValue = newValue.get();
console.log(newValue);