Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
docs: add rooms feature to examples/exchange-files (#1949)
Browse files Browse the repository at this point in the history
As mentioned in issue #1632, currently, it is impossible to guess that there is the room feature on the exchange files example.

So, I added a textbox and a button which can be used for subscribing to a different room. Here's a small preview of the feature: 

![ipfs rooms demo (2)](https://user-images.githubusercontent.com/31539366/54750766-d7742400-4bfe-11e9-825c-7b0ff6007c8a.gif)

closes #1632 

License: MIT
Signed-off-by: Nitin Patel <nitinpatel278@gmail.com>
  • Loading branch information
niinpatel authored and Alan Shaw committed Apr 4, 2019
1 parent c51b86e commit 08b6740
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
29 changes: 27 additions & 2 deletions examples/exchange-files-in-browser/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ const $allDisabledButtons = document.querySelectorAll('button:disabled')
const $allDisabledInputs = document.querySelectorAll('input:disabled')
const $allDisabledElements = document.querySelectorAll('.disabled')

const FILES = []
const workspace = location.hash
// Workspace inputs
const $workspaceInput = document.querySelector('#workspace-input')
const $workspaceBtn = document.querySelector('#workspace-btn')

let FILES = []
let workspace = location.hash

let fileSize = 0

Expand Down Expand Up @@ -65,6 +69,8 @@ function start () {
.catch((error) => onError(error))

subscribeToWorkpsace()

window.addEventListener('hashchange', workspaceUpdated)
})
}
}
Expand All @@ -87,9 +93,25 @@ const messageHandler = (message) => {

const subscribeToWorkpsace = () => {
node.pubsub.subscribe(workspace, messageHandler)
.then(() => {
const msg = `Subscribed to workspace ${workspace}`
$logs.innerHTML = msg
})
.catch(() => onError('An error occurred when subscribing to the workspace.'))
}

// unsubscribe from old workspace and re-subscribe to new one
const workspaceUpdated = () => {
node.pubsub.unsubscribe(workspace).then(() => {
// clear files from old workspace
FILES = []
$fileHistory.innerHTML = ''

workspace = location.hash
subscribeToWorkpsace()
})
}

const publishHash = (hash) => {
const data = Buffer.from(hash)

Expand Down Expand Up @@ -327,6 +349,9 @@ const startApplication = () => {
$dragContainer.addEventListener('dragleave', onDragLeave)
$fetchButton.addEventListener('click', getFile)
$connectButton.addEventListener('click', connectToPeer)
$workspaceBtn.addEventListener('click', () => {
window.location.hash = $workspaceInput.value
})

start()
}
Expand Down
8 changes: 8 additions & 0 deletions examples/exchange-files-in-browser/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ <h3>Logs</h3>
<pre id="logs" class="success">Initializing node...</pre>
</div>
</div>

<div>
<h3>Workspace</h3>
<div class="input-button">
<input id="workspace-input" type="text" placeholder="Enter workspace name" disabled />
<button id="workspace-btn" disabled>Join</button>
</div>
</div>
</div>


Expand Down

0 comments on commit 08b6740

Please sign in to comment.