Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a3e847d
Add new structure for realtime/channel details
tomczoink May 5, 2020
aa718d8
Updated channels/overview page
May 19, 2020
4628497
Update overview.textile
MarkWoulfeAbly May 20, 2020
ebeba62
Updated channel options partial
May 20, 2020
c6fc36e
Updted channel parameters page
May 20, 2020
9af0551
Updated rewind page
May 21, 2020
b29e1f6
Updated deltas page
May 21, 2020
6a252c1
Updated channel parameter example
MarkWoulfeAbly May 22, 2020
2b25a80
Revert overview changes to realtime docs
tomczoink May 29, 2020
5e6deaf
Resolving a number of matt's comments
Jun 1, 2020
e164484
Added delta JSBin code samples
tomczoink Jun 3, 2020
96128ca
Updated deltas code samples
tomczoink Jun 3, 2020
2940a0b
Shorted deltas code sample
tomczoink Jun 3, 2020
bfd02c2
Const/let to var in channel parameter code snippets
tomczoink Jun 3, 2020
4a4bbf6
Various code fixes and additions for channel-parameters
tomczoink Jun 3, 2020
45e4d35
Removed triple spaces in channel-parameters docs
tomczoink Jun 3, 2020
17afcc2
Corrected MQTT code example from JS to nodejs
tomczoink Jun 3, 2020
5c5f7d6
Added swift code samples to channel parameter pages
tomczoink Jun 3, 2020
bf1ce6f
Updated MQTT code samples to use generated API key name/secret
tomczoink Jun 3, 2020
0bd0992
Fixed various javascript code snippets
tomczoink Jun 3, 2020
4c0ecd2
Updated references to channel-params pages
tomczoink Jun 3, 2020
c7918f6
Corrected various broken code samples and links in channel parameter …
tomczoink Jun 3, 2020
6a143c2
Update content/realtime/channels/channel-parameters/deltas.textile
MarkWoulfeAbly Jun 3, 2020
076a5f2
Update content/realtime/channels/channel-parameters/deltas.textile
MarkWoulfeAbly Jun 3, 2020
0b45978
Improved channel parameter overview
Jun 5, 2020
e4d8e74
Reformatted content in the rewind page
Jun 5, 2020
ca48225
Added delta image
MarkWoulfeAbly Jun 5, 2020
58fdb13
Merge branch 'deltas-additions' of https://github.com/ably/docs into …
MarkWoulfeAbly Jun 5, 2020
c36345b
fixed duplication issue
MarkWoulfeAbly Jun 5, 2020
150d011
updated channel param titles
MarkWoulfeAbly Jun 5, 2020
cafbff8
Linked to channel options
MarkWoulfeAbly Jun 5, 2020
f1a5075
Added deltas image to deltas documentation
tomczoink Jun 5, 2020
e82a680
calrified non-supported libraries
Jun 8, 2020
b72bf94
minor formatting changes
Jun 8, 2020
d5af127
Updated rewind and delta descriptions
Jun 8, 2020
93a9b00
Updated delta size demo to new js version
tomczoink Jun 8, 2020
ac2cb52
Merge branch 'deltas-additions' of https://github.com/ably/docs into …
Jun 8, 2020
55f23be
updated overview based on feedback
Jun 8, 2020
4df4584
Reduce length of delta examples
tomczoink Jun 8, 2020
8aba69b
Fix sidebar ordering for realtime
tomczoink Jun 8, 2020
58a2263
Correct api ref in channel parameters for csharp
tomczoink Jun 8, 2020
ff006d4
fix: update jsbin pointers for realtime/channel-deltas-size
kennethkalmer Jun 8, 2020
b3d2a66
Add new code samples for channel params
tomczoink Jun 9, 2020
0ecaa00
Remove ./lib from code example on deltas
tomczoink Jun 9, 2020
6c80cd5
Fixed broken hrefs in channel parameter docs
tomczoink Jun 9, 2020
73a1412
Updated delta see/mqtt code examples
tomczoink Jun 9, 2020
8e6ead3
shortened some information
MarkWoulfeAbly Jun 9, 2020
7fd3e82
fixed broken url
MarkWoulfeAbly Jun 9, 2020
830ce56
typos fixed
MarkWoulfeAbly Jun 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file addedapp/assets/images/realtime/delta-messages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions content/code/realtime/channel-deltas-size.code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
[--- Javascript ---]
var receivedLogNotDeltas = document.getElementById('received-not-deltas');
var receivedLogDeltas = document.getElementById('received-deltas');
var totalWithoutDeltas = document.getElementById('no-delta');
var totalWithDeltas = document.getElementById('delta');

var clientOptions = {
key: '{{API_KEY}}',
plugins: {
vcdiff: {
decode: decodeAndCountSize
}
}
};

var deltaChannelOptions = {
params: {
delta: 'vcdiff',
rewind: 10
}
};

var ably = new Ably.Realtime(clientOptions);

var deltaChannel = ably.channels.get('[product:cttransit/gtfsr]vehicle:all', deltaChannelOptions);

var channel = ably.channels.get('[product:cttransit/gtfsr]vehicle:all');


/* Subscribe to a channel normally */
channel.subscribe(function(message, err) {
var size = getMessageSize(message);
totalWithoutDeltas.innerHTML = parseInt(totalWithoutDeltas.innerHTML, 10) + size;
receivedLogNotDeltas.insertAdjacentHTML('afterbegin', '<li>' + JSON.stringify(message.data) + '</li>');
});

/* Subscribe to a channel using deltas */
deltaChannel.subscribe(function(message) {
receivedLogDeltas.insertAdjacentHTML('afterbegin', '<li>' + JSON.stringify(message.data) + '</li>');
});

/* Recursively work out the size of the message's elements */
function getMessageSize(message) {
var bytes = 0;
if (typeof message === 'boolean') {
bytes += 4;
} else if (typeof message === 'string') {
bytes += message.length * 2;
} else if(typeof message === 'object') {
for (var i in message) {
/* Calculate the size of components of the object */
bytes += i.length * 2;
bytes += getMessageSize(message[i]);
}
} else if (typeof message == 'number') {
bytes += 8;
} else if (message === undefined) {
bytes += 1;
}
return bytes;
}

/* Wrapper for the vcdiff decoder, allowing us to check the size of the original diff */
function decodeAndCountSize(delta, source) {
totalWithDeltas.innerHTML = parseInt(totalWithDeltas.innerHTML, 10) + delta.byteLength;
var result = decoder.decode(delta, source);
return result;
}
[--- /Javascript ---]

[--- HTML ---]
<html>
<head>
<script src="//cdn.ably.io/lib/ably-1.js"></script>
<script src="//cdn.ably.io/lib/vcdiff-decoder.min-1.js"></script>
</head>
<body>
<h1><a href="https://www.ably.io" target="_blank" rel="noopener"><img src="/images/favicon.png">Ably realtime deltas comparison</a></h1>
<p>A simple example demonstrating how using <a href="https://www.ably.io/documentation/realtime/channels/deltas" target="_blank">deltas</a> compares to not using deltas.</p>
<p>This example by default is subscribed to the CTtransit bus source, found on the <a href="https://www.ably.io/hub" target="_blank">Ably Hub</a>. If you want to test this on one of your own channels, you can replace the API key with one of your own.</p>

<p>Cumulative size of messages sent <b>without deltas</b>: <span id="no-delta">0</span> Bytes</p>
<p>Cumulative size of messages sent <b>with deltas</b>: <span id="delta">0</span> Bytes</p>
<section>
<h2>No deltas output</h2>
<ul id="received-not-deltas"></ul>

<h2>Deltas output</h2>
<ul id="received-deltas"></ul>
</tr>
</section>
</body>
</html>
[--- /HTML ---]

[--- CSS ---]
body {
font-family: Arial, Sans Serif;
font-size: 13px;
min-width: 700px;
}

h1 {
font-family: Arial, Sans Serif;
font-size: 18px;
}

a, a:visited, a:active {
color: #ed760a;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

section {
padding: 10px 4px;
column-count: 2;
column-gap: 5px;
}

h2 {
margin: 0 auto 4px;
text-align: center;
}

ul {
display: block;
height: calc(100vh - 230px);
margin:0;
padding:0;
border: 1px solid #CCC;
overflow: scroll;
background-color: #EEE;

}

li {
padding: 2px 5px;
list-style: none;
line-height: 2em;
}

li:nth-child(even) {
background:#ccc;
}

section {
column-count: 2;
}
[--- /CSS ---]
74 changes: 74 additions & 0 deletions content/code/realtime/channel-deltas.code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
[--- Javascript ---]
var apiKey = '{{API_KEY}}';
var channelName = '{{RANDOM_CHANNEL_NAME}}';
var realtimePublisher = new Ably.Realtime({ key: apiKey });

/* Initialize subscriber with delta plugin. Makes use of the vcdiff-decoder we've included in the HTML */
var realtimeSubscriber = new Ably.Realtime({ key: apiKey,
plugins: {
vcdiff: vcdiffDecoder
}
});
var deltaChannelOptions = {
params: {
delta: 'vcdiff'
}
};

var channelPublisher = realtimePublisher.channels.get(channelName);

/* Specify in the channel options to use deltas for this channel */
var channelSubscriber = realtimeSubscriber.channels.get(channelName, deltaChannelOptions);

$('input#publish').on('click', function() {
show('Publishing message', 'orange');
channelPublisher.publish('event', 'data', function(err) {
if (err) {
show('✗ Publish failed: ' + err.message, 'red');
} else {
show('✓ Publish successful', 'green');
}
});
});

channelSubscriber.subscribe(function(message) {
show('⬅ Received message on subscription', 'green');
});

function show(status, color) {
$('#channel-status').append($('<li>').text(status).css('color', color));
}
[--- /Javascript ---]

[--- HTML ---]
<script type="text/javascript" src="//cdn.ably.io/lib/ably.min-1.js"></script>
<script src="//jsbin-files.ably.io/js/jquery-1.8.3.min.js"></script>
<script src="//cdn.ably.io/lib/vcdiff-decoder.min-1.js"></script>
<h1>Ably Deltas Example</h1>

<p>In this example, we demonstrate the simplest way to subscribe to deltas on a channel. See <a href="https://www.ably.io/documentation/realtime/channels/channel-parameters/deltas">our deltas documentation</a> for more details.

<div class="row">
<input id="publish" type="submit" value="Publish a message">
</div>

<ul class="row" id="channel-status"></ul>
[--- /HTML ---]

[--- CSS ---]
body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

h1 {
background: url('//jsbin-files.ably.io/images/logo.png') no-repeat;
font-size: 18px;
font-weight: bold;
padding: 8px 0 0 120px;
height: 42px;
}

.row {
margin-bottom: 1em;
}
[--- /CSS ---]
2 changes: 1 addition & 1 deletion content/code/realtime/rewind.code
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,7 @@ function show(status, color, box) {
<body>
<h1><a href="https://www.ably.io" target="_blank"><img src="/images/favicon.png">Ably Rewind demo</a></h1>

<p>In this example, we demonstrate the simplest way to subscribe to a message using rewind in libraries older than v1.2. See <a href="https://www.ably.io/documentation/realtime/channel-params#rewind">our Rewind documentation</a> for more details.
<p>In this example, we demonstrate the simplest way to subscribe to a message using rewind in libraries older than v1.2. See <a href="https://www.ably.io/documentation/realtime/channels/channel-parameters/overview/rewind">our Rewind documentation</a> for more details.

<div class="row">
<input id="publish" type="submit" value="Publish a message">
Expand Down
2 changes: 1 addition & 1 deletion content/concepts/long-polling.textile
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,7 +112,7 @@ From the readme, "Pollymer is a general-purpose AJAX library that provides conve

Optional extras include support for JSON-P and logging.

```[js]
```[javascript]
var req = new Pollymer.Request();
req.on('finished', function(code, result, headers) { ... });
req.on('error', function(reason) { ... });
Expand Down
8 changes: 4 additions & 4 deletions content/mqtt/index.textile
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,8 +35,8 @@ For example, in the NodeJS "MQTT package":https://www.npmjs.com/package/mqtt, yo
bc[nodejs]. {
var options = {
keepalive: 30,
username: 'FIRST_HALF_OF_API_KEY',
password: 'SECOND_HALF_OF_API_KEY',
username: '{{API_KEY_NAME}}', /* API key's name */
password: '{{API_KEY_SECRET}}', /* API key's secret */
port: 8883
};
var client = mqtt.connect('mqtts:mqtt.ably.io', options);
Expand All@@ -54,8 +54,8 @@ bc[nodejs]. {
var decoder = new encoding.TextDecoder();
var options = {
keepalive: 30,
username: 'FIRST_HALF_OF_API_KEY',
password: 'SECOND_HALF_OF_API_KEY',
username: '{{API_KEY_NAME}}', /* API key's name */
password: '{{API_KEY_SECRET}}', /* API key's secret */
port: 8883
};
var client = mqtt.connect('mqtts:mqtt.ably.io', options);
Expand Down
5 changes: 4 additions & 1 deletion content/partials/types/_channel_options.textile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
Currently the supported channel options are only used for "configuring encryption":/realtime/encryption.
Channel options are used for setting "channel parameters":/realtime/channels/channel-parameters/overview and "configuring encryption":/realtime/encryption.

blang[jsall].
@ChannelOptions@, a plain Javascript object, may optionally be specified when instancing a "@Channel@":/realtime/channels, and this may be used to specify channel-specific options. The following attributes can be defined on the object:
Expand All@@ -20,6 +20,9 @@ h4.
java: Members
ruby: Attributes

blang[jsall,java,swift,objc,dotnet].
- <span lang="default">params</span><span lang="csharp">Params</span> := Optional "parameters":/realtime/channels/channel-parameters/overview which specify behaviour of the channel.<br>__Type: <span lang='java'>@Map<String, String>@</span><span lang='jsall,objc,dotnet,swift'>@JSON Object@</span>__

- <span lang="default">cipher</span><span lang="ruby">:cipher</span><span lang="csharp,go">CipherParams</span> := Requests encryption for this channel when not null, and specifies encryption-related parameters (such as algorithm, chaining mode, key length and key). See "an example":/realtime/encryption#getting-started<br>__Type: "@CipherParams@":/realtime/encryption#cipher-params<span lang="jsall,java,ruby,php"> or <span lang="jsall">an options object</span><span lang="java">a @Param[]@ list</span><span lang="ruby">an options hash</span><span lang="php">an Associative Array</span> containing at a minimum a @key@</span>__

blang[java].
Expand Down
2 changes: 1 addition & 1 deletion content/realtime/channel-metadata.textile
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
---
title: Channel Metadata API
section: realtime
index: 31
index: 3
jump_to:
Help with:
- Overview#overview
Expand Down
Loading