当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Client.connect方法代码示例

本文整理汇总了TypeScript中@akala/json-rpc-ws.Client.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.connect方法的具体用法?TypeScript Client.connect怎么用?TypeScript Client.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@akala/json-rpc-ws.Client的用法示例。


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

示例1: Promise

            kodis[kodiService.id] = new Promise((resolve, reject) =>
            {
                var kodi = new Client();

                kodi.connect('ws://' + kodiService.referer.address + ':' + kodiService.port + '/jsonrpc', function connected(err)
                {
                    if (err)
                    {
                        debug.error(err);
                        reject(err);
                    }
                    debug.log('connected to ' + kodiService.name);

                    kodi.send('JSONRPC.Introspect', [], async function (error, reply)
                    {
                        if (error)
                        {
                            debug.error(error);
                            reject(error);
                        }
                        else
                        {
                            akala.each(reply['methods'], function (m, i)
                            {
                                var ns = (i as string).split('.');
                                if (typeof (kodi[ns[0]]) == 'undefined')
                                    kodi[ns[0]] = {};
                                kodi[ns[0]][ns[1]] = function (params)
                                {
                                    return new Promise<any>((resolve, reject) =>
                                    {
                                        if (!kodi.isConnected())
                                        {
                                            client.$proxy().unregisterPlayer({ identity: kodiService.id, name: kodiService.name })
                                            reject(new Error('Not connected'));
                                            return;
                                        }

                                        akala.each(m.params, function (value)
                                        {
                                            if (value.required && typeof (params[value.name]) == 'undefined')
                                            {
                                                throw JSON.stringify(params) + ' is missing the required param ' + value.name + ' for ' + ns[1];
                                            }
                                        });
                                        akala.logger.verbose('calling ' + i, JSON.stringify(params));
                                        kodi.send(i as string, params, (error, result) =>
                                        {
                                            if (error)
                                                reject(error);
                                            else
                                                resolve(result);
                                        });
                                    });
                                }
                            })
                            akala.each(reply['notifications'], function (i, m)
                            {
                                var ns = i.split('.');
                                if (typeof (kodi[ns[0]]) == 'undefined')
                                    kodi[ns[0]] = {};
                                kodi[ns[0]][ns[1]] = function (callback)
                                {
                                    if (typeof (callback) == 'undefined')
                                    {
                                        throw 'callback is missing for ' + ns[1];
                                    }
                                    akala.logger.info('monitoring ' + i, JSON.stringify(i));
                                    kodi.expose(i, callback);
                                }
                            })
                            debug('kodi client built');
                            await kodi['JSONRPC'].SetConfiguration({ notifications: { gui: false, system: true, player: true, audiolibrary: false, other: false, videolibrary: false } });
                            kodi['Player'].OnPause(function ()
                            {
                                debug('OnPause')
                                client.status({ target: kodiService.id });
                                stopTimer(kodiService.id);
                            });
                            kodi['Player'].OnPlay(function ()
                            {
                                debug('OnPlay')
                                client.status({ target: kodiService.id });
                                client.playlist({ target: kodiService.id });
                                startTimer(kodiService.id);
                            });
                            kodi['Player'].OnSeek(function ()
                            {
                                debug('OnSeek')
                                client.status({ target: kodiService.id });
                            });
                            kodi['Player'].OnPropertyChanged(function ()
                            {
                                debug('OnPropertyChanged')
                                client.status({ target: kodiService.id });
                            });
                            kodi['Player'].OnStop(function ()
                            {
                                debug('OnStop')
                                client.status({ target: kodiService.id });
//.........这里部分代码省略.........
开发者ID:domojs,项目名称:domojs-media-kodi,代码行数:101,代码来源:player.ts


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