aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Plugin.cs
blob: 3137978feb9896ff1b3aa6d3d5761c91c35e909e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Net;
using MediaBrowser.Api.HttpHandlers;

namespace MediaBrowser.Api
{
    public class Plugin : BasePlugin<BasePluginConfiguration>
    {
        List<IDisposable> HttpHandlers = new List<IDisposable>();

        protected override void InitInternal()
        {
            HttpHandlers.Add(Kernel.Instance.HttpServer.Where(ctx => ctx.Request.Url.LocalPath.EndsWith("mediabrowser/api/item")).Subscribe(ctx => ctx.Respond(new ItemHandler(ctx))));
            HttpHandlers.Add(Kernel.Instance.HttpServer.Where(ctx => ctx.Request.Url.LocalPath.EndsWith("mediabrowser/api/image")).Subscribe(ctx => ctx.Respond(new ItemHandler(ctx))));
        }

        public override void Dispose()
        {
            base.Dispose();

            foreach (var handler in HttpHandlers)
            {
                handler.Dispose();
            }

            HttpHandlers.Clear();
        }
    }
}