(function() { var messageChannel = 'MESSAGE_CHANNEL_GATE_GAME'; var SOUND_URL = 'https://hifi-content.s3.amazonaws.com/wadewatts/coin%20noise.wav?v=' + Date.now(); var entityID; var sound; function sendMessage(message) { message.entityID = entityID; Messages.sendMessage( messageChannel, JSON.stringify(message) ); } function onReceivedMessage(channel, message, senderID) { try { var data = JSON.parse(message); } catch (e) { print('Error parsing message: ' + message); return; } // print('data: ' + JSON.stringify(data)); // switch (data.type) { // case 'HELLO': // print(data.payload); // break; // } } return { preload: function(id) { entityID = id; Messages.subscribe(messageChannel); Messages.messageReceived.connect(null, onReceivedMessage); sound = SoundCache.getSound(SOUND_URL); print('Hello Main Gate'); }, unload: function(id) { Messages.unsubscribe(messageChannel); Messages.messageReceived.disconnect(null, onReceivedMessage); }, enterEntity: function(id) { var position = Entities.getEntityProperties(entityID, 'position').position; var audioProperties = { volume: 0.1, position: position }; Audio.playSound(sound, audioProperties); sendMessage({ type: 'PASS', name: MyAvatar.displayName }); } }; })