mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +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 log4js from "modules/log4js";
|
||||
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';
|
||||
const logger = log4js.getLogger();
|
||||
|
||||
|
@ -12,23 +12,6 @@ enum SessionState {
|
|||
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 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 {
|
||||
constructor(
|
||||
public container: string,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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 { Main, errorHandler } from 'src/Main';
|
||||
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 { WebSocket, WebSocketServer } from 'modules/ws';
|
||||
import { Main, errorHandler } from 'src/Main';
|
||||
|
@ -52,11 +53,10 @@ export class WebSocketListenerService {
|
|||
Main.logger.info('New WebSocket connection');
|
||||
|
||||
const session = new FCastSession(socket, (data) => socket.send(data));
|
||||
const connectionId = uuidv4();
|
||||
session.bindEvents(this.emitter);
|
||||
this.sessions.push(session);
|
||||
|
||||
const connectionId = uuidv4();
|
||||
|
||||
socket.on("error", (err) => {
|
||||
Main.logger.warn(`Error.`, err);
|
||||
session.close();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { toast, ToastIcon } from '../components/Toast';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
@ -31,27 +30,21 @@ if (TARGET === 'electron') {
|
|||
});
|
||||
|
||||
// @ts-ignore
|
||||
} else if (TARGET === 'webOS') {
|
||||
try {
|
||||
preloadData = {
|
||||
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
|
||||
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
|
||||
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
|
||||
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
|
||||
};
|
||||
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
|
||||
preloadData = {
|
||||
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
|
||||
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
|
||||
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
|
||||
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
|
||||
};
|
||||
|
||||
window.targetAPI = {
|
||||
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
||||
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
|
||||
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
|
||||
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
|
||||
getDeviceInfo: () => preloadData.deviceInfo,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Main: preload ${JSON.stringify(err)}`);
|
||||
toast(`Main: preload ${JSON.stringify(err)}`, ToastIcon.ERROR);
|
||||
}
|
||||
window.targetAPI = {
|
||||
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
||||
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
|
||||
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
|
||||
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
|
||||
getDeviceInfo: () => preloadData.deviceInfo,
|
||||
};
|
||||
} else {
|
||||
// @ts-ignore
|
||||
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
|
||||
|
|
|
@ -6,6 +6,7 @@ export {};
|
|||
declare global {
|
||||
interface Window {
|
||||
electronAPI: any;
|
||||
tizenOSAPI: any;
|
||||
webOSAPI: any;
|
||||
webOS: any;
|
||||
targetAPI: any;
|
||||
|
@ -32,7 +33,7 @@ if (TARGET === 'electron') {
|
|||
});
|
||||
|
||||
// @ts-ignore
|
||||
} else if (TARGET === 'webOS') {
|
||||
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
|
||||
preloadData = {
|
||||
sendPlaybackErrorCb: () => { console.error('Player: Callback "send_playback_error" 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 { PlaybackErrorMessage, PlaybackUpdateMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||
import { Opcode, PlaybackErrorMessage, PlaybackUpdateMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||
import { DiscoveryService } from 'common/DiscoveryService';
|
||||
import { TcpListenerService } from 'common/TcpListenerService';
|
||||
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
||||
import { NetworkService } from 'common/NetworkService';
|
||||
import { Opcode } from 'common/FCastSession';
|
||||
import { Updater } from './Updater';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<div class="card-title-separator"></div>
|
||||
<div>
|
||||
<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 id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
||||
<canvas id="qr-code"></canvas>
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
const Service = __non_webpack_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 { TcpListenerService } from 'common/TcpListenerService';
|
||||
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
||||
import { NetworkService } from 'common/NetworkService';
|
||||
import { Opcode } from 'common/FCastSession';
|
||||
import * as os from 'os';
|
||||
import * as log4js from "log4js";
|
||||
import { EventEmitter } from 'events';
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div class="card-title-separator"></div>
|
||||
<div>
|
||||
<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 id="automatic-discovery" class="non-selectable">Automatic discovery is available via mDNS</div>
|
||||
<canvas id="qr-code"></canvas>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue