Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jul 2, 2022
1 parent caa14f9 commit 0978b1b
Show file tree
Hide file tree
Showing 27 changed files with 7,524 additions and 1,142 deletions.
7,759 changes: 6,765 additions & 994 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@rollup/plugin-commonjs": "^21.0.2",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"decentraland-ecs": "^6.11.1",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.4.0"
Expand All @@ -39,5 +38,11 @@
"node": ">=16.0.0",
"npm": ">=8.0.0",
"yarn": "please use npm"
},
"dependencies": {
"@dcl/ecs-scene-utils": "^1.7.5",
"@dcl/npc-scene-utils": "^1.4.0",
"decentraland": "^3.11.0",
"decentraland-ecs": "^6.11.2"
}
}
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
output: [
{
file: packageJson.main,
sourcemap: true,
format: 'amd',
amd: {
id: packageJson.name
Expand Down
34 changes: 31 additions & 3 deletions src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import * as utils from '@dcl/ecs-scene-utils'
import { isPreviewMode } from "@decentraland/EnvironmentAPI";
import { getUserData } from "@decentraland/Identity";
import { getParcel } from "@decentraland/ParcelIdentity";
import { signedFetch } from "@decentraland/SignedFetch";
import { user } from './helpers/user';

export function startAnalytics() {

export function initAnalytics() {
onPlayerConnectedObservable.add((player) => {
recordEvent("player_connected", player);
// log("player entered: ", player.userId)
if(player.userId == user){
let delay = new Entity()
delay.addComponent(new utils.Delay(5000,()=>{
recordEvent("player_connected", player);
engine.removeEntity(delay)
}))
engine.addEntity(delay)
}
});

onPlayerDisconnectedObservable.add((player) => {
recordEvent("player_disconnected", player);
// log("player left: ", player.userId)
if(player.userId == user){
recordEvent("player_disconnected", player);
}
});

onEnterSceneObservable.add((player) => {
log("player entered scene: ", player.userId);
if(player.userId == user){
recordEvent("player_entered_scene", player);
}
});

// shows player left scene
onLeaveSceneObservable.add((player) => {
// log("player left scene: ", player.userId)
if(player.userId == user){
recordEvent("player_left_scene", player);
}
});

// // idle
Expand All @@ -30,8 +50,16 @@ export function startAnalytics() {

// player animation
onPlayerExpressionObservable.add(({ expressionId }) => {
// log("Expression: ", expressionId)

recordEvent("player_expression", expressionId);
});

// // fetch player data
// getUserData().then((data) => {
// // log(data)
// recordEvent("user_data", data)
// })
}

export async function recordEvent(eventType: any, metadata: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/audio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const createAudioStream = (audioStreams: Array<any>) => {};

export const updateAudioStream = (audioStreams: Array<any>, property: string) => {};
export const updateAudioStream = (audioStreams: Array<any>, property: string, id: string) => {};

export const removeAudioStream = (audioStreams: Array<any>, property: string) => {};
export const removeAudioStream = (audioStreams: Array<any>, property: string, id: string) => {};
11 changes: 11 additions & 0 deletions src/classes/StoredEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TImage } from "../types/Image";

export class StoredEntity extends Entity {
data: TImage;
material?: Material;
basicMaterial?: BasicMaterial;
texture: Texture;
constructor(name: string) {
super(name);
}
}
280 changes: 280 additions & 0 deletions src/classes/StoredVideoScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
import { EVideoSourceTypes, TVideoScreen } from "../types/VideoScreen";

export class StoredVideoScreen{
timer = 0
live = false
playing = false
started = false
texture: VideoTexture
material: Material
data:TVideoScreen
playlist?:VideoPlaylist

constructor(data:TVideoScreen){
this.data = data
log('video system data is', this.data)
this.texture = new VideoTexture(new VideoClip(""))
this.material = new Material()
if(this.data.offType == EVideoSourceTypes.PLAYLIST){
this.playlist = new VideoPlaylist(this, this.material, this.data.playlist!, this.data.noLoop ? this.data.noLoop : undefined)
}
}

update(dt:number){
if(this.started){
if(this.timer > 0){
this.timer -= dt
}
else{
this.timer = 10
try{
executeTask((async()=>{
log('trying to fetch video link')
let res = await fetch(this.data.liveLink!)
if(res.status < 400){
this.playing = false
log("Currently Live. -> ", this.data.liveLink!)
this.goOnline()
}
else{
// log('not live')
this.goOffline()
}
}))
}
catch(e){
log("video no live")
}
}
}
}

setVolume(vol:number){
this.data.volume = vol
// this.texture.volume = vol
this.playlist!.setVolume(vol)
}

startLive(){
if(this.data.type != EVideoSourceTypes.LIVE && !this.started){
this.data.type = EVideoSourceTypes.LIVE
this.start()
}
}

goOnline(){
if(!this.live){
// log("Intializing live screen.")
log('online')
this.live = true;
let liveFeed = new VideoClip(this.data.liveLink!);

log('live feed is ', + this.data.liveLink!)

if(this.data.offType == EVideoSourceTypes.PLAYLIST){
if(this.playlist!.playing){
this.playlist!.reset()
}
}

this.texture.playing = false
this.texture = new VideoTexture(liveFeed);
this.texture.playing = true
this.texture.volume = this.data.volume;

this.material.albedoTexture = this.texture;
this.material.emissiveTexture = this.texture;
this.material.emissiveIntensity = this.data.emission
this.material.emissiveColor = Color3.White()
this.material.roughness = 1
}
}


goOffline(){
if(!this.playing) {
this.live = false;
this.playing = true
this.texture.playing = false

if(this.data.offType == EVideoSourceTypes.PLAYLIST){
log('video system is offline, we need to play the playlist')
this.playlist!.start()
}
else{
this.texture = new VideoTexture(new VideoClip(""))
this.playing = false
}

this.texture.volume = this.data.volume;
this.material.albedoTexture = this.texture;
this.material.emissiveTexture = this.texture;

this.texture.playing = true
this.texture.loop = true
log('offline')
}
}

stop(){

log('stopping video system')
log(this.data.type)

switch(this.data.type){
case EVideoSourceTypes.LIVE:
this.texture.playing = false
this.live = false
this.playing = false
this.started = false
engine.removeSystem(this)
break;
}

if(this.playlist){
this.playlist.stop()
}
}

start(vol?:number){
log('starting live system')
this.started = true
if(vol){
this.data.volume = vol
}
if(this.data.type == EVideoSourceTypes.LIVE){
engine.addSystem(this)
}
else{
log('need to start video system')
this.playlist!.setVolume(this.data.volume ? this.data.volume : 1)
this.playlist!.start()
}
}

off(){
log('we are here, lets turn off')
this.texture = new VideoTexture(new VideoClip(""))
this.material.albedoTexture = this.texture
this.material.emissiveTexture = this.texture
// if(this.data.offType == Types.IMAGE){
// log('need to display an image')
// this.material.albedoTexture = new Texture(this.data.offImage ? this.data.offImage : "")
// this.material.emissiveTexture = new Texture(this.data.offImage ? this.data.offImage : "")
// }
}
}

class VideoPlaylist{

index = -1
timer = 0
playing = false

parentSystem:StoredVideoScreen
material: Material
texture:VideoTexture
links: any
exists = false
volume: number = 0
noLoop = false

constructor(system:StoredVideoScreen, mat:Material, links:string[], noLoop?:boolean){
this.parentSystem = system
this.material = mat
this.links = links
this.volume = system.data.volume
this.texture = new VideoTexture(new VideoClip(this.links[0]))
this.texture.volume = this.volume
if(noLoop){
this.noLoop = noLoop
}
}

update(dt:number){
if(this.playing){
if(this.timer > 0){
this.timer -= dt
}
else{
log('checking for video')
this.index++

if(this.noLoop){
if(this.index == 0){
this.timer = 500
this.playVideo(this.index)
}
else{
log('don playing video, switch to off mode')
this.stop()
this.parentSystem.off()
}
}
else{
if(this.index >= this.links.length){
log('we have reached the end of the video playlist; restart')
this.index = 0
}
this.timer = 500
this.playVideo(this.index)
}
}
}
}

setVolume(vol:number){
this.volume = vol
this.texture.volume = vol
}

stop(){
this.playing = false
this.texture.playing = false
this.parentSystem.playing = false
engine.removeSystem(this)
}

reset(){
this.stop()
this.timer = 0
this.index = -1
}

start(){
this.reset()
this.playing = true
this.parentSystem.playing = true
engine.addSystem(this)


onVideoEvent.add((data) => {
if(data.videoStatus == 4){
this.timer = data.totalVideoLength
onVideoEvent.clear()
}
})
}

playVideo(index: number){
log("playing new video in playlist")
this.texture.playing = false
this.texture = new VideoTexture(new VideoClip(this.links[this.index]))
this.material.albedoTexture = this.texture
this.material.emissiveTexture = this.texture

this.material.emissiveIntensity = this.parentSystem.data.emission
this.material.emissiveColor = Color3.White()
this.material.roughness = 1
this.texture.playing = true
this.texture.volume = this.volume

onVideoEvent.add((data) => {
if(data.videoStatus == 4){
this.timer = data.totalVideoLength
onVideoEvent.clear()
}
})
}

}

0 comments on commit 0978b1b

Please sign in to comment.