|
|
@@ -70,6 +70,7 @@ function JitsiTrack(conference, stream, track, streamInactiveHandler, trackMedia
|
|
70
|
70
|
this.type = trackMediaType;
|
|
71
|
71
|
this.track = track;
|
|
72
|
72
|
this.videoType = videoType;
|
|
|
73
|
+ this.handlers = {};
|
|
73
|
74
|
|
|
74
|
75
|
/**
|
|
75
|
76
|
* Indicates whether this JitsiTrack has been disposed. If true, this
|
|
|
@@ -79,13 +80,38 @@ function JitsiTrack(conference, stream, track, streamInactiveHandler, trackMedia
|
|
79
|
80
|
* @type {boolean}
|
|
80
|
81
|
*/
|
|
81
|
82
|
this.disposed = false;
|
|
|
83
|
+ this._setHandler("inactive", streamInactiveHandler);
|
|
|
84
|
+}
|
|
82
|
85
|
|
|
83
|
|
- if(stream) {
|
|
84
|
|
- if (RTCBrowserType.isFirefox()) {
|
|
85
|
|
- implementOnEndedHandling(this);
|
|
|
86
|
+/**
|
|
|
87
|
+ * Sets handler to the WebRTC MediaStream or MediaStreamTrack object depending
|
|
|
88
|
+ * on the passed type.
|
|
|
89
|
+ * @param {string} type the type of the handler that is going to be set
|
|
|
90
|
+ * @param {Function} handler the handler.
|
|
|
91
|
+ */
|
|
|
92
|
+JitsiTrack.prototype._setHandler = function (type, handler) {
|
|
|
93
|
+ if(this.stream) {
|
|
|
94
|
+ if(type === "inactive") {
|
|
|
95
|
+ if (RTCBrowserType.isFirefox()) {
|
|
|
96
|
+ implementOnEndedHandling(this);
|
|
|
97
|
+ }
|
|
|
98
|
+ addMediaStreamInactiveHandler(this.stream, handler);
|
|
86
|
99
|
}
|
|
87
|
|
- addMediaStreamInactiveHandler(stream, streamInactiveHandler);
|
|
88
|
100
|
}
|
|
|
101
|
+ this.handlers[type] = handler;
|
|
|
102
|
+}
|
|
|
103
|
+
|
|
|
104
|
+/**
|
|
|
105
|
+ * Sets the stream property of JitsiTrack object and sets all stored handlers
|
|
|
106
|
+ * to it.
|
|
|
107
|
+ * @param {MediaStream} stream the new stream.
|
|
|
108
|
+ */
|
|
|
109
|
+JitsiTrack.prototype._setStream = function (stream) {
|
|
|
110
|
+ this.stream = stream;
|
|
|
111
|
+ Object.keys(this.handlers).forEach(function (type) {
|
|
|
112
|
+ typeof(this.handlers[type]) === "function" &&
|
|
|
113
|
+ this._setHandler(type, this.handlers[type]);
|
|
|
114
|
+ }, this);
|
|
89
|
115
|
}
|
|
90
|
116
|
|
|
91
|
117
|
/**
|