mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-07-25 03:17:00 +00:00
Refractor shared code for tizen receiver
This commit is contained in:
parent
8d238ef8b1
commit
7be0a41166
10 changed files with 43 additions and 50 deletions
|
@ -1,7 +1,7 @@
|
||||||
import * as net from 'net';
|
import * as net from 'net';
|
||||||
import * as log4js from "modules/log4js";
|
import * as log4js from "modules/log4js";
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { PlaybackErrorMessage, PlaybackUpdateMessage, PlayMessage, SeekMessage, SetSpeedMessage, SetVolumeMessage, VersionMessage, VolumeUpdateMessage } from 'common/Packets';
|
import { Opcode, PlaybackErrorMessage, PlaybackUpdateMessage, PlayMessage, SeekMessage, SetSpeedMessage, SetVolumeMessage, VersionMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||||
import { WebSocket } from 'modules/ws';
|
import { WebSocket } from 'modules/ws';
|
||||||
const logger = log4js.getLogger();
|
const logger = log4js.getLogger();
|
||||||
|
|
||||||
|
@ -12,23 +12,6 @@ enum SessionState {
|
||||||
Disconnected,
|
Disconnected,
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum Opcode {
|
|
||||||
None = 0,
|
|
||||||
Play = 1,
|
|
||||||
Pause = 2,
|
|
||||||
Resume = 3,
|
|
||||||
Stop = 4,
|
|
||||||
Seek = 5,
|
|
||||||
PlaybackUpdate = 6,
|
|
||||||
VolumeUpdate = 7,
|
|
||||||
SetVolume = 8,
|
|
||||||
PlaybackError = 9,
|
|
||||||
SetSpeed = 10,
|
|
||||||
Version = 11,
|
|
||||||
Ping = 12,
|
|
||||||
Pong = 13
|
|
||||||
};
|
|
||||||
|
|
||||||
const LENGTH_BYTES = 4;
|
const LENGTH_BYTES = 4;
|
||||||
const MAXIMUM_PACKET_LENGTH = 32000;
|
const MAXIMUM_PACKET_LENGTH = 32000;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
|
export enum Opcode {
|
||||||
|
None = 0,
|
||||||
|
Play = 1,
|
||||||
|
Pause = 2,
|
||||||
|
Resume = 3,
|
||||||
|
Stop = 4,
|
||||||
|
Seek = 5,
|
||||||
|
PlaybackUpdate = 6,
|
||||||
|
VolumeUpdate = 7,
|
||||||
|
SetVolume = 8,
|
||||||
|
PlaybackError = 9,
|
||||||
|
SetSpeed = 10,
|
||||||
|
Version = 11,
|
||||||
|
Ping = 12,
|
||||||
|
Pong = 13
|
||||||
|
};
|
||||||
|
|
||||||
export class PlayMessage {
|
export class PlayMessage {
|
||||||
constructor(
|
constructor(
|
||||||
public container: string,
|
public container: string,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as net from 'net';
|
import * as net from 'net';
|
||||||
import { FCastSession, Opcode } from 'common/FCastSession';
|
import { FCastSession } from 'common/FCastSession';
|
||||||
|
import { Opcode } from 'common/Packets';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { Main, errorHandler } from 'src/Main';
|
import { Main, errorHandler } from 'src/Main';
|
||||||
import { v4 as uuidv4 } from 'modules/uuid';
|
import { v4 as uuidv4 } from 'modules/uuid';
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { FCastSession, Opcode } from 'common/FCastSession';
|
import { FCastSession } from 'common/FCastSession';
|
||||||
|
import { Opcode } from 'common/Packets';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { WebSocket, WebSocketServer } from 'modules/ws';
|
import { WebSocket, WebSocketServer } from 'modules/ws';
|
||||||
import { Main, errorHandler } from 'src/Main';
|
import { Main, errorHandler } from 'src/Main';
|
||||||
|
@ -52,11 +53,10 @@ export class WebSocketListenerService {
|
||||||
Main.logger.info('New WebSocket connection');
|
Main.logger.info('New WebSocket connection');
|
||||||
|
|
||||||
const session = new FCastSession(socket, (data) => socket.send(data));
|
const session = new FCastSession(socket, (data) => socket.send(data));
|
||||||
|
const connectionId = uuidv4();
|
||||||
session.bindEvents(this.emitter);
|
session.bindEvents(this.emitter);
|
||||||
this.sessions.push(session);
|
this.sessions.push(session);
|
||||||
|
|
||||||
const connectionId = uuidv4();
|
|
||||||
|
|
||||||
socket.on("error", (err) => {
|
socket.on("error", (err) => {
|
||||||
Main.logger.warn(`Error.`, err);
|
Main.logger.warn(`Error.`, err);
|
||||||
session.close();
|
session.close();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { toast, ToastIcon } from '../components/Toast';
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -31,27 +30,21 @@ if (TARGET === 'electron') {
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} else if (TARGET === 'webOS') {
|
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
|
||||||
try {
|
preloadData = {
|
||||||
preloadData = {
|
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
|
||||||
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
|
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
|
||||||
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
|
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
|
||||||
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
|
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
|
||||||
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
|
};
|
||||||
};
|
|
||||||
|
|
||||||
window.targetAPI = {
|
window.targetAPI = {
|
||||||
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
||||||
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
|
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
|
||||||
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
|
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
|
||||||
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
|
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
|
||||||
getDeviceInfo: () => preloadData.deviceInfo,
|
getDeviceInfo: () => preloadData.deviceInfo,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(`Main: preload ${JSON.stringify(err)}`);
|
|
||||||
toast(`Main: preload ${JSON.stringify(err)}`, ToastIcon.ERROR);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
|
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
|
||||||
|
|
|
@ -6,6 +6,7 @@ export {};
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
electronAPI: any;
|
electronAPI: any;
|
||||||
|
tizenOSAPI: any;
|
||||||
webOSAPI: any;
|
webOSAPI: any;
|
||||||
webOS: any;
|
webOS: any;
|
||||||
targetAPI: any;
|
targetAPI: any;
|
||||||
|
@ -32,7 +33,7 @@ if (TARGET === 'electron') {
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} else if (TARGET === 'webOS') {
|
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
|
||||||
preloadData = {
|
preloadData = {
|
||||||
sendPlaybackErrorCb: () => { console.error('Player: Callback "send_playback_error" not set'); },
|
sendPlaybackErrorCb: () => { console.error('Player: Callback "send_playback_error" not set'); },
|
||||||
sendPlaybackUpdateCb: () => { console.error('Player: Callback "send_playback_update" not set'); },
|
sendPlaybackUpdateCb: () => { console.error('Player: Callback "send_playback_update" not set'); },
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { BrowserWindow, ipcMain, IpcMainEvent, nativeImage, Tray, Menu, dialog } from 'electron';
|
import { BrowserWindow, ipcMain, IpcMainEvent, nativeImage, Tray, Menu, dialog } from 'electron';
|
||||||
import { PlaybackErrorMessage, PlaybackUpdateMessage, VolumeUpdateMessage } from 'common/Packets';
|
import { Opcode, PlaybackErrorMessage, PlaybackUpdateMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||||
import { DiscoveryService } from 'common/DiscoveryService';
|
import { DiscoveryService } from 'common/DiscoveryService';
|
||||||
import { TcpListenerService } from 'common/TcpListenerService';
|
import { TcpListenerService } from 'common/TcpListenerService';
|
||||||
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
||||||
import { NetworkService } from 'common/NetworkService';
|
import { NetworkService } from 'common/NetworkService';
|
||||||
import { Opcode } from 'common/FCastSession';
|
|
||||||
import { Updater } from './Updater';
|
import { Updater } from './Updater';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<div class="card-title-separator"></div>
|
<div class="card-title-separator"></div>
|
||||||
<div>
|
<div>
|
||||||
<div id="ips">IPs</div><br />
|
<div id="ips">IPs</div><br />
|
||||||
<div>Port<br>46899 (TCP), 46898 (WS)</div>
|
<div id="ip-ports">Port<br>46899 (TCP), 46898 (WS)</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
<div id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
||||||
<canvas id="qr-code"></canvas>
|
<canvas id="qr-code"></canvas>
|
||||||
|
|
|
@ -5,12 +5,11 @@
|
||||||
const Service = __non_webpack_require__('webos-service');
|
const Service = __non_webpack_require__('webos-service');
|
||||||
// const Service = require('webos-service');
|
// const Service = require('webos-service');
|
||||||
|
|
||||||
import { PlayMessage, PlaybackErrorMessage, PlaybackUpdateMessage, SeekMessage, SetSpeedMessage, SetVolumeMessage, VolumeUpdateMessage } from 'common/Packets';
|
import { Opcode, PlayMessage, PlaybackErrorMessage, PlaybackUpdateMessage, SeekMessage, SetSpeedMessage, SetVolumeMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||||
import { DiscoveryService } from 'common/DiscoveryService';
|
import { DiscoveryService } from 'common/DiscoveryService';
|
||||||
import { TcpListenerService } from 'common/TcpListenerService';
|
import { TcpListenerService } from 'common/TcpListenerService';
|
||||||
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
||||||
import { NetworkService } from 'common/NetworkService';
|
import { NetworkService } from 'common/NetworkService';
|
||||||
import { Opcode } from 'common/FCastSession';
|
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as log4js from "log4js";
|
import * as log4js from "log4js";
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<div class="card-title-separator"></div>
|
<div class="card-title-separator"></div>
|
||||||
<div>
|
<div>
|
||||||
<div id="ips">IPs</div><br />
|
<div id="ips">IPs</div><br />
|
||||||
<div>Port<br>46899 (TCP), 46898 (WS)</div>
|
<div id="ip-ports">Port<br>46899 (TCP), 46898 (WS)</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
<div id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
||||||
<canvas id="qr-code"></canvas>
|
<canvas id="qr-code"></canvas>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue