define(["connectionManager","playbackManager","events","inputManager","focusManager","embyRouter"],function(connectionManager,playbackManager,events,inputManager,focusManager,embyRouter){"use strict";functionnotifyApp(){inputManager.notify()}functiondisplayMessage(cmd){varargs=cmd.Arguments;args.TimeoutMs?require(["toast"],function(toast){toast({title:args.Header,text:args.Text})}):require(["alert"],function(alert){alert({title:args.Header,text:args.Text})})}functiondisplayContent(cmd,apiClient){apiClient.getItem(apiClient.getCurrentUserId(),cmd.Arguments.ItemId).then(function(item){embyRouter.showItem(item)})}functionprocessGeneralCommand(cmd,apiClient){switch(cmd.Name){case"Select":returnvoidinputManager.trigger("select");case"Back":returnvoidinputManager.trigger("back");case"MoveUp":returnvoidinputManager.trigger("up");case"MoveDown":returnvoidinputManager.trigger("down");case"MoveLeft":returnvoidinputManager.trigger("left");case"MoveRight":returnvoidinputManager.trigger("right");case"PageUp":returnvoidinputManager.trigger("pageup");case"PageDown":returnvoidinputManager.trigger("pagedown");case"SetRepeatMode":playbackManager.setRepeatMode(cmd.Arguments.RepeatMode);break;case"VolumeUp":returnvoidinputManager.trigger("volumeup");case"VolumeDown":returnvoidinputManager.trigger("volumedown");case"ChannelUp":returnvoidinputManager.trigger("channelup");case"ChannelDown":returnvoidinputManager.trigger("channeldown");case"Mute":returnvoidinputManager.trigger("mute");case"Unmute":returnvoidinputManager.trigger("unmute");case"ToggleMute":returnvoidinputManager.trigger("togglemute");case"SetVolume":notifyApp(),playbackManager.setVolume(cmd.Arguments.Volume);break;case"SetAudioStreamIndex":notifyApp(),playbackManager.setAudioStreamIndex(parseInt(cmd.Arguments.Index));break;case"SetSubtitleStreamIndex":notifyApp(),playbackManager.setSubtitleStreamIndex(parseInt(cmd.Arguments.Index));break;case"ToggleFullscreen":returnvoidinputManager.trigger("togglefullscreen");case"GoHome":returnvoidinputManager.trigger("home");case"GoToSettings":returnvoidinputManager.trigger("settings");case"DisplayContent":displayContent(cmd,apiClient);break;case"GoToSearch":returnvoidinputManager.trigger("search");case"DisplayMessage":displayMessage(cmd);break;case"ToggleOsd":break;case"ToggleContextMenu":break;case"TakeScreenShot":break;case"SendKey":break;case"SendString":focusManager.sendText(cmd.Arguments.String);break;default:console.log("processGeneralCommand does not recognize: "+cmd.Name)}notifyApp()}functiononWebSocketMessageReceived(e,msg){varapiClient=this;if("Play"===msg.MessageType){notifyApp();varserverId=apiClient.serverInfo().Id;"PlayNext"===msg.Data.PlayCommand?playbackManager.queueNext({ids:msg.Data.ItemIds,serverId:serverId}):"PlayLast"===msg.Data.PlayCommand?playbackManager.queue({ids:msg.Data.ItemIds,serverId:serverId}):playbackManager.play({ids:msg.Data.ItemIds,startPositionTicks:msg.Data.StartPositionTicks,serverId:serverId})}elseif("Playstate"===msg.MessageType)"Stop"===msg.Data.Command?inputManager.trigger("stop"):"Pause"===msg.Data.Command?inputManager.trigger("pause"):"Unpause"===msg.Data.Command?inputManager.trigger("play"):"Seek"===msg.Data.Command?playbackManager.seek(msg.Data.SeekPositionTicks):"NextTrack"===msg.Data.Command?inputManager.trigger("next"):"PreviousTrack"===msg.Data.Command?inputManager.trigger("previous"):notifyApp();elseif("GeneralCommand"===msg.MessageType){varcmd=msg.Data;processGeneralCommand(cmd,apiClient)}}functionbindEvents(apiClient){events.off(apiClient,"websocketmessage",onWebSocketMessageReceived),events.on(apiClient,"websocketmessage",onWebSocketMessageReceived)}connectionManager.getApiClients().forEach(bindEvents),events.on(connectionManager,"apiclientcreated",function(e,newApiClient){bindEvents(newApiClient)})});