This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var diffusion = require('diffusion'); | |
connectToDiffusion(); | |
function connectToDiffusion(){ | |
console.log('Connecting to Diffusion...'); | |
diffusion.connect({ | |
host : 'localhost', | |
port: 8080, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="diffusion.js"></script> | |
<script> | |
connectToDiffusion(); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webhookUri = "https://hooks.slack.com/services/WEBHOOK_ID"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateSlackChannel(value){ | |
slack.webhook({ | |
channel: "#diffusion", | |
username: "Diffusion", | |
text: value | |
}, | |
function(error, response) { | |
// Output error / response here | |
}); | |
} |
OlderNewer