1
- const { app, BrowserWindow, screen } = require ( 'electron' )
1
+ const { app, BrowserWindow, screen, ipcMain } = require ( 'electron' )
2
2
const path = require ( 'path' )
3
3
require ( 'dotenv' ) . config ( )
4
4
//require('electron-reloader')(module)
@@ -11,7 +11,7 @@ const peerflix = require("./vendor/peerflix");
11
11
const subsApi = require ( './src/subtitles/subtitles' ) ;
12
12
const port = process . env . PORT ;
13
13
14
- let g_activeMovieCode = null ;
14
+ let g_activeMedia = null ;
15
15
let mainWindow = null ;
16
16
let g_engine = null ;
17
17
let g_dirName = null ;
@@ -48,6 +48,10 @@ app.on('window-all-closed', function () {
48
48
if ( process . platform !== 'darwin' ) app . quit ( )
49
49
} )
50
50
51
+ ipcMain . on ( 'RES_PLAYER_STATUS' , ( event , arg ) => {
52
+ io . sockets . emit ( 'SET_PLAYER_PAUSED' , { isPaused :arg . isPaused } ) ;
53
+ } )
54
+
51
55
//
52
56
53
57
@@ -57,39 +61,52 @@ io.on("connection", socket => {
57
61
//receives the movie data from the mobile app
58
62
socket . on ( 'APP_START_STREAM' , ( data ) => {
59
63
const magnet = data . value . url
60
- g_activeMovieCode = data . imdb_code ;
64
+ g_activeMedia = data ;
61
65
62
66
//console.log(data);
63
67
start ( data , magnet ) ;
64
68
} )
65
69
66
70
//mobile app requesting status when the component is mounted
67
71
socket . on ( 'APP_GET_STATUS' , ( ) => {
68
- if ( g_engine != null && g_activeMovieCode != null ) {
69
- io . sockets . emit ( 'SET_WATCHING' , { condition :true , activeCode :g_activeMovieCode } ) ;
70
- } else {
71
- io . sockets . emit ( 'SET_WATCHING' , { condition :false } ) ;
72
- }
72
+ updateAppStatus ( ) ;
73
73
} )
74
74
75
75
socket . on ( 'APP_PAUSE_PLAYER' , ( ) => {
76
76
mainWindow . webContents . send ( 'PLAYER_PAUSE' ) ;
77
77
} )
78
78
79
+ socket . on ( 'APP_GET_PAUSED' , ( ) => {
80
+ mainWindow . webContents . send ( 'PLAYER_STATUS' ) ;
81
+ } )
82
+
79
83
//received when the mobile app press the button to close the player
80
84
socket . on ( 'APP_CLOSE_PROCESS' , ( ) => {
81
85
if ( g_engine ) {
82
86
mainWindow . webContents . send ( 'PLAYER_CLOSE' ) ;
83
87
g_engine . destroy ( ( ) => {
84
- io . sockets . emit ( 'SET_WATCHING' , { condition :false } ) ;
85
- g_activeMovieCode = null ;
88
+ g_activeMedia = null ;
86
89
g_engine = null ;
90
+ updateAppStatus ( )
87
91
fs . emptyDir ( g_dirName ) ;
88
92
} ) ;
89
93
}
90
94
} )
91
95
} ) ;
92
96
97
+ const updateAppStatus = ( ) => {
98
+ if ( g_engine != null && g_activeMedia != null ) {
99
+ const media = {
100
+ ...g_activeMedia . value ,
101
+ title : g_activeMedia . title ,
102
+ largeImage : g_activeMedia . largeImage ,
103
+ }
104
+ io . sockets . emit ( 'SET_STATUS_APP' , { condition :true , media} ) ;
105
+ } else {
106
+ io . sockets . emit ( 'SET_STATUS_APP' , { condition :false } ) ;
107
+ }
108
+ }
109
+
93
110
//starts the torrent-stream engine and opens the vlc with the engine stream;
94
111
async function start ( data , uri ) {
95
112
if ( ! uri ) {
@@ -122,7 +139,7 @@ openPlayer = async(data)=>{
122
139
const { status, subs} = await subsApi . getSubtitles ( data , g_dirName ) ;
123
140
let hasSubs = true ;
124
141
if ( status != 200 || subs < 1 ) {
125
- console . log ( chalk . red ( 'Starting without subtitles' ) ) ;
142
+ console . log ( 'Starting without subtitles' ) ;
126
143
hasSubs = false ;
127
144
}
128
145
@@ -147,7 +164,7 @@ openPlayer = async(data)=>{
147
164
clearInterval ( interval ) ;
148
165
149
166
//send watching status to mobile app to show the buttons
150
- io . sockets . emit ( 'SET_WATCHING ' , { condition : true , activeCode : g_activeMovieCode } ) ;
167
+ io . sockets . emit ( 'SET_STATUS_APP ' , { condition : true , activeMedia : g_activeMedia } ) ;
151
168
152
169
//streaming crashes if i remove the verify listener
153
170
//g_engine.removeListener('verify', changePiece)
0 commit comments