• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript server.api类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@akala/server.api的典型用法代码示例。如果您正苦于以下问题:TypeScript api类的具体用法?TypeScript api怎么用?TypeScript api使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了api类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: async

akala.injectWithNameAsync(['$agent.api/lifttt'], async (lifttt: Client<Connection>) =>
{
    var cl = akala.api.jsonrpcws(channel).createClient(lifttt, {
        executeAction: function (action)
        {
            switch (action.name)
            {
                case 'log':
                    console.log(action.params.message);
                    break;
            }
        },

        executeCondition: function (condition)
        {

        },
        stopTrigger: function (trigger)
        {

        },
        executeTrigger: async function (trigger)
        {
            return null;
        }
    });
    var server = cl.$proxy();
    await server.registerChannel({ name: 'console', view: '@domojs/lifttt/fs.html', icon: 'terminal' });
    await server.registerAction({ name: 'log', fields: [{ name: 'message', type: 'string' }] })
})
开发者ID:domojs,项目名称:lifttt,代码行数:30,代码来源:console.ts


示例2: async

akala.injectWithNameAsync(['$agent.api/lifttt'], async (lifttt: Client<Connection>) =>
{
    var registeredTriggers: { [triggerId: string]: fs.FSWatcher } = {};

    var writeFile = promisify(fs.writeFile);

    var cl = akala.api.jsonrpcws(channel).createClient(lifttt, {
        executeAction: function (action)
        {
            switch (action.name)
            {
                case 'write':
                    return writeFile(action.params.file as string, action.params.data);
            }
        },
        executeCondition: function (condition)
        {

        },
        stopTrigger: async function (trigger)
        {
            if (registeredTriggers[trigger.id])
            {
                registeredTriggers[trigger.id].close();
                delete registeredTriggers[trigger.id];
            }
        },
        executeTrigger: async function (trigger)
        {
            switch (trigger.name)
            {
                case 'watch':
                    var stat = await promisify(fs.stat)(trigger.params['path'] as string);
                    if (stat.isDirectory() || stat.isFile())
                    {
                        var id = uuid();
                        var watcher = fs.watch(trigger.params['path'] as string, function (event, fileName)
                        {
                            if (!trigger.params['event'] || trigger.params['event'] == event)
                                server.trigger({ id: id, data: { path: fileName, mtime: new Date().toJSON() } });
                        });
                        registeredTriggers[id] = watcher;
                    }
                    break;
            }
            return null;
        }
    });
    var server = cl.$proxy();
    await server.registerChannel({ name: 'fs', view: '@domojs/lifttt/fs.html', icon: 'file' });
    await server.registerTrigger({ name: 'watch', icon: 'file-medical-alt', view: '@domojs/lifttt/fs-watch.html', fields: [{ name: 'path', type: 'string' }] })
    await server.registerAction({ name: 'write', icon: 'file-medical-alt', view: '@domojs/lifttt/fs-watch.html', fields: [{ name: 'path', type: 'string' }, { name: 'data', type: 'string' }] })
})
开发者ID:domojs,项目名称:lifttt,代码行数:53,代码来源:fs.ts


示例3: function

akala.injectWithNameAsync(['$agent.api/media'], function (client: Client<Connection>)
{
    var s = akala.api.jsonrpcws(media.scrapper).createClient(client, {
        scrap: function (media: media.TVShow | media.Movie)
        {
            switch (media.subType)
            {
                case 'movie':
                    fs.writeFile(media.path + '.nfo', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                    <movie>
                        <title>${media.name}</title>
                        <sorttitle>${media.displayName}</sorttitle>
                        <thumb aspect="poster">${media.cover}</thumb>
                    </movie>`, 'utf8', function (err)
                        {
                            if (err)
                                akala.logger.error(err);
                        });

                    break;
                case 'tvshow':

                    fs.writeFile(media.path + '.nfo', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                    <episodedetails>
                        <title>${media.name}</title>
                        <sorttitle>${media.displayName}</sorttitle>
                        <thumb aspect="poster">${media.cover}</thumb>
                        <season>${media.season}</season>
                        <episode>${media.episode}</episode>
                    </episodedetails>`, 'utf8', function (err)
                        {
                            if (err)
                                akala.logger.error(err);
                        });
                    break;
            }

            return media;

        }
    }).$proxy();
    s.register({ type: 'video', priority: 20 });
});
开发者ID:domojs,项目名称:domojs-media-kodi,代码行数:43,代码来源:scrapper.ts


示例4: async

akala.injectWithNameAsync(['$agent.api/lifttt'], async (lifttt: Client<Connection>) =>
{
    var cl = akala.api.jsonrpcws(channel).createClient(lifttt, {
        executeAction: function (action)
        {
            switch (action.name)
            {
                case 'call':
                    var http: akala.Http = akala.resolve('$http');
                    return http.call(action.params as any).then((response) => { return; });
                    break;
            }
        },

        executeCondition: function (condition)
        {

        },
        stopTrigger: function (trigger)
        {

        },
        executeTrigger: async function (trigger)
        {
            return null;
        }
    });
    var server = cl.$proxy();
    await server.registerChannel({ name: 'http', icon: 'html5' });
    await server.registerAction({
        name: 'call', fields: [
            { name: 'url', type: 'string' },
            { name: 'method', type: 'string' },
            { name: 'queryString', type: 'string' },
            { name: 'body', type: 'string' },
            { name: 'headers', type: 'string' },
            { name: 'contentType', type: 'string' },
            { name: 'type', type: 'string' },
        ]
    })
})
开发者ID:domojs,项目名称:lifttt,代码行数:41,代码来源:http.ts


示例5: function

akala.injectWithNameAsync(['$agent.api/zeroconf', '$agent.api/media'], function (zeroconfClient, mediaClient)
{
    var kodis: { [id: string]: PromiseLike<{ Player: KodiPlayerProxy, Playlist: KodiPlaylistProxy }> } = {};
    var timers: { [id: string]: NodeJS.Timer } = {};
    function startTimer(id: string)
    {
        if (timers[id])
            return;
        timers[id] = setInterval(function ()
        {
            client.status({ target: id });
        }, 1000)
    }

    function stopTimer(id: string)
    {
        if (timers[id])
            clearInterval(timers[id]);
        timers[id] = null;
    }


    var client = akala.api.jsonrpcws(media.player).createClient(mediaClient, {
        mute(p)
        {

        },
        async status(p)
        {
            var kodi = await kodis[p.identity];
            var players = await kodi.Player.GetActivePlayers(null)
            if (players.length > 0)
            {
                debug.verbose(players);
                var player = await kodi.Player.GetProperties({ playerid: players[0].playerid, properties: ['position', 'percentage', 'repeat', 'canseek', 'time', 'totaltime', 'speed'] });
                debug.verbose(player);
                return client.$proxy().status({
                    identity: p.identity,
                    state: player.speed ? 'playing' : 'paused',
                    position: player.percentage / 100,
                    time: player.time.seconds + 60 * player.time.minutes + 3600 * player.time.hours,
                    length: player.totaltime.seconds + 60 * player.totaltime.minutes + 3600 * player.totaltime.hours,
                });
            }
            else
            {
                client.$proxy().status({
                    identity: p.identity,
                    state: 'stopped',
                });
                stopTimer(p.identity);
            }

        },
        async playlist(p: { target: string })
        {
            var kodi = await kodis[p.target];
            var players = await kodi.Player.GetActivePlayers(null);
            if (players.length > 0)
            {
                debug.log(players);
                var properties = await kodi.Player.GetProperties({ playerid: players[0].playerid, properties: ['playlistid', 'speed'] });
                if (typeof (properties.playlistid) != 'undefined')
                {
                    var item: { item: Item & { current?: boolean } } = await kodi.Player.GetItem({ playerid: players[0].playerid, properties: ['title', 'artist', 'albumartist', 'fanart', 'plot', 'season', 'episode', 'thumbnail', 'file', 'art'] })
                    {
                        akala.extend(item.item, { current: true });
                        var playlist = await kodi.Playlist.GetItems({ playlistid: properties.playlistid, properties: ['title', 'artist', 'albumartist', 'fanart', 'plot', 'season', 'episode', 'thumbnail', 'file', 'art'] })
                        debug.verbose(playlist);
                        if (playlist && !playlist.items)
                            playlist.items = [item.item]
                        else
                            playlist.items.unshift(item.item);
                        debug.verbose(playlist.items);
                        if (properties.speed > 0)
                            startTimer(p.target);
                        if (playlist && playlist.items)
                            client.$proxy().playlist({
                                identity: p.target, playlist: akala.map(playlist.items, function (media: Item & { current?: boolean })
                                {
                                    return { url: media.file.replace(/smb:\/\//, 'file://///'), current: media.current };
                                })
                            });
                    }
                }
            }
        },
        async next(p)
        {
            var kodi = await kodis[p.target];
            var players = await kodi.Player.GetActivePlayers(null);
            if (players.length > 0)
            {
                debug.verbose(players);
                kodi.Player.GoNext({ playerid: players[0].playerid })
            }
        },
        async previous(p)
        {
            var kodi = await kodis[p.target];
//.........这里部分代码省略.........
开发者ID:domojs,项目名称:domojs-media-kodi,代码行数:101,代码来源:player.ts


示例6: function

akala.injectWithNameAsync(['$agent.api/lifttt', '$worker'], function (client: Client<Connection>, worker: EventEmitter)
{
    var recipes: { [name: string]: Recipe & { triggerId?: string } } = {};
    var triggerMap: { [id: string]: Recipe } = {};
    var init: boolean;
    var recipeFile = path.resolve(process.cwd(), '../../../recipes.json');
    exists(recipeFile).then(async (exists) =>
    {
        if (exists)
        {
            logger.verbose(recipeFile + ' exists')
            var recipeStore: { [id: string]: Recipe } = JSON.parse(await readFile(recipeFile, { encoding: 'utf8' }));
            logger.verbose(recipeStore);
            init = true;
            worker.on('ready', function ()
            {
                setTimeout(function ()
                {

                    logger.verbose('initializing recipes')
                    akala.eachAsync(recipeStore, async function (recipe, name, next)
                    {
                        delete recipe.triggerId;
                        try
                        {
                            await cl.insert(recipe, init);
                        }
                        catch
                        {
                            setTimeout(cl.insert, 60000, recipe, true);
                        }
                        next();
                    }, function ()
                        {
                            init = false;
                        });
                }, 30000)
            })
        }
        else
            logger.info(recipeFile + ' does not exist');
    });

    var server = akala.api.jsonrpcws(organizer).createServerProxy(client);
    var cl = akala.api.jsonrpcws(organizer).createClient(client, {
        trigger: async (param) =>
        {
            var triggerData = akala.extend({ $date: new Date() }, param.data);
            var conditionsData: PayloadDataType = null;
            akala.logger.verbose(`trigger ${param.id} received`);
            if (triggerMap[param.id].condition)
            {
                var result = interpolate(triggerMap[param.id].condition.params, triggerData);
                conditionsData = await server.executeCondition({ name: triggerMap[param.id].condition.name, channel: triggerMap[param.id].condition.channel, params: { $triggerData: triggerData, ...result } });
            }

            akala.logger.verbose(`interpolating: ${JSON.stringify(triggerMap[param.id].action.params)}`);
            akala.logger.verbose(`triggerData: ${JSON.stringify(triggerData)}`);
            akala.logger.verbose(`conditionsData: ${JSON.stringify(conditionsData)}`);
            await server.executeAction({ name: triggerMap[param.id].action.name, channel: triggerMap[param.id].action.channel, params: interpolate(triggerMap[param.id].action.params, { $triggerData: triggerData, $conditionsData: conditionsData }) });
        },
        async update(param)
        {
            if (!(param.name in recipes))
                return Promise.reject({ status: 404, message: 'recipe does not exist' });

            if (recipes[param.recipe.name].triggerId)
            {
                await server.stopTrigger({ id: recipes[param.recipe.name].triggerId });
                delete triggerMap[recipes[param.recipe.name].triggerId];
            }
            if (param.name != param.recipe.name)
            {
                delete recipes[param.name];
                param.recipe.name = param.name;
            }
            recipes[param.name] = param.recipe;
            await writeFile(recipeFile, JSON.stringify(recipes));
            recipes[param.recipe.name].triggerId = await server.executeTrigger(param.recipe.trigger);
            triggerMap[recipes[param.recipe.name].triggerId] = param.recipe;
        },
        async insert(recipe, init?: boolean)
        {
            if (recipe.name in recipes)
                return Promise.reject({ status: 403, message: 'recipe already exists' });

            recipes[recipe.name] = recipe;
            if (!init)
                await writeFile(recipeFile, JSON.stringify(recipes));
            logger.verbose(`requesting trigger ${recipe.trigger}`);
            recipes[recipe.name].triggerId = await server.executeTrigger(recipe.trigger);
            triggerMap[recipes[recipe.name].triggerId] = recipe;
        },
        get(param)
        {
            return recipes[param.name];
        },
        list()
        {
            return akala.map(recipes, function (recipe)
//.........这里部分代码省略.........
开发者ID:domojs,项目名称:lifttt,代码行数:101,代码来源:index.ts


示例7: function

    akala.injectWithName(['$worker'], function (worker)
    {
        function getMainDevice(name)
        {
            var indexOfDot = name.indexOf('.');
            if (indexOfDot > 0)
                var mainDevice = name.substr(0, indexOfDot);
            else
                var mainDevice = name;

            return deviceCollection[mainDevice];
        }

        var client = akala.api.jsonrpcws(devices.deviceType).createClient(c, {
            exec: function (p)
            {
                var cmd = p.command;
                var mainDevice = getMainDevice(p.device);
                if (p.device != mainDevice.name)
                {
                    switch (p.device.substring(mainDevice.name.length + 1))
                    {
                        case 'power':
                            if (p.command == 'off')
                                cmd = 'PF'
                            else
                                cmd = 'PO'
                            break;
                        case 'mute':
                            if (p.command == 'off')
                                cmd = 'MF';
                            else
                                cmd = 'MO';
                            break;
                        case 'volume':
                            switch (p.command)
                            {
                                case 'up':
                                    cmd = 'VU';
                                    break;
                                case 'down':
                                    cmd = 'VD';
                                    break;
                                case 'set':
                                    cmd = 'VL';
                                    break;
                            }
                            break;
                        case 'input':
                            switch (p.command)
                            {
                                case 'Game':
                                    cmd = '49FN';
                                    break;
                                case 'Dvd':
                                    cmd = '04FN';
                                    break;
                                case 'Sat/Cbl':
                                    cmd = '06FN';
                                    break;
                                case 'Dvr/Bdr':
                                    cmd = '15FN';
                                    break;
                                case 'iPod':
                                    cmd = '17FN';
                                    break;
                                case 'Video':
                                    cmd = '10FN';
                                    break;
                                case 'BD':
                                    cmd = '25FN';
                                    break;
                            }
                            break;
                    }
                }
                return api.send(cmd, mainDevice['address']).then((result) => undefined);
            },
            getStatus: function (device)
            {
                var mainDevice = getMainDevice(device.device);

                if (mainDevice.name == device.device)
                    return Promise.resolve(mainDevice.status());
                else
                    return Promise.resolve(mainDevice.subdevices[device.device.substring(mainDevice.name.length + 1)].status());
            },
            save: (p) =>
            {
                if (p.device.name.indexOf('.') > -1)
                    return p.device;
                deviceCollection[p.device.name] = p.device;
                p.device['address'] = p.body.IP || p.device.name;
                p.device.statusMethod = 'pull';
                p.device.subdevices = [
                    {
                        name: "power",
                        type: 'pioneer',
                        category: 'switch',
                        classes: ['power', 'switch'],
//.........这里部分代码省略.........
开发者ID:domojs,项目名称:domojs-pioneer,代码行数:101,代码来源:index.ts



注:本文中的@akala/server.api类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript server.logger类代码示例发布时间:2022-05-28
下一篇:
TypeScript server.injectWithNameAsync函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap