Clean up the Chrome API implementation code

This commit is contained in:
Cheng Zhao 2016-05-28 17:51:49 +09:00
parent 31628abadc
commit d55b96fdf5
3 changed files with 54 additions and 50 deletions

View file

@ -44,6 +44,7 @@ class Port {
constructor (webContentsId, portId, extensionId, name) {
this.webContentsId = webContentsId
this.portId = portId
this.disconnected = false
this.name = name
this.onDisconnect = new Event()
@ -60,6 +61,8 @@ class Port {
}
disconnect () {
if (this.disconnected) return
ipcRenderer.send('CHROME_PORT_DISCONNECT', this.webContentsId, this.portId)
this._onDisconnect()
}
@ -69,6 +72,7 @@ class Port {
}
_onDisconnect () {
this.disconnected = true
ipcRenderer.removeAllListeners(`CHROME_PORT_ONMESSAGE_${this.portId}`)
this.onDisconnect.emit()
}