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

Show room feature in Exchange Files Example #1949

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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