diff options
-rw-r--r-- | src/utils/webrtc/models/LocalCallParticipantModel.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/utils/webrtc/models/LocalCallParticipantModel.js b/src/utils/webrtc/models/LocalCallParticipantModel.js index 171821a85..e2e8591fe 100644 --- a/src/utils/webrtc/models/LocalCallParticipantModel.js +++ b/src/utils/webrtc/models/LocalCallParticipantModel.js @@ -26,6 +26,8 @@ export default function LocalCallParticipantModel() { guestName: null, } + this._handlers = [] + } LocalCallParticipantModel.prototype = { @@ -34,6 +36,40 @@ LocalCallParticipantModel.prototype = { this.attributes[key] = value }, + on: function(event, handler) { + if (!this._handlers.hasOwnProperty(event)) { + this._handlers[event] = [handler] + } else { + this._handlers[event].push(handler) + } + }, + + off: function(event, handler) { + const index = this._handlers[event].indexOf(handler) + if (index !== -1) { + this._handlers[event].splice(index, 1) + } + }, + + _trigger: function(event, args) { + let handlers = this._handlers[event] + if (!handlers) { + return + } + + if (!args) { + args = [] + } + + args.unshift(this) + + handlers = handlers.slice(0) + for (let i = 0; i < handlers.length; i++) { + const handler = handlers[i] + handler.apply(handler, args) + } + }, + setWebRtc: function(webRtc) { this._webRtc = webRtc |