當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Client.send方法代碼示例

本文整理匯總了TypeScript中@akala/json-rpc-ws.Client.send方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client.send方法的具體用法?TypeScript Client.send怎麽用?TypeScript Client.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@akala/json-rpc-ws.Client的用法示例。


在下文中一共展示了Client.send方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: reject

                                    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);
                                        });
                                    });
開發者ID:domojs,項目名稱:domojs-media-kodi,代碼行數:25,代碼來源:player.ts

示例2: connected

                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 });
                                stopTimer(kodiService.id);
                            });

                            resolve(kodi as any);
//.........這裏部分代碼省略.........
開發者ID:domojs,項目名稱:domojs-media-kodi,代碼行數:101,代碼來源:player.ts


注:本文中的@akala/json-rpc-ws.Client.send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。