# Environment ## Example Usage ```kotlin val source = GlobalAudioSource(Environment.ENGINE, "...", 0.8, true) val trigger = EnterRegionTrigger(source) Environment.addTrigger(trigger) ``` ```kotlin val source = LocalAudioSource(Environment.ENGINE, "...", 0.8, true, Triple(x, y, z)) val instance = source.createInstance(player) instance.volume = 0.0 // volume = instance.volume * source.volume instance.rate = 1.2 // rate = instance.rate * source.rate instance.play() instance.fadeTo(1.0, 2500) source.baseVolume = 0.5 source.x = 22.5 // ... instance.stop(2500) ``` ## Messages ### Registration After creating the websocket connection, the service will send a message containing the url the player may connect to. ```jsx= { "version": 1, "type": "environment.producer_registered", "payload": { "url": "e1ab91e7-6f14-4b6c-94f5-2366f3c1b26e" } } ``` ### Producer -> Service -> Consumer ```jsx= { "version": 1, "type": "environment.set_position", "payload": { "x": 0.0, "y": 64.0, "z": 0.0 } } ``` ```jsx= { "version": 1, "type": "environment.play_audio", // or "environment.update_audio" "payload": { "id": "e1ab91e7-6f14-4b6c-94f5-2366f3c1b26e", "key": "minecraft.blockparty.songs.make_a_cake", // only on play "volume": 0.8, "rate": 1.0, "loop": false, "loopFadeDuration": 0, // only on play when cross-fading "sprite": { // only on play "from": 69000, "to": 420000 }, "position": { "x": 10.5, "y": 64.0, "z": 120.0 }, "pannerAttrributes": { "distanceModel": "exponential", "refDistance": 5.0, "rolloffFactor": 2.5 } } } ``` ```jsx= { "version": 1, "type": "environment.fade_audio", "payload": { "target_volume": 0.0, "duration": 2500 } } ``` ```jsx= { "version": 1, "type": "environment.stop_audio", "payload": { "id": "e1ab91e7-6f14-4b6c-94f5-2366f3c1b26e", "fade_duration": 2500 // only required when fading is desired } } ``` ### Service -> Producer ```jsx= { "version": 1, "type": "environment.consumer_connected", "payload": {} } ``` ```jsx= { "version": 1, "type": "environment.consumer_disconnected", "payload": {} } ``` ### Consumer -> Service -> Producer ```jsx= { "version": 1, "type": "environment.audio_started", "payload": { "id": "e1ab91e7-6f14-4b6c-94f5-2366f3c1b26e" } } ``` ```jsx= { "version": 1, "type": "environment.audio_stopped", "payload": { "id": "e1ab91e7-6f14-4b6c-94f5-2366f3c1b26e" } } ```