@jxstjh/jhvideo
Version:
HTML5 jhvideo base on MPEG2-TS Stream Player
208 lines • 8.73 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import httpClient from './core/httpClient';
import { Base64 } from '../node_modules/js-base64/base64';
/*
*@description
*@author jsyang
*@date 2021-06-03 14:55:19
*@variable LoginUrl 登录接口
*@variable 变量2
*@variable 变量3
*/
export var STATUS_TYPE = {
'LOGIN_SUCCESS': 'LoginSuccess',
'LOGIN_ERROR': 'LoginError'
};
var LoginUrl = '/oauth/token';
export var serverName = '/video-platform-basedata';
// export const getAislesBySearchObjUrl = '/hik-stream/aisle-page'
export var getAislesUrl = '/hik-stream/aisle-page';
var GlobalClientConfig = /** @class */ (function () {
function GlobalClientConfig() {
}
return GlobalClientConfig;
}());
export { GlobalClientConfig };
/**
* authClient
* @param 参数1
* @param 参数2
* @return
* @description
* @author jsyang
* @date 2021-11-01 20:13:07
*/
var GlobalClient = /** @class */ (function () {
function GlobalClient(config, onStatusChanged) {
if (onStatusChanged === void 0) { onStatusChanged = function (statusMsg) { }; }
var _this = this;
this.config = __assign({ clientId: "third-aplication", clientSecret: "third-aplication2021" }, config);
this._onStatusChanged = onStatusChanged;
var username = config.appKey || config.username;
var password = config.appSecret || config.password;
this.login(config.endPoint + serverName + LoginUrl + '?grant_type=password&scope=server', { username: username, password: password }).then(function (res) {
if (res.code === 0) {
_this.data = res.data;
}
else {
throw new Error(res);
}
}).then(function () {
_this._onStatusChanged(STATUS_TYPE.LOGIN_SUCCESS);
}).catch(function (err) {
_this._onStatusChanged(STATUS_TYPE.LOGIN_ERROR, err);
});
}
Object.defineProperty(GlobalClient.prototype, "config", {
get: function () {
return this._config;
},
set: function (config) {
this._config = __assign({}, config);
},
enumerable: false,
configurable: true
});
Object.defineProperty(GlobalClient.prototype, "data", {
get: function () {
return this._data;
},
set: function (data) {
this._data = __assign({}, data);
},
enumerable: false,
configurable: true
});
Object.defineProperty(GlobalClient.prototype, "accessToken", {
get: function () {
return this.data.access_token;
},
enumerable: false,
configurable: true
});
GlobalClient.prototype.login = function (url, body) {
var _a = this.config, clientId = _a.clientId, clientSecret = _a.clientSecret;
return httpClient.post(url, body, {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": 'Basic ' + Base64.encode("".concat(clientId, ":").concat(clientSecret)),
});
};
GlobalClient.prototype.reLogin = function () {
return __awaiter(this, void 0, void 0, function () {
var config;
var _this = this;
return __generator(this, function (_a) {
config = this.config;
return [2 /*return*/, new Promise(function (reslove, reject) {
var url = config.endPoint + serverName + LoginUrl + '?grant_type=password&scope=server';
_this.login(url, {
username: _this.config.username,
password: _this.config.password
}).then(function (res) {
if (res.code === 0) {
_this.data = res.data;
reslove(res.data);
}
else {
reject(res);
}
}).catch(function (err) {
reject(err);
});
})];
});
});
};
/*public getAislesBySearchObj(obj) {
return new Promise((reslove, reject) => {
if (!this.accessToken) {
reject('无登录信息!')
}
const { config } = this;
const url = config.endPoint + serverName + getAislesBySearchObjUrl
httpClient.get(url, obj, {
"Content-Type": "application/json;charset=UTF-8",
"Authorization": 'Bearer ' + this.accessToken,
}).then(res => {
if (res.code === 0) {
reslove(res)
} else {
reject(res)
}
}).catch(err => reject(err))
})
}*/
GlobalClient.prototype.getAisles = function (params) {
var _this = this;
return new Promise(function (reslove, reject) {
if (!_this.accessToken) {
reject('无登录信息!');
}
var config = _this.config;
var url = config.endPoint + serverName + getAislesUrl;
httpClient.get(url, params, {
"Content-Type": "application/json;charset=UTF-8",
"Authorization": 'Bearer ' + _this.accessToken,
}).then(function (res) {
if (res.code === 0) {
reslove(res);
}
else {
reject(res);
}
}).catch(function (err) { return reject(err); });
});
};
GlobalClient.prototype.destroy = function () { };
return GlobalClient;
}());
export { GlobalClient };
;
export default GlobalClient;
//# sourceMappingURL=globalClient.js.map