Getting Photon is not defined

Hey there I am trying to use photon in babylon but getting this error, that Photon is not defined.

here is my code snippet

export class PhotonManager extends BABYLON.ScriptComponent {
        // Example: private helloWorld:string = "Hello World";

        private client:Photon.LoadBalancing.LoadBalancingClient;
        protected awake(): void {
            /* Init component function */
        }

        protected ready(): void {
            this.InitPhoton();
        }

        private InitPhoton(){
            this.client = new Photon.LoadBalancing.LoadBalancingClient(Photon.ConnectionProtocol.Ws, APPID, "0");
            this.setAllCallBacks();
            let connectBoolean = this.client.connect();
            console.log("Log Of Connet :- " + connectBoolean);
        }

        private setAllCallBacks(){
            this.client.onStateChange = this.stateChanged;
            this.client.onActorJoin = this.actorJoined;
            this.client.onActorLeave = this.actorLeft;
            this.client.onJoinRoom = this.joinedRoom;
        }

        private stateChanged(stateNumber: number): void {
            console.log("State Changed :- " + stateNumber);
        } 
        
        private actorJoined (actor: Photon.LoadBalancing.Actor): void{
            console.log("Actor Joined :- " + actor.name);
        }

        private actorLeft (actor: Photon.LoadBalancing.Actor, cleanUp: boolean): void{
            console.log("Actor Left :- " + actor.name + " cleanUp :- " + cleanUp);
        }

        private joinedRoom(createdByMe: boolean): void{
            console.log("Joined Room :- " + createdByMe);
        }
    }

Hello @Shubham , how are you doing?

Can you provide a little more information about you project setup? Are you using webpack? Which version of babylon and proton are you using?

Actually the issue is solved, the issue was the photon was not referenced in the engine.html file

    <script type="text/javascript" src="###SCRIPT###/photon.js"></script>

Just added this line in the engine.html file in side the body

1 Like