-
Notifications
You must be signed in to change notification settings - Fork 45
Inband occupancy #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tbedford
wants to merge
7
commits into
main
Choose a base branch
from
inband-occupancy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Inband occupancy #93
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d6af7f9
Step 3 - Basic HTML page to display inband occupancy results.
tbedford 1758c24
Step 4 - Instantiating the Ably realtime library
tbedford 8685d4d
Step 5 - Add button callbacks
tbedford c16e98c
Complete code
tbedford 797d4fa
Step 4 - Instantiating the Ably realtime library
tbedford 6463c38
Step 5 - Add button callbacks
tbedford 5d4ac11
Complete Code
tbedford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <html> | ||
|
|
||
| <head> | ||
| <title>** Inband Channel Occupancy Events **</title> | ||
| <script src="https://cdn.ably.io/lib/ably.min-1.js" crossorigin="anonymous"></script> | ||
| </head> | ||
|
|
||
| <body style="padding: 60px; font-family:Arial, Helvetica, sans-serif; text-align: center;"> | ||
| Ably Inband Channel Occupancy Events - Demo | ||
| <br/> | ||
| <br/> | ||
| <div style="text-align: center; padding: 10px;"> | ||
| <button style="padding: 5px; width: 150px" id="add-publisher-instance" onclick="addPublisherInstance()">Add publisher instance</button> | ||
| <button style="padding: 5px; width: 150px" id="add-subscriber-instance" onclick="addSubscriberInstance()">Add subscriber instance</button> | ||
| </div> | ||
| <div style="text-align: center; padding: 10px;"> | ||
| <button style="padding: 5px; width: 150px" id="add-publisher-instance-presence" onclick="addPublisherInstanceWithPresence()">Add publisher instance and enter presence</button> | ||
| <button style="padding: 5px; width: 150px" id="add-subscriber-instance-presence" onclick="addSubscriberInstanceWithPresence()">Add subscriber instance and enter presence</button> | ||
| </div> | ||
| <div> | ||
| <br> | ||
| <textarea id="result" rows="30" style="width: 100%; margin-top: 10px; font-family: courier, courier new; background-color: #333; color: orange; overflow-y: scroll;" | ||
| disabled> | ||
| </textarea> | ||
| </div> | ||
| <script src="main.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| let apiKey = 'YOUR_API_KEY'; | ||
| let ably = new Ably.Realtime({ | ||
| key: apiKey, | ||
| }); | ||
|
|
||
| let regularChannelName = "channel-" + Math.random().toString(36).substr(2, 16); | ||
tbedford marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let channelOpts = { params: { occupancy: "metrics" } }; | ||
| let channel = ably.channels.get(regularChannelName, channelOpts); | ||
| let resultArea = document.getElementById("result"); | ||
| resultArea.scrollTop = resultArea.scrollHeight; | ||
|
|
||
| channel.subscribe("[meta]occupancy", (msg) => { | ||
| let msgJSONobj = JSON.parse(JSON.stringify(msg)); | ||
tbedford marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| console.log("MSG: " + msg); | ||
| //extract occupancy data from the message returned in the callback | ||
| let occupancyMetrics = msgJSONobj.data.metrics; | ||
| if (occupancyMetrics && msgJSONobj.name.includes("[meta]")) { | ||
| resultArea.value += | ||
tbedford marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "\n\n[METADATA - " + | ||
| new Date().toLocaleTimeString() + | ||
| ' ]: Occupancy on channel "' + | ||
| regularChannelName + | ||
| '" has been updated. New data is as follows:\n'; | ||
| resultArea.value += "Connections: " + occupancyMetrics.connections + " \n"; | ||
| resultArea.value += "Publishers: " + occupancyMetrics.publishers + " \n"; | ||
| resultArea.value += "Subscribers: " + occupancyMetrics.subscribers + " \n"; | ||
| resultArea.value += | ||
| "Presence Connections: " + occupancyMetrics.presenceConnections + " \n"; | ||
| resultArea.value += | ||
| "Presence Members: " + occupancyMetrics.presenceMembers + " \n"; | ||
| resultArea.value += | ||
| "Presence Subscribers: " + occupancyMetrics.presenceSubscribers + " \n"; | ||
| resultArea.scrollTop = resultArea.scrollHeight; | ||
| } | ||
| }); | ||
|
|
||
| function addPublisherInstance() { | ||
| console.log("API KEY: " + apiKey); | ||
| resultArea.value += | ||
| "\n[LOCAL LOG - " + | ||
| new Date().toLocaleTimeString() + | ||
| " ]: Adding new publisher instance\n"; | ||
| let ably = new Ably.Realtime({ | ||
| key: apiKey, | ||
| }); | ||
| let regularChannel = ably.channels.get(regularChannelName); | ||
| console.log("adding publisher instance"); | ||
| regularChannel.publish("test-data", { | ||
| data: "Dummy Data", | ||
| time: Date.now(), | ||
| }); | ||
| } | ||
|
|
||
| function addSubscriberInstance() { | ||
| resultArea.value += | ||
| "\n[LOCAL LOG - " + | ||
| new Date().toLocaleTimeString() + | ||
| " ]: Adding new subscriber instance\n"; | ||
| let ably = new Ably.Realtime({ | ||
| key: apiKey, | ||
| }); | ||
| let regularChannel = ably.channels.get(regularChannelName); | ||
| console.log("adding subscriber instance"); | ||
| regularChannel.subscribe("test-data", (data) => { | ||
| //do whatever | ||
| console.log("Subscription working"); | ||
| }); | ||
| } | ||
|
|
||
| function addPublisherInstanceWithPresence() { | ||
| resultArea.value += | ||
| "\n[LOCAL LOG - " + | ||
tbedford marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new Date().toLocaleTimeString() + | ||
| " ]: Adding new publisher instance\n"; | ||
| let myId = "clientId-" + Math.random().toString(36).substr(2, 16); | ||
| let ably = new Ably.Realtime({ | ||
| key: apiKey, | ||
| clientId: myId, | ||
| }); | ||
| let regularChannel = ably.channels.get(regularChannelName); | ||
| console.log("adding publisher instance"); | ||
| regularChannel.publish("test-data", { | ||
| data: "Dummy Data", | ||
| time: Date.now(), | ||
| }); | ||
| regularChannel.presence.enter(); | ||
| } | ||
|
|
||
| function addSubscriberInstanceWithPresence() { | ||
| resultArea.value += | ||
| "\n[LOCAL LOG - " + | ||
| new Date().toLocaleTimeString() + | ||
| " ]: Adding new subscriber instance\n"; | ||
| let myId = "clientId-" + Math.random().toString(36).substr(2, 16); | ||
| let ably = new Ably.Realtime({ | ||
| key: apiKey, | ||
| clientId: myId, | ||
| }); | ||
| let regularChannel = ably.channels.get(regularChannelName); | ||
| console.log("adding subscriber instance"); | ||
| regularChannel.subscribe("test-data", (data) => { | ||
| //do whatever | ||
| console.log("Subscription working"); | ||
| }); | ||
| regularChannel.presence.enter(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.