Toggle navigation
Toggle navigation
This project
Loading...
Sign in
digsig
/
digsig-player-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Stefan Huber
2017-02-06 17:59:45 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fd68ad6868d42702008a1ad543dde29b7a76256f
fd68ad68
1 parent
643e8077
testing support
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
49 additions
and
21 deletions
build/bundle.js
build/bundle.js.map
index.d.ts
rollup.config.js
spec/dummy-program-repository.ts
spec/player.spec.ts
spec/util.spec.ts
src/player.ts
src/program-manager.ts
src/program-repository.ts
build/bundle.js
View file @
fd68ad6
This diff is collapsed. Click to expand it.
build/bundle.js.map
View file @
fd68ad6
This diff is collapsed. Click to expand it.
index.d.ts
View file @
fd68ad6
...
...
@@ -6,19 +6,30 @@ interface ProgramRepository {
}
interface
Player
{
new
()
:
Player
;
on
(
name
:
string
,
any
);
once
(
name
:
string
,
any
);
start
()
:
void
;
stop
()
:
void
;
programRepository
:
ProgramRepository
;
programManager
:
ProgramManager
;
}
interface
ProgramManager
{
new
()
:
ProgramManager
;
programRepository
:
ProgramRepository
;
}
interface
ProgramItemFactory
{
basePath
:
string
;
programRepository
:
ProgramRepository
;
new
()
:
ProgramItemFactory
;
getProgramItem
(
programItemId
:
string
)
:
Promise
<
any
>
;
basePath
:
string
;
programRepository
:
ProgramRepository
;
}
declare
var
digsigPlayer
:
{
...
...
rollup.config.js
View file @
fd68ad6
...
...
@@ -15,8 +15,8 @@ var rollupConfig = {
dest
:
'build/bundle.js'
,
plugins
:
[
builtins
(),
globals
(),
//
builtins(),
//
globals(),
typescript
()
]
...
...
spec/dummy-program-repository.ts
View file @
fd68ad6
...
...
@@ -15,7 +15,7 @@ export class DummyProgramRepository implements ProgramRepository {
return
null
;
}
replicate
()
:
Promise
<
void
>
{
replicate
()
:
Promise
<
boolean
>
{
return
null
;
}
...
...
spec/player.spec.ts
View file @
fd68ad6
...
...
@@ -31,8 +31,7 @@ describe('Player repository triggers', () => {
});
player
.
triggerReplication
().
then
(()
=>
{
expect
(
player
.
trigger
).
toHaveBeenCalledWith
(
player
.
triggerProgramItemId
,
Util
.
calculateNextMinute
());
expect
(
player
.
trigger
).
toHaveBeenCalled
();
done
();
});
});
...
...
@@ -44,10 +43,12 @@ describe('Player repository triggers', () => {
});
});
player
.
triggerReplication
().
then
(
()
=>
{
expect
(
player
.
trigger
).
toHaveBeenCalled
With
(
player
.
triggerReplication
,
player
.
replicationRetry
);
player
.
once
(
'error'
,
()
=>
{
expect
(
player
.
trigger
).
toHaveBeenCalled
(
);
done
();
});
player
.
triggerReplication
();
});
});
...
...
spec/util.spec.ts
View file @
fd68ad6
...
...
@@ -13,7 +13,8 @@ describe("Util", () => {
});
it
(
'should get the remaining seconds'
,
()
=>
{
expect
(
Util
.
calculateNextMinute
()).
toEqual
((
60
-
(
new
Date
()).
getSeconds
())
*
1000
);
let
now
=
(
60
-
(
new
Date
()).
getSeconds
());
expect
(
Util
.
calculateNextMinute
()
/
1000
).
toBeCloseTo
(
now
);
});
});
\ No newline at end of file
...
...
src/player.ts
View file @
fd68ad6
...
...
@@ -8,9 +8,13 @@ const STATE_STOP = "stop";
export
class
Player
extends
EventEmitter
{
constructor
()
{
super
();
}
protected
_programRepository
:
ProgramRepository
;
protected
_programManager
:
ProgramManager
;
protected
_minutesReplication
:
number
=
5
;
protected
_minutesReplication
:
number
=
3
;
protected
_replicationRetry
:
number
=
10000
;
protected
_currentProgramItemId
:
string
=
''
;
...
...
@@ -54,17 +58,22 @@ export class Player extends EventEmitter {
}
triggerReplication
()
:
Promise
<
void
>
{
console
.
info
(
"digsig-player-service: trigger replication"
);
return
this
.
programRepository
.
replicate
()
.
then
(
()
=>
{
.
then
(
changes
=>
{
this
.
_currentReplicationCounter
=
0
;
this
.
trigger
(
this
.
triggerProgramItemId
,
Util
.
calculateNextMinute
()
);
this
.
trigger
(
()
=>
{
this
.
triggerProgramItemId
(
changes
);
}
);
})
.
catch
(()
=>
{
this
.
trigger
(
this
.
triggerReplication
,
this
.
replicationRetry
);
.
catch
(
error
=>
{
this
.
trigger
(()
=>
{
this
.
triggerReplication
();
},
this
.
replicationRetry
);
this
.
emit
(
'error'
,
error
);
});
}
triggerProgramItemId
()
{
triggerProgramItemId
(
changes
:
boolean
=
false
)
{
console
.
info
(
"digsig-player-service: trigger program item id"
);
this
.
programManager
.
getCurrentProgramItemId
()
.
then
(
programItemId
=>
{
this
.
_currentReplicationCounter
++
;
...
...
@@ -73,18 +82,20 @@ export class Player extends EventEmitter {
// else (1) calculate next potential program change point
// or (2) trigger replication
if
(
programItemId
!=
this
.
_currentProgramItemId
)
{
if
(
programItemId
&&
(
programItemId
!=
this
.
_currentProgramItemId
||
changes
)
)
{
this
.
_currentProgramItemId
=
programItemId
;
this
.
emit
(
'play'
,
programItemId
);
}
else
if
(
this
.
_currentReplicationCounter
>=
this
.
_minutesReplication
)
{
}
if
(
this
.
_currentReplicationCounter
>=
this
.
_minutesReplication
)
{
this
.
triggerReplication
();
}
else
{
this
.
trigger
(
this
.
triggerProgramItemId
,
Util
.
calculateNextMinute
());
this
.
trigger
(
()
=>
{
this
.
triggerProgramItemId
();
}
,
Util
.
calculateNextMinute
());
}
});
}
trigger
(
func
:
Function
,
milliseconds
:
number
)
{
trigger
(
func
:
Function
,
milliseconds
:
number
=
0
)
{
if
(
this
.
_state
===
STATE_START
)
{
setTimeout
(()
=>
{
func
();
},
milliseconds
);
}
...
...
src/program-manager.ts
View file @
fd68ad6
...
...
@@ -33,6 +33,7 @@ export class ProgramManager {
findCurrentProgramItem
(
schedule
:
any
,
dateInMinutes
:
number
)
:
string
{
let
timeList
:
any
=
[];
let
tmpSchedule
:
any
=
{};
dateInMinutes
--
;
// make it not so strict, which will start one minute earlier
for
(
let
startTime
in
schedule
)
{
if
(
schedule
.
hasOwnProperty
(
startTime
))
{
...
...
src/program-repository.ts
View file @
fd68ad6
...
...
@@ -6,6 +6,9 @@ export interface ProgramRepository {
findByType
(
type
:
string
)
:
Promise
<
Array
<
any
>>
;
replicate
()
:
Promise
<
void
>
;
/**
* returns true / false depending on if there where any changes to download
*/
replicate
()
:
Promise
<
boolean
>
;
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment