Skip to content

Commit

Permalink
toggle connection by clicking on y-connect-btn
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter authored and Peter committed May 19, 2023
1 parent 305e494 commit b785433
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/code-mirror/frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ const state = EditorState.create({
})

const view = new EditorView({ state, parent: document.querySelector('#editor') })

// toggle connection by clicking on connect-btn
const toggleButton = document.getElementById('y-connect-btn')
let connected = true

toggleButton.addEventListener('click', () => {
if (connected) {
provider.disconnect()
connected = false
toggleButton.innerText = 'Reconnect'
} else {
provider.connect()
connected = true
toggleButton.innerText = 'Disconnect'
}
})
16 changes: 16 additions & 0 deletions examples/webrtc-signaling-server/frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ const state = EditorState.create({
})

const view = new EditorView({ state, parent: document.querySelector('#editor') })

// toggle connection by clicking on connect-btn
const toggleButton = document.getElementById('y-connect-btn')
let connected = true

toggleButton.addEventListener('click', () => {
if (connected) {
provider.disconnect()
connected = false
toggleButton.innerText = 'Reconnect'
} else {
provider.connect()
connected = true
toggleButton.innerText = 'Disconnect'
}
})

0 comments on commit b785433

Please sign in to comment.