Skip to content
Draft
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
},
"dependencies": {
"@koa/cors": "3",
"apollo-server": "^2.19.0",
"beamcoder": "^0.6.10",
"graphql": "^15.4.0",
"koa": "^2.13.0",
"macadam": "^2.0.14",
"naudiodon": "^2.3.0",
Expand Down
58 changes: 58 additions & 0 deletions src/GraphQL/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { gql } from 'apollo-server'

export default gql`
"""
A channel is an individual composition of various sources, layed out on different layers
"""
type Channel {
id: ID!
number: Int!
videoFormat: VideoFormat!
layers: [Layer!]!
}

"""
A producer is a media stream source that will produce media when not paused
"""
type Producer {
sourceId: ID!
format: VideoFormat!
paused: Boolean!
}

type Mixer {
dupa: String
}

"""
A layer is a part of the channel, that can have a foreground and a background. The background can play
automatically, if the foreground is empty.
"""
type Layer {
foreground: Producer
background: Producer
autoPlay: Boolean!
mixer: Mixer!
}

"""
A video format is a specification of the audio & video format that will be produced by a Channel
"""
type VideoFormat {
name: String!
fields: Int!
width: Int!
height: Int!
squareWidth: Int!
squareHeight: Int!
timescale: Float!
duration: Int!
audioSampleRate: Int!
audioChannels: Int!
}

type Query {
channels: [Channel]!
videoFormats: [VideoFormat]!
}
`
33 changes: 33 additions & 0 deletions src/GraphQL/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ApolloServer } from 'apollo-server'
import { Channel } from '../channel'
import { VideoFormat, VideoFormats } from '../config'
import typeDefs from './schema'

const model: {
channels: Channel[]
videoFormats: VideoFormat[]
} = {
channels: [],
videoFormats: []
}

const resolvers = {
Query: {
channels: () => [], // (parent, args, context, info) => [],
videoFormats: () => [] // (parent, args, context, info) => []
}
}

const server = new ApolloServer({ typeDefs, resolvers })

export async function start(channels: Channel[]): Promise<string> {
model.channels = channels
model.videoFormats = new VideoFormats().list()
const { url } = await server.listen()
return `🚀 GraphQL Server ready at ${url}`
}

export async function stop(): Promise<string> {
await server.stop()
return `GraphQL Server shut down.`
}
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class VideoFormats {
if (!format) throw new Error(`Video format ${name} not found`)
return format
}

list(): VideoFormat[] {
return Array.from(this.formats.values())
}
}

export interface DeviceConfig {
Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import { clContext as nodenCLContext } from 'nodencl'
import { ClProcessJobs } from './clJobQueue'
import { start, processCommand } from './AMCP/server'
import { start as amcpStart, processCommand } from './AMCP/server'
import { start as graphQLStart } from './GraphQL/server'
import { Commands } from './AMCP/commands'
import { Channel } from './channel'
import { BasicCmds } from './AMCP/basicCmds'
Expand Down Expand Up @@ -102,16 +103,17 @@ rl.on('SIGINT', () => {

console.log('\nWelcome to Phaneron\n')

const channels: Channel[] = []

const commands: Commands = new Commands()
initialiseOpenCL()
.then(async (clContext) => {
const config = new Config()
const consReg = new ConsumerRegistry(clContext)
const prodReg = new ProducerRegistry(clContext)

const clProcessJobs = new ClProcessJobs(clContext)
const clJobs = clProcessJobs.getJobs()
const config = new Config()
const channels: Channel[] = []

config.consumers.forEach((consumerConfig, i) => {
try {
Expand All @@ -131,7 +133,9 @@ initialiseOpenCL()

// setInterval(() => clContext.logBuffers(), 2000)
})
.then(() => start(commands))
.then(() => graphQLStart(channels))
.then(console.log, console.error)
.then(() => amcpStart(commands))
.then(console.log, console.error)
.then(() => rl.prompt())
.catch(console.error)
Loading