Skip to content

Commit

Permalink
don't expose ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
Septias authored and Simon-Laux committed Jun 4, 2024
1 parent 11ab616 commit d823026
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions static/webxdc-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* @type {RT}
*/
class RealtimeListener {
constructor(ipc) {
constructor(sendRealtime, leaveRealtime) {
this.listener = null
this.trashed = false
this.ipc = ipc
this.sendRealtime = sendRealtime
this.leaveRealtime = leaveRealtime
}

is_trashed() {
Expand All @@ -33,12 +34,12 @@ class RealtimeListener {
if (this.trashed) {
throw new Error('realtime listener is trashed and can no longer be used')
}
this.ipc.invoke('webxdc.sendRealtimeData', Array.from(data))
this.sendRealtime(Array.from(data))
}

leave() {
this.trashed = true
this.ipc.invoke('webxdc.leaveRealtimeChannel')
this.leaveRealtime()
}
}

Expand Down Expand Up @@ -118,15 +119,17 @@ class RealtimeListener {
throw new Error('realtime listener already exists')
}

realtimeListener = new RealtimeListener(ipcRenderer)
realtimeListener = new RealtimeListener(
arr => ipcRenderer.invoke('webxdc.sendRealtimeData', arr),
() => ipcRenderer.invoke('webxdc.leaveRealtimeChannel')
)
ipcRenderer.invoke('webxdc.sendRealtimeAdvertisement')
realtimeListener.setListener =
realtimeListener.setListener.bind(realtimeListener)
realtimeListener.send = realtimeListener.send.bind(realtimeListener)
realtimeListener.leave = realtimeListener.leave.bind(realtimeListener)
realtimeListener.is_trashed =
realtimeListener.is_trashed.bind(realtimeListener)

return realtimeListener
},
getAllUpdates: () => {
Expand Down

0 comments on commit d823026

Please sign in to comment.