Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"material-design-lite": "1.3.0",
"ngx-clipboard": "13.0.1",
"nouislider": "14.6.0",
"otpauth": "^7.0.6",
"popper.js": "^1.16.1",
"rxjs": "^6.6.2",
"tslib": "^2.0.1",
Expand Down
326 changes: 323 additions & 3 deletions src/app/app.page/app.page.component.html

Large diffs are not rendered by default.

162 changes: 160 additions & 2 deletions src/app/app.page/app.page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {MatTableDataSource} from "@angular/material/table"
import {MatSort} from "@angular/material/sort"
import "rxjs/add/operator/toPromise";
import {AppSettings, ServerSettings} from "./app.definitions";
import * as OTPAuth from 'otpauth';

import {
BroadcastInfo,
Expand Down Expand Up @@ -188,6 +189,27 @@ export class AppPageComponent implements OnInit, OnDestroy, AfterViewInit {
public user: User;
public currentClusterNode: string;

public jwtPublishToken: String;
public jwtPlayToken: String;
public jwtPublishStreamId: string;
public jwtPlayStreamId: String;
public jwtPublishStreamIdCheck = true;
public jwtPlayStreamIdCheck = true;
public oneTimeTokenPublishStreamIdCheck = true;
public oneTimeTokenPlayStreamIdCheck = true;
public TOTPSecret = "mysecret";
public TOTPNoOfDigits = 6;
public TOTPPeriod = 60;
public TOTPToken : string;
public TOTPGeneratorTimer = null;
public timeLeftForTOTP = 0;

public oneTimeTokenPublishStreamId: string;
public oneTimePublishToken: string;
public oneTimePlayToken: string;
public oneTimeTokenPlayStreamId: string;



public appSettings: AppSettings; // = new AppSettings(false, true, true, 5, 2, "event", "no clientid", "no fb secret", "no youtube cid", "no youtube secre", "no pers cid", "no pers sec");
public token: Token;
Expand Down Expand Up @@ -767,6 +789,12 @@ export class AppPageComponent implements OnInit, OnDestroy, AfterViewInit {
this.timerId = null ;
this.dropdownTimer = null ;

if(this.TOTPGeneratorTimer != null || typeof this.TOTPGeneratorTimer != "undefined"){
clearInterval(this.TOTPGeneratorTimer);

this.TOTPGeneratorTimer = null;
}

}

ngOnDestroy() {
Expand Down Expand Up @@ -952,7 +980,8 @@ export class AppPageComponent implements OnInit, OnDestroy, AfterViewInit {
let currentUnixTime : number = Math.floor(Date.now() / 1000)
let expireDate : number = currentUnixTime + 100;

this.restService.getOneTimeToken (this.appName, tokenParam, expireDate).subscribe(data => {

this.restService.getOneTimeToken (this.appName, tokenParam, expireDate, "play").subscribe(data => {
this.token = <Token>data;
this.openPlayer(this.getIFrameEmbedCode(id), id, path, "640px", this.token.tokenId)
});
Expand All @@ -962,7 +991,7 @@ export class AppPageComponent implements OnInit, OnDestroy, AfterViewInit {
let currentUnixTime : number = Math.floor(Date.now() / 1000)
let expireDate : number = currentUnixTime + 100;

this.restService.getJWTToken(this.appName, tokenParam, expireDate).subscribe(data => {
this.restService.getJwtToken(this.appName, tokenParam, expireDate, "play").subscribe(data => {
this.token = <Token>data;
this.openPlayer(this.getIFrameEmbedCode(id), id, path, "640px", this.token.tokenId)
});
Expand Down Expand Up @@ -1830,6 +1859,135 @@ export class AppPageComponent implements OnInit, OnDestroy, AfterViewInit {
return str;
};

generateTOTPToken(){
if((this.TOTPGeneratorTimer == null || typeof this.TOTPGeneratorTimer == "undefined")){
this.TOTPGeneratorTimer = setInterval(() => {
// Create a new TOTP object.
let totp = new OTPAuth.TOTP({
algorithm: 'SHA1',
digits: this.TOTPNoOfDigits,
period: this.TOTPPeriod,
secret: OTPAuth.Secret.fromBase32(this.TOTPSecret)
});
// Generate a token.
this.TOTPToken = totp.generate();
let currentTime = Math.round(new Date().getTime() / 1000.0);
this.timeLeftForTOTP = this.TOTPPeriod - (currentTime % this.TOTPPeriod);
if(!this.appSettings.enableTimeTokenForPublish && !this.appSettings.enableTimeTokenForPlay){
clearInterval(this.TOTPGeneratorTimer);
this.TOTPGeneratorTimer = null;
}
},1000)
}
}

//Get JWT token from the REST call to the server
getJwtStreamToken(type: string){
let currentUnixTime : number = Math.floor(Date.now() / 1000)
let expireDate : number = currentUnixTime + 100;

if(type == "publish"){
this.jwtPublishStreamIdCheck=true;
if(typeof this.jwtPublishStreamId == "undefined" || this.jwtPublishStreamId == null || this.jwtPublishStreamId == ""){
this.jwtPublishStreamIdCheck = false;
this.showTokenNotGenerated();
}
else{
this.restService.getJwtToken (this.appName, this.jwtPublishStreamId, expireDate, type).subscribe(data => {
this.token = <Token>data;
if(data["success"] == true){
this.jwtPublishToken = this.token.tokenId;
}
else{
this.showTokenNotGenerated();
}
},
error =>{
this.showTokenNotGenerated();
});
}
}
if(type == "play"){
this.jwtPlayStreamIdCheck=true;
if(typeof this.jwtPlayStreamId == "undefined" || this.jwtPlayStreamId == null || this.jwtPlayStreamId == ""){
this.jwtPlayStreamIdCheck = false;
this.showTokenNotGenerated();
}
else{
this.restService.getJwtToken (this.appName, this.jwtPublishStreamId, expireDate, type).subscribe(data => {
this.token = <Token>data;
if(data["success"] == true){
this.jwtPlayToken = this.token.tokenId;
}
else{
this.showTokenNotGenerated();
}
},
error =>{
this.showTokenNotGenerated();
});
}
}
}
getStreamToken(type: string){
let currentUnixTime : number = Math.floor(Date.now() / 1000)
let expireDate : number = currentUnixTime + 100;

if(type == "publish"){
this.oneTimeTokenPublishStreamIdCheck=true;
if(typeof this.oneTimeTokenPublishStreamId == "undefined" || this.oneTimeTokenPublishStreamId == null || this.oneTimeTokenPublishStreamId == ""){
this.oneTimeTokenPublishStreamIdCheck = false;
this.showTokenNotGenerated();
}
else{
this.restService.getOneTimeToken(this.appName, this.oneTimeTokenPublishStreamId, expireDate, type).subscribe(data => {
this.token = <Token>data;
if(data["tokenId"].length > 5){
this.oneTimePublishToken = this.token.tokenId;
}
else{
this.showTokenNotGenerated();
}

});
}
}
if(type == "play"){
this.oneTimeTokenPlayStreamIdCheck = true;
if(typeof this.oneTimeTokenPlayStreamId == "undefined" || this.oneTimeTokenPlayStreamId == null || this.oneTimeTokenPlayStreamId == ""){
this.oneTimeTokenPlayStreamIdCheck = false;
this.showTokenNotGenerated();
}
else{
this.restService.getOneTimeToken (this.appName, this.oneTimeTokenPlayStreamId, expireDate, type).subscribe(data => {
this.token = <Token>data;
if(data["tokenId"].length > 5){
this.oneTimePlayToken = this.token.tokenId;
}
else{
this.showTokenNotGenerated();
}
},
error =>{
this.showTokenNotGenerated();
});
}
}
}
showTokenNotGenerated() {
$.notify({
icon: "ti-save",
message: Locale.getLocaleInterface().token_not_generated
}, {
type: "warning",
delay: 900,
placement: {
from: 'top',
align: 'right'
}
});
}

startDiscover() {
this.discoveryStarted = true;
this.onvifURLs = this.getDiscoveryList();
Expand Down
1 change: 1 addition & 0 deletions src/app/locale/locale.en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export let Locale_English: LocaleInterface =
missing_configuration_parameter_for_stalker: "Configuration params are missing. Please contact system admin",
vod_deleted: "Vod file deleted successfully",
support: "Support",
token_not_generated: "Token can't be generated, please check secret and streamId"
}
1 change: 1 addition & 0 deletions src/app/locale/locale.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ export interface LocaleInterface {
missing_configuration_parameter_for_stalker: string;
vod_deleted: string;
support: string;
token_not_generated: string;
}
1 change: 1 addition & 0 deletions src/app/locale/locale.tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export let Locale_Turkish: LocaleInterface =
vod_deleted: "Vod başarıyla silindi.",
cluster: "Cluster",
support: "Destek",
token_not_generated: "Token oluşturulamadı, lütfen secret ve streamId yi kontrol edin."
}

10 changes: 5 additions & 5 deletions src/app/rest/rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,17 @@ export class RestService {
/**
* This methods get One Time Token
*/
public getOneTimeToken(appName: string, streamId: string, expireDate:number) : Observable<Object>{
return this.http.get(REST_SERVICE_ROOT + "/request?_path=" + appName
+ "/rest/v2/broadcasts/"+ streamId + "/token&expireDate=" + expireDate + "&type=play" );
public getOneTimeToken(appName: string, streamId: string, expireDate:number, type: string) : Observable<Object>{
return this.http.get(REST_SERVICE_ROOT + "/request?_path=" + appName
+ "/rest/v2/broadcasts/"+ streamId + "/token&expireDate=" + expireDate + "&type=" + type );
}

/**
* This methods get JWT Token
*/
public getJWTToken(appName: string, streamId: string, expireDate:number) : Observable<Object>{
public getJwtToken(appName: string, streamId: string, expireDate:number, type: string) : Observable<Object>{
return this.http.get(REST_SERVICE_ROOT + "/request?_path=" + appName
+ "/rest/v2/broadcasts/"+ streamId + "/jwt-token&expireDate=" + expireDate + "&type=play" );
+ "/rest/v2/broadcasts/"+ streamId + "/jwt-token&expireDate=" + expireDate + "&type=" + type );
}

public getRtmpUrl(appName:string, streamId:string): string {
Expand Down