Skip to content

Instantly share code, notes, and snippets.

@push-gists
Last active October 25, 2017 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save push-gists/7ff4ddb0023337e6e6e143eb8d807fc9 to your computer and use it in GitHub Desktop.
Save push-gists/7ff4ddb0023337e6e6e143eb8d807fc9 to your computer and use it in GitHub Desktop.
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');
});
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment