video player
This commit is contained in:
@@ -1,34 +1,73 @@
|
||||
import { schema, table, t } from "spacetimedb/server";
|
||||
|
||||
const spacetimedb = schema({
|
||||
person: table(
|
||||
videoState: table(
|
||||
{ public: true },
|
||||
{
|
||||
name: t.string(),
|
||||
id: t.u64().primaryKey(),
|
||||
url: t.string(),
|
||||
timePosition: t.f64(),
|
||||
isPlaying: t.bool(),
|
||||
lastUpdatedAt: t.timestamp(),
|
||||
},
|
||||
),
|
||||
});
|
||||
export default spacetimedb;
|
||||
|
||||
export const init = spacetimedb.init((_ctx) => {
|
||||
// Called when the module is initially published
|
||||
export const init = spacetimedb.init((ctx) => {
|
||||
// Insert initial video state row on first deploy
|
||||
ctx.db.videoState.insert({
|
||||
id: 1n,
|
||||
url: "https://cdn.cazzzer.com/LycoReco08.mkv",
|
||||
timePosition: 0.0,
|
||||
isPlaying: false,
|
||||
lastUpdatedAt: ctx.timestamp,
|
||||
});
|
||||
});
|
||||
|
||||
export const onConnect = spacetimedb.clientConnected((_ctx) => {
|
||||
// Called every time a new client connects
|
||||
export const onConnect = spacetimedb.clientConnected((_ctx) => {});
|
||||
export const onDisconnect = spacetimedb.clientDisconnected((_ctx) => {});
|
||||
|
||||
export const set_url = spacetimedb.reducer({ url: t.string() }, (ctx, { url }) => {
|
||||
const row = ctx.db.videoState.id.find(1n);
|
||||
if (!row) return;
|
||||
ctx.db.videoState.id.update({
|
||||
...row,
|
||||
url,
|
||||
timePosition: 0.0,
|
||||
isPlaying: false,
|
||||
lastUpdatedAt: ctx.timestamp,
|
||||
});
|
||||
});
|
||||
|
||||
export const onDisconnect = spacetimedb.clientDisconnected((_ctx) => {
|
||||
// Called every time a client disconnects
|
||||
export const play = spacetimedb.reducer({ time_position: t.f64() }, (ctx, { time_position }) => {
|
||||
const row = ctx.db.videoState.id.find(1n);
|
||||
if (!row) return;
|
||||
ctx.db.videoState.id.update({
|
||||
...row,
|
||||
timePosition: time_position,
|
||||
isPlaying: true,
|
||||
lastUpdatedAt: ctx.timestamp,
|
||||
});
|
||||
});
|
||||
|
||||
export const add = spacetimedb.reducer({ name: t.string() }, (ctx, { name }) => {
|
||||
ctx.db.person.insert({ name });
|
||||
export const pause = spacetimedb.reducer({ time_position: t.f64() }, (ctx, { time_position }) => {
|
||||
const row = ctx.db.videoState.id.find(1n);
|
||||
if (!row) return;
|
||||
ctx.db.videoState.id.update({
|
||||
...row,
|
||||
timePosition: time_position,
|
||||
isPlaying: false,
|
||||
lastUpdatedAt: ctx.timestamp,
|
||||
});
|
||||
});
|
||||
|
||||
export const sayHello = spacetimedb.reducer((ctx) => {
|
||||
for (const person of ctx.db.person.iter()) {
|
||||
console.info(`Hello, ${person.name}!`);
|
||||
}
|
||||
console.info("Hello, World!");
|
||||
export const seek = spacetimedb.reducer({ time_position: t.f64() }, (ctx, { time_position }) => {
|
||||
const row = ctx.db.videoState.id.find(1n);
|
||||
if (!row) return;
|
||||
ctx.db.videoState.id.update({
|
||||
...row,
|
||||
timePosition: time_position,
|
||||
lastUpdatedAt: ctx.timestamp,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user