Skip to content

Instantly share code, notes, and snippets.

@push-gists
push-gists / gist:64f61b7c837849d4525f145627681922
Last active October 25, 2017 12:41
The agent client receives topic notifications about structural changes to the topic tree. In this application, the addition of a topic under /chat/chatsessions will mean that a new user has visited the website.
var registerTopicListener = function (session){
var listener = {
onDescendantNotification: function() {},
onTopicNotification: function(topicPath, topicSpecification, type) {
addUser(topicPath);
},
onClose: function() {},
onError: function(error) {}
};
@push-gists
push-gists / gist:7ff4ddb0023337e6e6e143eb8d807fc9
Last active October 25, 2017 12:39
This code shows how we receive and display new chat messages. The client registers a callback which appends all incoming messages to an HTML element with the id 'chatmessages.' Each new value streamed will also have an associated author, sequence number and timestamp.
...
session.stream(chatTopic).asType(diffusion.datatypes.json())
.on('value', function (topic, specification, newValue, oldValue) {
appendMessageToChat(newValue.value.get(), '#chatmessages');
});
...
@push-gists
push-gists / gist:8ed8c52ca067700fb48a3d11bdc8917e
Last active October 25, 2017 11:38
Appending a new chat message to the time series topic. Using a JSON event to represent messages allows us to add extra metadata about the sender.
var sendTextMessage = function(session){
var input = $("#chatinput").val();
$("#chatinput").val('');
if(session.isConnected() && (input.replace(/\s/g, '').length > 0)){
var message = {
origin: chatUserId,
type: 'txtmsg',
payload: input
};
session.timeseries.append(chatTopic, message);
@push-gists
push-gists / gist:16098f2d32bcff0e62d20bd966d33aba
Last active October 25, 2017 11:28
Creating a Time Series Topic with a specification and subscribing to it. The specification determines how many events the topic retains and how many are received when the topic is subscribed to.
var createTopic = function(topicPath){
var specification = new diffusion.topics.TopicSpecification( diffusion.topics.TopicType.TIME_SERIES, {
TIME_SERIES_EVENT_VALUE_TYPE : "json",
TIME_SERIES_SUBSCRIPTION_RANGE : "limit 30000",
TIME_SERIES_RETAINED_RANGE : "limit 30000"
});
session.topics.add(topicPath, specification);
session.subscribe(topicPath);
}
...
topicControl.addTopic(topicPath,
TopicType.JSON,
callback);
...
TopicControl topicControl = session.feature(TopicControl.class);
Session session = Diffusion.sessions().open("ws://localhost:8080");
@push-gists
push-gists / Gatekeeper.java
Created January 10, 2017 14:53
A Java Reappt client that subscribes another client to a topic
import java.util.Collection;
import com.pushtechnology.diffusion.client.Diffusion;
import com.pushtechnology.diffusion.client.callbacks.ErrorReason;
import com.pushtechnology.diffusion.client.features.control.topics.SubscriptionControl;
import com.pushtechnology.diffusion.client.features.control.topics.SubscriptionControl.SubscriptionByFilterCallback;
import com.pushtechnology.diffusion.client.session.Session;
import com.pushtechnology.diffusion.client.types.ErrorReport;
public class Gatekeeper {
@push-gists
push-gists / requester.js
Created January 10, 2017 14:50
A simple JS Reappt client that attempts subscription to topics with different permissions
var diffusion = require('diffusion');
// Connect to Reappt with requester credentials
diffusion.connect({
host : 'approvingBoldDaVinci.us.reappt.io',
port : 443,
secure : true,
principal : 'requester',
credentials : 'retseuqer'
}).then(function(session) {
@push-gists
push-gists / keymaster.js
Created January 10, 2017 14:41
A simple JS Reappt client that updates the security and system authentication stores.
var diffusion = require('diffusion');
// Connect to Reappt with admin credentials
diffusion.connect({
host : 'approvingBoldDaVinci.us.reappt.io',
port : 443,
secure : true,
principal : 'admin',
credentials : 'nimda'
}).then(function(session) {