Skip to content

Commit 64310c3

Browse files
committed
fix(Cast): Allow serialize nested events (#9283)
1 parent d4512ca commit 64310c3

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/cast/cast_utils.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ shaka.cast.CastUtils = class {
4545
} else if (eventValue instanceof Event ||
4646
eventValue instanceof shaka.util.FakeEvent) {
4747
simpleEvent[eventKey] =
48-
shaka.cast.CastUtils.serialize(eventValue);
48+
shaka.cast.CastUtils.unpackEvent_(eventValue);
4949
} else if (isFakeEvent && Array.isArray(eventValue)) {
5050
simpleEvent[eventKey] = eventValue;
5151
}
@@ -124,6 +124,9 @@ shaka.cast.CastUtils = class {
124124
} else if (value && typeof value == 'object' &&
125125
value['__type__'] == 'Error') {
126126
return shaka.cast.CastUtils.makeError_(value);
127+
} else if (value && typeof value == 'object' &&
128+
value['__type__'] == 'Event') {
129+
return shaka.cast.CastUtils.makeEvent_(value);
127130
}
128131
return value;
129132
});
@@ -199,6 +202,30 @@ shaka.cast.CastUtils = class {
199202
}
200203

201204

205+
/**
206+
* @param {!Object} value
207+
* @return {!Object}
208+
* @private
209+
*/
210+
static unpackEvent_(value) {
211+
return {
212+
'__type__': 'Event', // a signal to deserialize
213+
'event': shaka.cast.CastUtils.serialize(value),
214+
};
215+
}
216+
217+
218+
/**
219+
* Creates a Event object from data sent by the cast receiver.
220+
* @param {?} obj
221+
* @return {!Object}
222+
* @private
223+
*/
224+
static makeEvent_(obj) {
225+
return shaka.cast.CastUtils.deserialize(obj['event']);
226+
}
227+
228+
202229
/**
203230
* @param {!Error} error
204231
* @return {!Object}

0 commit comments

Comments
 (0)