Commit 0a2d60b9 by libai

测试

parent 026a1274
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license * @license Licensed under MIT license
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
* @version v4.2.5+7f2b526d * @version 4.1.0
*/ */
(function (global, factory) { (function (global, factory) {
...@@ -15,30 +15,27 @@ ...@@ -15,30 +15,27 @@
}(this, (function () { 'use strict'; }(this, (function () { 'use strict';
function objectOrFunction(x) { function objectOrFunction(x) {
var type = typeof x; return typeof x === 'function' || typeof x === 'object' && x !== null;
return x !== null && (type === 'object' || type === 'function');
} }
function isFunction(x) { function isFunction(x) {
return typeof x === 'function'; return typeof x === 'function';
} }
var _isArray = undefined;
if (!Array.isArray) {
var _isArray = void 0;
if (Array.isArray) {
_isArray = Array.isArray;
} else {
_isArray = function (x) { _isArray = function (x) {
return Object.prototype.toString.call(x) === '[object Array]'; return Object.prototype.toString.call(x) === '[object Array]';
}; };
} else {
_isArray = Array.isArray;
} }
var isArray = _isArray; var isArray = _isArray;
var len = 0; var len = 0;
var vertxNext = void 0; var vertxNext = undefined;
var customSchedulerFn = void 0; var customSchedulerFn = undefined;
var asap = function asap(callback, arg) { var asap = function asap(callback, arg) {
queue[len] = callback; queue[len] = callback;
...@@ -67,7 +64,7 @@ ...@@ -67,7 +64,7 @@
var browserWindow = typeof window !== 'undefined' ? window : undefined; var browserWindow = typeof window !== 'undefined' ? window : undefined;
var browserGlobal = browserWindow || {}; var browserGlobal = browserWindow || {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
// test for web worker but not in IE10 // test for web worker but not in IE10
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
...@@ -138,7 +135,8 @@ ...@@ -138,7 +135,8 @@
function attemptVertx() { function attemptVertx() {
try { try {
var vertx = Function('return this')().require('vertx'); var r = _dereq_;
var vertx = r('vertx');
vertxNext = vertx.runOnLoop || vertx.runOnContext; vertxNext = vertx.runOnLoop || vertx.runOnContext;
return useVertxTimer(); return useVertxTimer();
} catch (e) { } catch (e) {
...@@ -146,7 +144,7 @@ ...@@ -146,7 +144,7 @@
} }
} }
var scheduleFlush = void 0; var scheduleFlush = undefined;
// Decide what async method to use to triggering processing of queued callbacks: // Decide what async method to use to triggering processing of queued callbacks:
if (isNode) { if (isNode) {
scheduleFlush = useNextTick(); scheduleFlush = useNextTick();
...@@ -161,6 +159,8 @@ ...@@ -161,6 +159,8 @@
} }
function then(onFulfillment, onRejection) { function then(onFulfillment, onRejection) {
var _arguments = arguments;
var parent = this; var parent = this;
var child = new this.constructor(noop); var child = new this.constructor(noop);
...@@ -171,12 +171,13 @@ ...@@ -171,12 +171,13 @@
var _state = parent._state; var _state = parent._state;
if (_state) { if (_state) {
var callback = arguments[_state - 1]; (function () {
asap(function () { var callback = _arguments[_state - 1];
return invokeCallback(_state, child, callback, parent._result); asap(function () {
}); return invokeCallback(_state, child, callback, parent._result);
});
})();
} else { } else {
subscribe(parent, child, onFulfillment, onRejection); subscribe(parent, child, onFulfillment, onRejection);
} }
...@@ -215,7 +216,7 @@ ...@@ -215,7 +216,7 @@
@return {Promise} a promise that will become fulfilled with the given @return {Promise} a promise that will become fulfilled with the given
`value` `value`
*/ */
function resolve$1(object) { function resolve(object) {
/*jshint validthis:true */ /*jshint validthis:true */
var Constructor = this; var Constructor = this;
...@@ -224,11 +225,11 @@ ...@@ -224,11 +225,11 @@
} }
var promise = new Constructor(noop); var promise = new Constructor(noop);
resolve(promise, object); _resolve(promise, object);
return promise; return promise;
} }
var PROMISE_ID = Math.random().toString(36).substring(2); var PROMISE_ID = Math.random().toString(36).substring(16);
function noop() {} function noop() {}
...@@ -236,7 +237,7 @@ ...@@ -236,7 +237,7 @@
var FULFILLED = 1; var FULFILLED = 1;
var REJECTED = 2; var REJECTED = 2;
var TRY_CATCH_ERROR = { error: null }; var GET_THEN_ERROR = new ErrorObject();
function selfFulfillment() { function selfFulfillment() {
return new TypeError("You cannot resolve a promise with itself"); return new TypeError("You cannot resolve a promise with itself");
...@@ -250,29 +251,29 @@ ...@@ -250,29 +251,29 @@
try { try {
return promise.then; return promise.then;
} catch (error) { } catch (error) {
TRY_CATCH_ERROR.error = error; GET_THEN_ERROR.error = error;
return TRY_CATCH_ERROR; return GET_THEN_ERROR;
} }
} }
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
try { try {
then$$1.call(value, fulfillmentHandler, rejectionHandler); then.call(value, fulfillmentHandler, rejectionHandler);
} catch (e) { } catch (e) {
return e; return e;
} }
} }
function handleForeignThenable(promise, thenable, then$$1) { function handleForeignThenable(promise, thenable, then) {
asap(function (promise) { asap(function (promise) {
var sealed = false; var sealed = false;
var error = tryThen(then$$1, thenable, function (value) { var error = tryThen(then, thenable, function (value) {
if (sealed) { if (sealed) {
return; return;
} }
sealed = true; sealed = true;
if (thenable !== value) { if (thenable !== value) {
resolve(promise, value); _resolve(promise, value);
} else { } else {
fulfill(promise, value); fulfill(promise, value);
} }
...@@ -282,12 +283,12 @@ ...@@ -282,12 +283,12 @@
} }
sealed = true; sealed = true;
reject(promise, reason); _reject(promise, reason);
}, 'Settle: ' + (promise._label || ' unknown promise')); }, 'Settle: ' + (promise._label || ' unknown promise'));
if (!sealed && error) { if (!sealed && error) {
sealed = true; sealed = true;
reject(promise, error); _reject(promise, error);
} }
}, promise); }, promise);
} }
...@@ -296,36 +297,36 @@ ...@@ -296,36 +297,36 @@
if (thenable._state === FULFILLED) { if (thenable._state === FULFILLED) {
fulfill(promise, thenable._result); fulfill(promise, thenable._result);
} else if (thenable._state === REJECTED) { } else if (thenable._state === REJECTED) {
reject(promise, thenable._result); _reject(promise, thenable._result);
} else { } else {
subscribe(thenable, undefined, function (value) { subscribe(thenable, undefined, function (value) {
return resolve(promise, value); return _resolve(promise, value);
}, function (reason) { }, function (reason) {
return reject(promise, reason); return _reject(promise, reason);
}); });
} }
} }
function handleMaybeThenable(promise, maybeThenable, then$$1) { function handleMaybeThenable(promise, maybeThenable, then$$) {
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {
handleOwnThenable(promise, maybeThenable); handleOwnThenable(promise, maybeThenable);
} else { } else {
if (then$$1 === TRY_CATCH_ERROR) { if (then$$ === GET_THEN_ERROR) {
reject(promise, TRY_CATCH_ERROR.error); _reject(promise, GET_THEN_ERROR.error);
TRY_CATCH_ERROR.error = null; GET_THEN_ERROR.error = null;
} else if (then$$1 === undefined) { } else if (then$$ === undefined) {
fulfill(promise, maybeThenable); fulfill(promise, maybeThenable);
} else if (isFunction(then$$1)) { } else if (isFunction(then$$)) {
handleForeignThenable(promise, maybeThenable, then$$1); handleForeignThenable(promise, maybeThenable, then$$);
} else { } else {
fulfill(promise, maybeThenable); fulfill(promise, maybeThenable);
} }
} }
} }
function resolve(promise, value) { function _resolve(promise, value) {
if (promise === value) { if (promise === value) {
reject(promise, selfFulfillment()); _reject(promise, selfFulfillment());
} else if (objectOrFunction(value)) { } else if (objectOrFunction(value)) {
handleMaybeThenable(promise, value, getThen(value)); handleMaybeThenable(promise, value, getThen(value));
} else { } else {
...@@ -354,7 +355,7 @@ ...@@ -354,7 +355,7 @@
} }
} }
function reject(promise, reason) { function _reject(promise, reason) {
if (promise._state !== PENDING) { if (promise._state !== PENDING) {
return; return;
} }
...@@ -368,7 +369,6 @@ ...@@ -368,7 +369,6 @@
var _subscribers = parent._subscribers; var _subscribers = parent._subscribers;
var length = _subscribers.length; var length = _subscribers.length;
parent._onerror = null; parent._onerror = null;
_subscribers[length] = child; _subscribers[length] = child;
...@@ -388,8 +388,8 @@ ...@@ -388,8 +388,8 @@
return; return;
} }
var child = void 0, var child = undefined,
callback = void 0, callback = undefined,
detail = promise._result; detail = promise._result;
for (var i = 0; i < subscribers.length; i += 3) { for (var i = 0; i < subscribers.length; i += 3) {
...@@ -406,6 +406,12 @@ ...@@ -406,6 +406,12 @@
promise._subscribers.length = 0; promise._subscribers.length = 0;
} }
function ErrorObject() {
this.error = null;
}
var TRY_CATCH_ERROR = new ErrorObject();
function tryCatch(callback, detail) { function tryCatch(callback, detail) {
try { try {
return callback(detail); return callback(detail);
...@@ -417,10 +423,10 @@ ...@@ -417,10 +423,10 @@
function invokeCallback(settled, promise, callback, detail) { function invokeCallback(settled, promise, callback, detail) {
var hasCallback = isFunction(callback), var hasCallback = isFunction(callback),
value = void 0, value = undefined,
error = void 0, error = undefined,
succeeded = void 0, succeeded = undefined,
failed = void 0; failed = undefined;
if (hasCallback) { if (hasCallback) {
value = tryCatch(callback, detail); value = tryCatch(callback, detail);
...@@ -434,7 +440,7 @@ ...@@ -434,7 +440,7 @@
} }
if (promise === value) { if (promise === value) {
reject(promise, cannotReturnOwn()); _reject(promise, cannotReturnOwn());
return; return;
} }
} else { } else {
...@@ -445,25 +451,25 @@ ...@@ -445,25 +451,25 @@
if (promise._state !== PENDING) { if (promise._state !== PENDING) {
// noop // noop
} else if (hasCallback && succeeded) { } else if (hasCallback && succeeded) {
resolve(promise, value); _resolve(promise, value);
} else if (failed) { } else if (failed) {
reject(promise, error); _reject(promise, error);
} else if (settled === FULFILLED) { } else if (settled === FULFILLED) {
fulfill(promise, value); fulfill(promise, value);
} else if (settled === REJECTED) { } else if (settled === REJECTED) {
reject(promise, value); _reject(promise, value);
} }
} }
function initializePromise(promise, resolver) { function initializePromise(promise, resolver) {
try { try {
resolver(function resolvePromise(value) { resolver(function resolvePromise(value) {
resolve(promise, value); _resolve(promise, value);
}, function rejectPromise(reason) { }, function rejectPromise(reason) {
reject(promise, reason); _reject(promise, reason);
}); });
} catch (e) { } catch (e) {
reject(promise, e); _reject(promise, e);
} }
} }
...@@ -479,103 +485,101 @@ ...@@ -479,103 +485,101 @@
promise._subscribers = []; promise._subscribers = [];
} }
function validationError() { function Enumerator(Constructor, input) {
return new Error('Array Methods must be provided an Array'); this._instanceConstructor = Constructor;
} this.promise = new Constructor(noop);
var Enumerator = function () { if (!this.promise[PROMISE_ID]) {
function Enumerator(Constructor, input) { makePromise(this.promise);
this._instanceConstructor = Constructor; }
this.promise = new Constructor(noop);
if (!this.promise[PROMISE_ID]) {
makePromise(this.promise);
}
if (isArray(input)) { if (isArray(input)) {
this.length = input.length; this._input = input;
this._remaining = input.length; this.length = input.length;
this._remaining = input.length;
this._result = new Array(this.length); this._result = new Array(this.length);
if (this.length === 0) { if (this.length === 0) {
fulfill(this.promise, this._result);
} else {
this.length = this.length || 0;
this._enumerate();
if (this._remaining === 0) {
fulfill(this.promise, this._result); fulfill(this.promise, this._result);
} else {
this.length = this.length || 0;
this._enumerate(input);
if (this._remaining === 0) {
fulfill(this.promise, this._result);
}
} }
} else {
reject(this.promise, validationError());
} }
} else {
_reject(this.promise, validationError());
} }
}
Enumerator.prototype._enumerate = function _enumerate(input) { function validationError() {
for (var i = 0; this._state === PENDING && i < input.length; i++) { return new Error('Array Methods must be provided an Array');
this._eachEntry(input[i], i); };
}
}; Enumerator.prototype._enumerate = function () {
var length = this.length;
var _input = this._input;
Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { for (var i = 0; this._state === PENDING && i < length; i++) {
var c = this._instanceConstructor; this._eachEntry(_input[i], i);
var resolve$$1 = c.resolve; }
};
Enumerator.prototype._eachEntry = function (entry, i) {
var c = this._instanceConstructor;
var resolve$$ = c.resolve;
if (resolve$$1 === resolve$1) { if (resolve$$ === resolve) {
var _then = getThen(entry); var _then = getThen(entry);
if (_then === then && entry._state !== PENDING) { if (_then === then && entry._state !== PENDING) {
this._settledAt(entry._state, i, entry._result); this._settledAt(entry._state, i, entry._result);
} else if (typeof _then !== 'function') { } else if (typeof _then !== 'function') {
this._remaining--; this._remaining--;
this._result[i] = entry; this._result[i] = entry;
} else if (c === Promise$1) { } else if (c === Promise) {
var promise = new c(noop); var promise = new c(noop);
handleMaybeThenable(promise, entry, _then); handleMaybeThenable(promise, entry, _then);
this._willSettleAt(promise, i); this._willSettleAt(promise, i);
} else {
this._willSettleAt(new c(function (resolve$$1) {
return resolve$$1(entry);
}), i);
}
} else { } else {
this._willSettleAt(resolve$$1(entry), i); this._willSettleAt(new c(function (resolve$$) {
return resolve$$(entry);
}), i);
} }
}; } else {
this._willSettleAt(resolve$$(entry), i);
Enumerator.prototype._settledAt = function _settledAt(state, i, value) { }
var promise = this.promise; };
if (promise._state === PENDING) { Enumerator.prototype._settledAt = function (state, i, value) {
this._remaining--; var promise = this.promise;
if (state === REJECTED) { if (promise._state === PENDING) {
reject(promise, value); this._remaining--;
} else {
this._result[i] = value;
}
}
if (this._remaining === 0) { if (state === REJECTED) {
fulfill(promise, this._result); _reject(promise, value);
} else {
this._result[i] = value;
} }
}; }
Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { if (this._remaining === 0) {
var enumerator = this; fulfill(promise, this._result);
}
};
subscribe(promise, undefined, function (value) { Enumerator.prototype._willSettleAt = function (promise, i) {
return enumerator._settledAt(FULFILLED, i, value); var enumerator = this;
}, function (reason) {
return enumerator._settledAt(REJECTED, i, reason);
});
};
return Enumerator; subscribe(promise, undefined, function (value) {
}(); return enumerator._settledAt(FULFILLED, i, value);
}, function (reason) {
return enumerator._settledAt(REJECTED, i, reason);
});
};
/** /**
`Promise.all` accepts an array of promises, and returns a new promise which `Promise.all` accepts an array of promises, and returns a new promise which
...@@ -745,11 +749,11 @@ ...@@ -745,11 +749,11 @@
Useful for tooling. Useful for tooling.
@return {Promise} a promise rejected with the given `reason`. @return {Promise} a promise rejected with the given `reason`.
*/ */
function reject$1(reason) { function reject(reason) {
/*jshint validthis:true */ /*jshint validthis:true */
var Constructor = this; var Constructor = this;
var promise = new Constructor(noop); var promise = new Constructor(noop);
reject(promise, reason); _reject(promise, reason);
return promise; return promise;
} }
...@@ -860,330 +864,301 @@ ...@@ -860,330 +864,301 @@
``` ```
@class Promise @class Promise
@param {Function} resolver @param {function} resolver
Useful for tooling. Useful for tooling.
@constructor @constructor
*/ */
function Promise(resolver) {
this[PROMISE_ID] = nextId();
this._result = this._state = undefined;
this._subscribers = [];
if (noop !== resolver) {
typeof resolver !== 'function' && needsResolver();
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
}
}
var Promise$1 = function () { Promise.all = all;
function Promise(resolver) { Promise.race = race;
this[PROMISE_ID] = nextId(); Promise.resolve = resolve;
this._result = this._state = undefined; Promise.reject = reject;
this._subscribers = []; Promise._setScheduler = setScheduler;
Promise._setAsap = setAsap;
Promise._asap = asap;
if (noop !== resolver) { Promise.prototype = {
typeof resolver !== 'function' && needsResolver(); constructor: Promise,
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
}
}
/** /**
The primary way of interacting with a promise is through its `then` method, The primary way of interacting with a promise is through its `then` method,
which registers callbacks to receive either a promise's eventual value or the which registers callbacks to receive either a promise's eventual value or the
reason why the promise cannot be fulfilled. reason why the promise cannot be fulfilled.
```js
findUser().then(function(user){ ```js
// user is available findUser().then(function(user){
}, function(reason){ // user is available
// user is unavailable, and you are given the reason why }, function(reason){
}); // user is unavailable, and you are given the reason why
``` });
Chaining ```
--------
The return value of `then` is itself a promise. This second, 'downstream' Chaining
promise is resolved with the return value of the first promise's fulfillment --------
or rejection handler, or rejected if the handler throws an exception.
```js The return value of `then` is itself a promise. This second, 'downstream'
findUser().then(function (user) { promise is resolved with the return value of the first promise's fulfillment
return user.name; or rejection handler, or rejected if the handler throws an exception.
}, function (reason) {
return 'default name'; ```js
}).then(function (userName) { findUser().then(function (user) {
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it return user.name;
// will be `'default name'` }, function (reason) {
}); return 'default name';
findUser().then(function (user) { }).then(function (userName) {
throw new Error('Found user, but still unhappy'); // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
}, function (reason) { // will be `'default name'`
throw new Error('`findUser` rejected and we're unhappy'); });
}).then(function (value) {
// never reached findUser().then(function (user) {
}, function (reason) { throw new Error('Found user, but still unhappy');
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. }, function (reason) {
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. throw new Error('`findUser` rejected and we're unhappy');
}); }).then(function (value) {
``` // never reached
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. }, function (reason) {
```js // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
findUser().then(function (user) { // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
throw new PedagogicalException('Upstream error'); });
}).then(function (value) { ```
// never reached If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
}).then(function (value) {
// never reached ```js
}, function (reason) { findUser().then(function (user) {
// The `PedgagocialException` is propagated all the way down to here throw new PedagogicalException('Upstream error');
}); }).then(function (value) {
``` // never reached
Assimilation }).then(function (value) {
------------ // never reached
Sometimes the value you want to propagate to a downstream promise can only be }, function (reason) {
retrieved asynchronously. This can be achieved by returning a promise in the // The `PedgagocialException` is propagated all the way down to here
fulfillment or rejection handler. The downstream promise will then be pending });
until the returned promise is settled. This is called *assimilation*. ```
```js
findUser().then(function (user) { Assimilation
return findCommentsByAuthor(user); ------------
}).then(function (comments) {
// The user's comments are now available Sometimes the value you want to propagate to a downstream promise can only be
}); retrieved asynchronously. This can be achieved by returning a promise in the
``` fulfillment or rejection handler. The downstream promise will then be pending
If the assimliated promise rejects, then the downstream promise will also reject. until the returned promise is settled. This is called *assimilation*.
```js
findUser().then(function (user) { ```js
return findCommentsByAuthor(user); findUser().then(function (user) {
}).then(function (comments) { return findCommentsByAuthor(user);
// If `findCommentsByAuthor` fulfills, we'll have the value here }).then(function (comments) {
}, function (reason) { // The user's comments are now available
// If `findCommentsByAuthor` rejects, we'll have the reason here });
}); ```
```
Simple Example If the assimliated promise rejects, then the downstream promise will also reject.
--------------
Synchronous Example ```js
```javascript findUser().then(function (user) {
let result; return findCommentsByAuthor(user);
try { }).then(function (comments) {
result = findResult(); // If `findCommentsByAuthor` fulfills, we'll have the value here
// success }, function (reason) {
} catch(reason) { // If `findCommentsByAuthor` rejects, we'll have the reason here
// failure });
} ```
```
Errback Example Simple Example
```js --------------
findResult(function(result, err){
if (err) { Synchronous Example
// failure
} else { ```javascript
let result;
try {
result = findResult();
// success // success
} } catch(reason) {
});
```
Promise Example;
```javascript
findResult().then(function(result){
// success
}, function(reason){
// failure
});
```
Advanced Example
--------------
Synchronous Example
```javascript
let author, books;
try {
author = findAuthor();
books = findBooksByAuthor(author);
// success
} catch(reason) {
// failure
}
```
Errback Example
```js
function foundBooks(books) {
}
function failure(reason) {
}
findAuthor(function(author, err){
if (err) {
failure(err);
// failure // failure
} else {
try {
findBoooksByAuthor(author, function(books, err) {
if (err) {
failure(err);
} else {
try {
foundBooks(books);
} catch(reason) {
failure(reason);
}
}
});
} catch(error) {
failure(err);
}
// success
} }
}); ```
```
Promise Example;
```javascript
findAuthor().
then(findBooksByAuthor).
then(function(books){
// found books
}).catch(function(reason){
// something went wrong
});
```
@method then
@param {Function} onFulfilled
@param {Function} onRejected
Useful for tooling.
@return {Promise}
*/
/**
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
as the catch block of a try/catch statement.
```js
function findAuthor(){
throw new Error('couldn't find that author');
}
// synchronous
try {
findAuthor();
} catch(reason) {
// something went wrong
}
// async with promises
findAuthor().catch(function(reason){
// something went wrong
});
```
@method catch
@param {Function} onRejection
Useful for tooling.
@return {Promise}
*/
Promise.prototype.catch = function _catch(onRejection) {
return this.then(null, onRejection);
};
/**
`finally` will be invoked regardless of the promise's fate just as native
try/catch/finally behaves
Synchronous example: Errback Example
```js ```js
findAuthor() { findResult(function(result, err){
if (Math.random() > 0.5) { if (err) {
throw new Error(); // failure
} else {
// success
} }
return new Author(); });
} ```
Promise Example;
```javascript
findResult().then(function(result){
// success
}, function(reason){
// failure
});
```
Advanced Example
--------------
Synchronous Example
```javascript
let author, books;
try { try {
return findAuthor(); // succeed or fail author = findAuthor();
} catch(error) { books = findBooksByAuthor(author);
return findOtherAuther(); // success
} finally { } catch(reason) {
// always runs // failure
// doesn't affect the return value
} }
``` ```
Asynchronous example: Errback Example
```js ```js
findAuthor().catch(function(reason){
return findOtherAuther(); function foundBooks(books) {
}).finally(function(){
// author was either found, or not }
function failure(reason) {
}
findAuthor(function(author, err){
if (err) {
failure(err);
// failure
} else {
try {
findBoooksByAuthor(author, function(books, err) {
if (err) {
failure(err);
} else {
try {
foundBooks(books);
} catch(reason) {
failure(reason);
}
}
});
} catch(error) {
failure(err);
}
// success
}
}); });
``` ```
@method finally Promise Example;
@param {Function} callback
```javascript
findAuthor().
then(findBooksByAuthor).
then(function(books){
// found books
}).catch(function(reason){
// something went wrong
});
```
@method then
@param {Function} onFulfilled
@param {Function} onRejected
Useful for tooling.
@return {Promise} @return {Promise}
*/ */
then: then,
/**
Promise.prototype.finally = function _finally(callback) { `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
var promise = this; as the catch block of a try/catch statement.
var constructor = promise.constructor;
```js
if (isFunction(callback)) { function findAuthor(){
return promise.then(function (value) { throw new Error('couldn't find that author');
return constructor.resolve(callback()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(callback()).then(function () {
throw reason;
});
});
} }
return promise.then(callback, callback); // synchronous
};
return Promise;
}();
Promise$1.prototype.then = then;
Promise$1.all = all;
Promise$1.race = race;
Promise$1.resolve = resolve$1;
Promise$1.reject = reject$1;
Promise$1._setScheduler = setScheduler;
Promise$1._setAsap = setAsap;
Promise$1._asap = asap;
/*global self*/
function polyfill() {
var local = void 0;
if (typeof global !== 'undefined') {
local = global;
} else if (typeof self !== 'undefined') {
local = self;
} else {
try { try {
local = Function('return this')(); findAuthor();
} catch (e) { } catch(reason) {
throw new Error('polyfill failed because global object is unavailable in this environment'); // something went wrong
} }
// async with promises
findAuthor().catch(function(reason){
// something went wrong
});
```
@method catch
@param {Function} onRejection
Useful for tooling.
@return {Promise}
*/
'catch': function _catch(onRejection) {
return this.then(null, onRejection);
} }
};
var P = local.Promise; function polyfill() {
var local = undefined;
if (P) { if (typeof global !== 'undefined') {
var promiseToString = null; local = global;
try { } else if (typeof self !== 'undefined') {
promiseToString = Object.prototype.toString.call(P.resolve()); local = self;
} catch (e) { } else {
// silently ignored try {
local = Function('return this')();
} catch (e) {
throw new Error('polyfill failed because global object is unavailable in this environment');
}
} }
if (promiseToString === '[object Promise]' && !P.cast) { var P = local.Promise;
return;
if (P) {
var promiseToString = null;
try {
promiseToString = Object.prototype.toString.call(P.resolve());
} catch (e) {
// silently ignored
}
if (promiseToString === '[object Promise]' && !P.cast) {
return;
}
} }
}
local.Promise = Promise$1; local.Promise = Promise;
} }
// Strange compat.. // Strange compat..
Promise$1.polyfill = polyfill; Promise.polyfill = polyfill;
Promise$1.Promise = Promise$1; Promise.Promise = Promise;
return Promise$1; return Promise;
}))); })));
}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) }).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"_process":3}],2:[function(_dereq_,module,exports){ },{"_process":3}],2:[function(_dereq_,module,exports){
...@@ -1708,7 +1683,7 @@ ...@@ -1708,7 +1683,7 @@
wcache[key] = key; wcache[key] = key;
} }
sources[wkey] = [ sources[wkey] = [
'function(require,module,exports){' + fn + '(self); }', Function(['require','module','exports'], '(' + fn + ')(self)'),
wcache wcache
]; ];
} }
...@@ -1716,11 +1691,12 @@ ...@@ -1716,11 +1691,12 @@
var scache = {}; scache[wkey] = wkey; var scache = {}; scache[wkey] = wkey;
sources[skey] = [ sources[skey] = [
'function(require,module,exports){' + Function(['require'], (
// try to call default if defined to also support babel esmodule exports // try to call default if defined to also support babel esmodule
// exports
'var f = require(' + stringify(wkey) + ');' + 'var f = require(' + stringify(wkey) + ');' +
'(f.default ? f.default : f)(self);' + '(f.default ? f.default : f)(self);'
'}', )),
scache scache
]; ];
...@@ -1809,11 +1785,8 @@ ...@@ -1809,11 +1785,8 @@
seekParamEnd: 'bend', seekParamEnd: 'bend',
rangeLoadZeroStart: false, rangeLoadZeroStart: false,
customSeekHandler: undefined, customSeekHandler: undefined,
reuseRedirectedURL: false, reuseRedirectedURL: false
// referrerPolicy: leave as unspecified // referrerPolicy: leave as unspecified
headers: undefined,
customLoader: undefined
}; };
function createDefaultConfig() { function createDefaultConfig() {
...@@ -2477,12 +2450,7 @@ ...@@ -2477,12 +2450,7 @@
var sb = this._sourceBuffers[type]; var sb = this._sourceBuffers[type];
if (sb) { if (sb) {
if (ms.readyState !== 'closed') { if (ms.readyState !== 'closed') {
// ms edge can throw an error: Unexpected call to method or property access ms.removeSourceBuffer(sb);
try {
ms.removeSourceBuffer(sb);
} catch (error) {
_logger2.default.e(this.TAG, error.message);
}
sb.removeEventListener('error', this.e.onSourceBufferError); sb.removeEventListener('error', this.e.onSourceBufferError);
sb.removeEventListener('updateend', this.e.onSourceBufferUpdateEnd); sb.removeEventListener('updateend', this.e.onSourceBufferUpdateEnd);
} }
...@@ -3041,8 +3009,6 @@ ...@@ -3041,8 +3009,6 @@
ctl.on(_transmuxingEvents2.default.LOADING_COMPLETE, this._onLoadingComplete.bind(this)); ctl.on(_transmuxingEvents2.default.LOADING_COMPLETE, this._onLoadingComplete.bind(this));
ctl.on(_transmuxingEvents2.default.RECOVERED_EARLY_EOF, this._onRecoveredEarlyEof.bind(this)); ctl.on(_transmuxingEvents2.default.RECOVERED_EARLY_EOF, this._onRecoveredEarlyEof.bind(this));
ctl.on(_transmuxingEvents2.default.MEDIA_INFO, this._onMediaInfo.bind(this)); ctl.on(_transmuxingEvents2.default.MEDIA_INFO, this._onMediaInfo.bind(this));
ctl.on(_transmuxingEvents2.default.METADATA_ARRIVED, this._onMetaDataArrived.bind(this));
ctl.on(_transmuxingEvents2.default.SCRIPTDATA_ARRIVED, this._onScriptDataArrived.bind(this));
ctl.on(_transmuxingEvents2.default.STATISTICS_INFO, this._onStatisticsInfo.bind(this)); ctl.on(_transmuxingEvents2.default.STATISTICS_INFO, this._onStatisticsInfo.bind(this));
ctl.on(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, this._onRecommendSeekpoint.bind(this)); ctl.on(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, this._onRecommendSeekpoint.bind(this));
} }
...@@ -3172,57 +3138,39 @@ ...@@ -3172,57 +3138,39 @@
}); });
} }
}, { }, {
key: '_onMetaDataArrived',
value: function _onMetaDataArrived(metadata) {
var _this6 = this;
Promise.resolve().then(function () {
_this6._emitter.emit(_transmuxingEvents2.default.METADATA_ARRIVED, metadata);
});
}
}, {
key: '_onScriptDataArrived',
value: function _onScriptDataArrived(data) {
var _this7 = this;
Promise.resolve().then(function () {
_this7._emitter.emit(_transmuxingEvents2.default.SCRIPTDATA_ARRIVED, data);
});
}
}, {
key: '_onStatisticsInfo', key: '_onStatisticsInfo',
value: function _onStatisticsInfo(statisticsInfo) { value: function _onStatisticsInfo(statisticsInfo) {
var _this8 = this; var _this6 = this;
Promise.resolve().then(function () { Promise.resolve().then(function () {
_this8._emitter.emit(_transmuxingEvents2.default.STATISTICS_INFO, statisticsInfo); _this6._emitter.emit(_transmuxingEvents2.default.STATISTICS_INFO, statisticsInfo);
}); });
} }
}, { }, {
key: '_onIOError', key: '_onIOError',
value: function _onIOError(type, info) { value: function _onIOError(type, info) {
var _this9 = this; var _this7 = this;
Promise.resolve().then(function () { Promise.resolve().then(function () {
_this9._emitter.emit(_transmuxingEvents2.default.IO_ERROR, type, info); _this7._emitter.emit(_transmuxingEvents2.default.IO_ERROR, type, info);
}); });
} }
}, { }, {
key: '_onDemuxError', key: '_onDemuxError',
value: function _onDemuxError(type, info) { value: function _onDemuxError(type, info) {
var _this10 = this; var _this8 = this;
Promise.resolve().then(function () { Promise.resolve().then(function () {
_this10._emitter.emit(_transmuxingEvents2.default.DEMUX_ERROR, type, info); _this8._emitter.emit(_transmuxingEvents2.default.DEMUX_ERROR, type, info);
}); });
} }
}, { }, {
key: '_onRecommendSeekpoint', key: '_onRecommendSeekpoint',
value: function _onRecommendSeekpoint(milliseconds) { value: function _onRecommendSeekpoint(milliseconds) {
var _this11 = this; var _this9 = this;
Promise.resolve().then(function () { Promise.resolve().then(function () {
_this11._emitter.emit(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, milliseconds); _this9._emitter.emit(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, milliseconds);
}); });
} }
}, { }, {
...@@ -3258,8 +3206,6 @@ ...@@ -3258,8 +3206,6 @@
Object.setPrototypeOf(data, _mediaInfo2.default.prototype); Object.setPrototypeOf(data, _mediaInfo2.default.prototype);
this._emitter.emit(message.msg, data); this._emitter.emit(message.msg, data);
break; break;
case _transmuxingEvents2.default.METADATA_ARRIVED:
case _transmuxingEvents2.default.SCRIPTDATA_ARRIVED:
case _transmuxingEvents2.default.STATISTICS_INFO: case _transmuxingEvents2.default.STATISTICS_INFO:
this._emitter.emit(message.msg, data); this._emitter.emit(message.msg, data);
break; break;
...@@ -3606,8 +3552,6 @@ ...@@ -3606,8 +3552,6 @@
this._demuxer.onError = this._onDemuxException.bind(this); this._demuxer.onError = this._onDemuxException.bind(this);
this._demuxer.onMediaInfo = this._onMediaInfo.bind(this); this._demuxer.onMediaInfo = this._onMediaInfo.bind(this);
this._demuxer.onMetaDataArrived = this._onMetaDataArrived.bind(this);
this._demuxer.onScriptDataArrived = this._onScriptDataArrived.bind(this);
this._remuxer.bindDataSource(this._demuxer.bindDataSource(this._ioctl)); this._remuxer.bindDataSource(this._demuxer.bindDataSource(this._ioctl));
...@@ -3658,16 +3602,6 @@ ...@@ -3658,16 +3602,6 @@
} }
} }
}, { }, {
key: '_onMetaDataArrived',
value: function _onMetaDataArrived(metadata) {
this._emitter.emit(_transmuxingEvents2.default.METADATA_ARRIVED, metadata);
}
}, {
key: '_onScriptDataArrived',
value: function _onScriptDataArrived(data) {
this._emitter.emit(_transmuxingEvents2.default.SCRIPTDATA_ARRIVED, data);
}
}, {
key: '_onIOSeeked', key: '_onIOSeeked',
value: function _onIOSeeked() { value: function _onIOSeeked() {
this._remuxer.insertDiscontinuity(); this._remuxer.insertDiscontinuity();
...@@ -3680,7 +3614,6 @@ ...@@ -3680,7 +3614,6 @@
if (nextSegmentIndex < this._mediaDataSource.segments.length) { if (nextSegmentIndex < this._mediaDataSource.segments.length) {
this._internalAbort(); this._internalAbort();
this._remuxer.flushStashedSamples();
this._loadSegment(nextSegmentIndex); this._loadSegment(nextSegmentIndex);
} else { } else {
this._remuxer.flushStashedSamples(); this._remuxer.flushStashedSamples();
...@@ -3826,8 +3759,6 @@ ...@@ -3826,8 +3759,6 @@
LOADING_COMPLETE: 'loading_complete', LOADING_COMPLETE: 'loading_complete',
RECOVERED_EARLY_EOF: 'recovered_early_eof', RECOVERED_EARLY_EOF: 'recovered_early_eof',
MEDIA_INFO: 'media_info', MEDIA_INFO: 'media_info',
METADATA_ARRIVED: 'metadata_arrived',
SCRIPTDATA_ARRIVED: 'scriptdata_arrived',
STATISTICS_INFO: 'statistics_info', STATISTICS_INFO: 'statistics_info',
RECOMMEND_SEEKPOINT: 'recommend_seekpoint' RECOMMEND_SEEKPOINT: 'recommend_seekpoint'
}; };
...@@ -3895,8 +3826,6 @@ ...@@ -3895,8 +3826,6 @@
controller.on(_transmuxingEvents2.default.LOADING_COMPLETE, onLoadingComplete.bind(this)); controller.on(_transmuxingEvents2.default.LOADING_COMPLETE, onLoadingComplete.bind(this));
controller.on(_transmuxingEvents2.default.RECOVERED_EARLY_EOF, onRecoveredEarlyEof.bind(this)); controller.on(_transmuxingEvents2.default.RECOVERED_EARLY_EOF, onRecoveredEarlyEof.bind(this));
controller.on(_transmuxingEvents2.default.MEDIA_INFO, onMediaInfo.bind(this)); controller.on(_transmuxingEvents2.default.MEDIA_INFO, onMediaInfo.bind(this));
controller.on(_transmuxingEvents2.default.METADATA_ARRIVED, onMetaDataArrived.bind(this));
controller.on(_transmuxingEvents2.default.SCRIPTDATA_ARRIVED, onScriptDataArrived.bind(this));
controller.on(_transmuxingEvents2.default.STATISTICS_INFO, onStatisticsInfo.bind(this)); controller.on(_transmuxingEvents2.default.STATISTICS_INFO, onStatisticsInfo.bind(this));
controller.on(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, onRecommendSeekpoint.bind(this)); controller.on(_transmuxingEvents2.default.RECOMMEND_SEEKPOINT, onRecommendSeekpoint.bind(this));
break; break;
...@@ -3981,22 +3910,6 @@ ...@@ -3981,22 +3910,6 @@
self.postMessage(obj); self.postMessage(obj);
} }
function onMetaDataArrived(metadata) {
var obj = {
msg: _transmuxingEvents2.default.METADATA_ARRIVED,
data: metadata
};
self.postMessage(obj);
}
function onScriptDataArrived(data) {
var obj = {
msg: _transmuxingEvents2.default.SCRIPTDATA_ARRIVED,
data: data
};
self.postMessage(obj);
}
function onStatisticsInfo(statInfo) { function onStatisticsInfo(statInfo) {
var obj = { var obj = {
msg: _transmuxingEvents2.default.STATISTICS_INFO, msg: _transmuxingEvents2.default.STATISTICS_INFO,
...@@ -4597,8 +4510,6 @@ ...@@ -4597,8 +4510,6 @@
this._onError = null; this._onError = null;
this._onMediaInfo = null; this._onMediaInfo = null;
this._onMetaDataArrived = null;
this._onScriptDataArrived = null;
this._onTrackMetadata = null; this._onTrackMetadata = null;
this._onDataAvailable = null; this._onDataAvailable = null;
...@@ -4668,8 +4579,6 @@ ...@@ -4668,8 +4579,6 @@
this._onError = null; this._onError = null;
this._onMediaInfo = null; this._onMediaInfo = null;
this._onMetaDataArrived = null;
this._onScriptDataArrived = null;
this._onTrackMetadata = null; this._onTrackMetadata = null;
this._onDataAvailable = null; this._onDataAvailable = null;
} }
...@@ -4829,10 +4738,6 @@ ...@@ -4829,10 +4738,6 @@
this._metadata = scriptData; this._metadata = scriptData;
var onMetaData = this._metadata.onMetaData; var onMetaData = this._metadata.onMetaData;
if (this._onMetaDataArrived) {
this._onMetaDataArrived(Object.assign({}, onMetaData));
}
if (typeof onMetaData.hasAudio === 'boolean') { if (typeof onMetaData.hasAudio === 'boolean') {
// hasAudio // hasAudio
if (this._hasAudioFlagOverrided === false) { if (this._hasAudioFlagOverrided === false) {
...@@ -4901,12 +4806,6 @@ ...@@ -4901,12 +4806,6 @@
this._onMediaInfo(this._mediaInfo); this._onMediaInfo(this._mediaInfo);
} }
} }
if (Object.keys(scriptData).length > 0) {
if (this._onScriptDataArrived) {
this._onScriptDataArrived(Object.assign({}, scriptData));
}
}
} }
}, { }, {
key: '_parseKeyframesIndex', key: '_parseKeyframesIndex',
...@@ -5598,22 +5497,6 @@ ...@@ -5598,22 +5497,6 @@
set: function set(callback) { set: function set(callback) {
this._onMediaInfo = callback; this._onMediaInfo = callback;
} }
}, {
key: 'onMetaDataArrived',
get: function get() {
return this._onMetaDataArrived;
},
set: function set(callback) {
this._onMetaDataArrived = callback;
}
}, {
key: 'onScriptDataArrived',
get: function get() {
return this._onScriptDataArrived;
},
set: function set(callback) {
this._onScriptDataArrived = callback;
}
// prototype: function(type: number, info: string): void // prototype: function(type: number, info: string): void
...@@ -6065,8 +5948,6 @@ ...@@ -6065,8 +5948,6 @@
var _features2 = _interopRequireDefault(_features); var _features2 = _interopRequireDefault(_features);
var _loader = _dereq_('./io/loader.js');
var _flvPlayer = _dereq_('./player/flv-player.js'); var _flvPlayer = _dereq_('./player/flv-player.js');
var _flvPlayer2 = _interopRequireDefault(_flvPlayer); var _flvPlayer2 = _interopRequireDefault(_flvPlayer);
...@@ -6129,10 +6010,6 @@ ...@@ -6129,10 +6010,6 @@
flvjs.isSupported = isSupported; flvjs.isSupported = isSupported;
flvjs.getFeatureList = getFeatureList; flvjs.getFeatureList = getFeatureList;
flvjs.BaseLoader = _loader.BaseLoader;
flvjs.LoaderStatus = _loader.LoaderStatus;
flvjs.LoaderErrors = _loader.LoaderErrors;
flvjs.Events = _playerEvents2.default; flvjs.Events = _playerEvents2.default;
flvjs.ErrorTypes = _playerErrors.ErrorTypes; flvjs.ErrorTypes = _playerErrors.ErrorTypes;
flvjs.ErrorDetails = _playerErrors.ErrorDetails; flvjs.ErrorDetails = _playerErrors.ErrorDetails;
...@@ -6145,13 +6022,13 @@ ...@@ -6145,13 +6022,13 @@
enumerable: true, enumerable: true,
get: function get() { get: function get() {
// replaced by browserify-versionify transform // replaced by browserify-versionify transform
return '1.5.0'; return '1.4.0';
} }
}); });
exports.default = flvjs; exports.default = flvjs;
},{"./core/features.js":6,"./io/loader.js":24,"./player/flv-player.js":32,"./player/native-player.js":33,"./player/player-errors.js":34,"./player/player-events.js":35,"./utils/exception.js":40,"./utils/logging-control.js":42,"./utils/polyfill.js":43}],21:[function(_dereq_,module,exports){ },{"./core/features.js":6,"./player/flv-player.js":32,"./player/native-player.js":33,"./player/player-errors.js":34,"./player/player-events.js":35,"./utils/exception.js":40,"./utils/logging-control.js":42,"./utils/polyfill.js":43}],21:[function(_dereq_,module,exports){
'use strict'; 'use strict';
// entry/index file // entry/index file
...@@ -6294,13 +6171,6 @@ ...@@ -6294,13 +6171,6 @@
referrerPolicy: 'no-referrer-when-downgrade' referrerPolicy: 'no-referrer-when-downgrade'
}; };
// add additional headers
if (_typeof(this._config.headers) === 'object') {
for (var _key in this._config.headers) {
headers.append(_key, this._config.headers[_key]);
}
}
// cors is enabled by default // cors is enabled by default
if (dataSource.cors === false) { if (dataSource.cors === false) {
// no-cors means 'disregard cors policy', which can only be used in ServiceWorker // no-cors means 'disregard cors policy', which can only be used in ServiceWorker
...@@ -6373,23 +6243,9 @@ ...@@ -6373,23 +6243,9 @@
// ReadableStreamReader // ReadableStreamReader
return reader.read().then(function (result) { return reader.read().then(function (result) {
if (result.done) { if (result.done) {
// First check received length _this3._status = _loader.LoaderStatus.kComplete;
if (_this3._contentLength !== null && _this3._receivedLength < _this3._contentLength) { if (_this3._onComplete) {
// Report Early-EOF _this3._onComplete(_this3._range.from, _this3._range.from + _this3._receivedLength - 1);
_this3._status = _loader.LoaderStatus.kError;
var type = _loader.LoaderErrors.EARLY_EOF;
var info = { code: -1, msg: 'Fetch stream meet Early-EOF' };
if (_this3._onError) {
_this3._onError(type, info);
} else {
throw new _exception.RuntimeException(info.msg);
}
} else {
// OK. Download complete
_this3._status = _loader.LoaderStatus.kComplete;
if (_this3._onComplete) {
_this3._onComplete(_this3._range.from, _this3._range.from + _this3._receivedLength - 1);
}
} }
} else { } else {
if (_this3._requestAbort === true) { if (_this3._requestAbort === true) {
...@@ -6644,9 +6500,7 @@ ...@@ -6644,9 +6500,7 @@
}, { }, {
key: '_selectLoader', key: '_selectLoader',
value: function _selectLoader() { value: function _selectLoader() {
if (this._config.customLoader != null) { if (this._isWebSocketURL) {
this._loaderClass = this._config.customLoader;
} else if (this._isWebSocketURL) {
this._loaderClass = _websocketLoader2.default; this._loaderClass = _websocketLoader2.default;
} else if (_fetchStreamLoader2.default.isSupported()) { } else if (_fetchStreamLoader2.default.isSupported()) {
this._loaderClass = _fetchStreamLoader2.default; this._loaderClass = _fetchStreamLoader2.default;
...@@ -7963,17 +7817,6 @@ ...@@ -7963,17 +7817,6 @@
} }
} }
// add additional headers
if (_typeof(this._config.headers) === 'object') {
var _headers = this._config.headers;
for (var _key in _headers) {
if (_headers.hasOwnProperty(_key)) {
xhr.setRequestHeader(_key, _headers[_key]);
}
}
}
this._status = _loader.LoaderStatus.kConnecting; this._status = _loader.LoaderStatus.kConnecting;
xhr.send(); xhr.send();
} }
...@@ -8258,17 +8101,6 @@ ...@@ -8258,17 +8101,6 @@
} }
} }
// add additional headers
if (_typeof(this._config.headers) === 'object') {
var _headers = this._config.headers;
for (var _key in _headers) {
if (_headers.hasOwnProperty(_key)) {
xhr.setRequestHeader(_key, _headers[_key]);
}
}
}
if (this._isReconnecting) { if (this._isReconnecting) {
this._isReconnecting = false; this._isReconnecting = false;
} else { } else {
...@@ -8633,17 +8465,6 @@ ...@@ -8633,17 +8465,6 @@
} }
} }
// add additional headers
if (_typeof(this._config.headers) === 'object') {
var _headers = this._config.headers;
for (var _key in _headers) {
if (_headers.hasOwnProperty(_key)) {
xhr.setRequestHeader(_key, _headers[_key]);
}
}
}
xhr.send(); xhr.send();
} }
}, { }, {
...@@ -9146,12 +8967,6 @@ ...@@ -9146,12 +8967,6 @@
_this3._mediaInfo = mediaInfo; _this3._mediaInfo = mediaInfo;
_this3._emitter.emit(_playerEvents2.default.MEDIA_INFO, Object.assign({}, mediaInfo)); _this3._emitter.emit(_playerEvents2.default.MEDIA_INFO, Object.assign({}, mediaInfo));
}); });
this._transmuxer.on(_transmuxingEvents2.default.METADATA_ARRIVED, function (metadata) {
_this3._emitter.emit(_playerEvents2.default.METADATA_ARRIVED, metadata);
});
this._transmuxer.on(_transmuxingEvents2.default.SCRIPTDATA_ARRIVED, function (data) {
_this3._emitter.emit(_playerEvents2.default.SCRIPTDATA_ARRIVED, data);
});
this._transmuxer.on(_transmuxingEvents2.default.STATISTICS_INFO, function (statInfo) { this._transmuxer.on(_transmuxingEvents2.default.STATISTICS_INFO, function (statInfo) {
_this3._statisticsInfo = _this3._fillStatisticsInfo(statInfo); _this3._statisticsInfo = _this3._fillStatisticsInfo(statInfo);
_this3._emitter.emit(_playerEvents2.default.STATISTICS_INFO, Object.assign({}, _this3._statisticsInfo)); _this3._emitter.emit(_playerEvents2.default.STATISTICS_INFO, Object.assign({}, _this3._statisticsInfo));
...@@ -9921,8 +9736,6 @@ ...@@ -9921,8 +9736,6 @@
LOADING_COMPLETE: 'loading_complete', LOADING_COMPLETE: 'loading_complete',
RECOVERED_EARLY_EOF: 'recovered_early_eof', RECOVERED_EARLY_EOF: 'recovered_early_eof',
MEDIA_INFO: 'media_info', MEDIA_INFO: 'media_info',
METADATA_ARRIVED: 'metadata_arrived',
SCRIPTDATA_ARRIVED: 'scriptdata_arrived',
STATISTICS_INFO: 'statistics_info' STATISTICS_INFO: 'statistics_info'
}; };
...@@ -10956,7 +10769,7 @@ ...@@ -10956,7 +10769,7 @@
} }
}; };
silentFrames.push(frame); silentFrames.push(frame);
mdatBytes += frame.size; mdatBytes += unit.byteLength;
currentDts += refSampleDuration; currentDts += refSampleDuration;
} }
...@@ -11591,7 +11404,7 @@ ...@@ -11591,7 +11404,7 @@
} else if (console.warn) { } else if (console.warn) {
console.warn(str); console.warn(str);
} else { } else {
//console.log(str); console.log(str);
} }
} }
}, { }, {
...@@ -11612,7 +11425,7 @@ ...@@ -11612,7 +11425,7 @@
if (console.info) { if (console.info) {
console.info(str); console.info(str);
} else { } else {
//console.log(str); console.log(str);
} }
} }
}, { }, {
...@@ -11633,7 +11446,7 @@ ...@@ -11633,7 +11446,7 @@
if (console.warn) { if (console.warn) {
console.warn(str); console.warn(str);
} else { } else {
//console.log(str); console.log(str);
} }
} }
}, { }, {
...@@ -11654,7 +11467,7 @@ ...@@ -11654,7 +11467,7 @@
if (console.debug) { if (console.debug) {
console.debug(str); console.debug(str);
} else { } else {
//console.log(str); console.log(str);
} }
} }
}, { }, {
...@@ -11672,7 +11485,7 @@ ...@@ -11672,7 +11485,7 @@
return; return;
} }
//console.log(str); console.log(str);
} }
}]); }]);
......
...@@ -480,7 +480,8 @@ $(function () { ...@@ -480,7 +480,8 @@ $(function () {
var sendType=1; var sendType=1;
var guardShowOk=null; var guardShowOk=null;
var richType=1 var richType=1
var layzT=true; var layzT=true;3
$(window).on("scroll",function(){ $(window).on("scroll",function(){
if(layzT==true){ if(layzT==true){
layzT=false layzT=false
...@@ -622,13 +623,15 @@ $(function () { ...@@ -622,13 +623,15 @@ $(function () {
if (promise !== undefined) { if (promise !== undefined) {
promise.then(_ => { promise.then(_ => {
var html = []; var html = [];
html += '<div class="live-video jswebrtc" data-url="'+data.pullFlowUrl+'" ></div>';
$(".live-content-box-left-roombox").html(html)
html += '<video controls webkit-playsinline ="true" playsinline ="true" autoplay ="" playsinline="true" class="live-video" src="" id="videoElement" loop="" ></video>'; html += '<video controls webkit-playsinline ="true" playsinline ="true" autoplay ="" playsinline="true" class="live-video" src="" id="videoElement" loop="" ></video>';
$(".live-content-box-left-roombox").html(html) $(".live-content-box-left-roombox").html(html)
flvPlay(data.pullFlowUrl) flvPlay(data.pullFlowUrl)
// Autoplay started! // Autoplay started!
}).catch(error => { }).catch(error => {
var myVideo=document.querySelector(".live-video") var myVideo=document.querySelector(".live-video")
var html = []; var html = [];
html += '<video controls webkit-playsinline ="true" muted playsinline ="true" autoplay ="" playsinline="true" class="live-video" src="" id="videoElement" loop="" ></video>'; html += '<video controls webkit-playsinline ="true" muted playsinline ="true" autoplay ="" playsinline="true" class="live-video" src="" id="videoElement" loop="" ></video>';
$(".live-content-box-left-roombox").html(html) $(".live-content-box-left-roombox").html(html)
flvPlay(data.pullFlowUrl) flvPlay(data.pullFlowUrl)
......
...@@ -226,10 +226,10 @@ $(function(){ ...@@ -226,10 +226,10 @@ $(function(){
} }
$(".video-tag-box").html(html); $(".video-tag-box").html(html);
var html=[]; var html=[];
html+='<video autoplay="" class="video" src="" id="videoElement" controls="" loop="" poster="https://zhibocdn.yabolive.net/comm'+videoList.videos[0].cover+'"></video>'; html+='<video autoplay="" class="video" src="https://zhibocdn.yabolive.net/comm'+videoList.videos[0].url.replace("flv","mp4")+'" id="videoElement" controls="" loop="" poster="https://zhibocdn.yabolive.net/comm'+videoList.videos[0].cover+'"></video>';
$(".video-play-box").html(html) $(".video-play-box").html(html)
var flvUrl=videoList.videos[0].url.replace("mp4","flv") // var flvUrl=videoList.videos[0].url.replace("mp4","flv")
flvPlay('https://zhibocdn.yabolive.net/comm'+flvUrl+'') // flvPlay('https://zhibocdn.yabolive.net/comm'+flvUrl+'')
if(data.selfUp==1) var html='<div><img src="images/icon1.png" alt=""><span>'+data.comment+'</span></div><div class="good-box"><img class="good-btn" data-type="1" src="images/icon2-click.png" alt=""><span>'+data.up+'</span></div>'; if(data.selfUp==1) var html='<div><img src="images/icon1.png" alt=""><span>'+data.comment+'</span></div><div class="good-box"><img class="good-btn" data-type="1" src="images/icon2-click.png" alt=""><span>'+data.up+'</span></div>';
else var html='<div><img src="images/icon1.png" alt=""><span>'+data.comment+'</span></div><div class="good-box"><img class="good-btn" data-type="0" src="images/icon2.png" alt=""><span>'+data.up+'</span></div>'; else var html='<div><img src="images/icon1.png" alt=""><span>'+data.comment+'</span></div><div class="good-box"><img class="good-btn" data-type="0" src="images/icon2.png" alt=""><span>'+data.up+'</span></div>';
$(".video-btn-box").html(html) $(".video-btn-box").html(html)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment