本文整理匯總了TypeScript中@akala/server.injectWithNameAsync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript injectWithNameAsync函數的具體用法?TypeScript injectWithNameAsync怎麽用?TypeScript injectWithNameAsync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了injectWithNameAsync函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 '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' },
]
})
})
示例2: 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];
//.........這裏部分代碼省略.........
示例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 });
});
示例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 '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' }] })
})
示例5: 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)
//.........這裏部分代碼省略.........
示例6: 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' }] })
})