3 exports.__esModule = true;
10 * Add RTMP properties to the {@link Flash} Tech.
12 * @param {Flash} Flash
13 * The flash tech class.
15 * @mixin FlashRtmpDecorator
17 function FlashRtmpDecorator(Flash) {
18 Flash.streamingFormats = {
24 * Join connection and stream with an ampersand.
26 * @param {string} connection
27 * The connection string.
29 * @param {string} stream
32 Flash.streamFromParts = function (connection, stream) {
33 return connection + '&' + stream;
37 * The flash parts object that contains connection and stream info.
39 * @typedef {Object} Flash~PartsObject
41 * @property {string} connection
42 * The connection string of a source, defaults to an empty string.
44 * @property {string} stream
45 * The stream string of the source, defaults to an empty string.
49 * Convert a source url into a stream and connection parts.
54 * @return {Flash~PartsObject}
55 * The parts object that contains a connection and a stream
57 Flash.streamToParts = function (src) {
67 // Look for the normal URL separator we expect, '&'.
68 // If found, we split the URL into two pieces around the
70 var connEnd = src.search(/&(?!\w+=)/);
71 var streamBegin = void 0;
74 streamBegin = connEnd + 1;
76 // If there's not a '&', we use the last '/' as the delimiter.
77 connEnd = streamBegin = src.lastIndexOf('/') + 1;
79 // really, there's not a '/'?
80 connEnd = streamBegin = src.length;
84 parts.connection = src.substring(0, connEnd);
85 parts.stream = src.substring(streamBegin, src.length);
91 * Check if the source type is a streaming type.
93 * @param {string} srcType
94 * The mime type to check.
97 * - True if the source type is a streaming type.
98 * - False if the source type is not a streaming type.
100 Flash.isStreamingType = function (srcType) {
101 return srcType in Flash.streamingFormats;
104 // RTMP has four variations, any string starting
105 // with one of these protocols should be valid
108 * Regular expression used to check if the source is an rtmp source.
110 * @property {RegExp} Flash.RTMP_RE
112 Flash.RTMP_RE = /^rtmp[set]?:\/\//i;
115 * Check if the source itself is a streaming type.
117 * @param {string} src
118 * The url to the source.
121 * - True if the source url indicates that the source is streaming.
122 * - False if the shource url indicates that the source url is not streaming.
124 Flash.isStreamingSrc = function (src) {
125 return Flash.RTMP_RE.test(src);
129 * A source handler for RTMP urls
132 Flash.rtmpSourceHandler = {};
135 * Check if Flash can play the given mime type.
137 * @param {string} type
138 * The mime type to check
141 * 'maybe', or '' (empty string)
143 Flash.rtmpSourceHandler.canPlayType = function (type) {
144 if (Flash.isStreamingType(type)) {
152 * Check if Flash can handle the source natively
154 * @param {Object} source
157 * @param {Object} [options]
158 * The options passed to the tech
161 * 'maybe', or '' (empty string)
163 Flash.rtmpSourceHandler.canHandleSource = function (source, options) {
164 var can = Flash.rtmpSourceHandler.canPlayType(source.type);
170 if (Flash.isStreamingSrc(source.src)) {
178 * Pass the source to the flash object.
180 * @param {Object} source
183 * @param {Flash} tech
184 * The instance of the Flash tech
186 * @param {Object} [options]
187 * The options to pass to the source
189 Flash.rtmpSourceHandler.handleSource = function (source, tech, options) {
190 var srcParts = Flash.streamToParts(source.src);
192 tech.setRtmpConnection(srcParts.connection);
193 tech.setRtmpStream(srcParts.stream);
196 // Register the native source handler
197 Flash.registerSourceHandler(Flash.rtmpSourceHandler);
202 exports['default'] = FlashRtmpDecorator;