Skip to content

Commit

Permalink
Merge pull request #14 from peterkogo/example-feature-disconnect
Browse files Browse the repository at this point in the history
Toggle connection by clicking on y-connect-btn
  • Loading branch information
Horusiath authored Dec 7, 2024
2 parents 587c00e + b785433 commit a350be3
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 a350be3

Please sign in to comment.