<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Форум Рутокен &mdash; Новый асинхронный интерфейс]]></title>
		<link>https://forum.rutoken.ru/topic/6924/</link>
		<atom:link href="https://forum.rutoken.ru/feed/rss/topic/6924" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Новый асинхронный интерфейс».]]></description>
		<lastBuildDate>Fri, 01 Aug 2025 12:39:21 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Новый асинхронный интерфейс]]></title>
			<link>https://forum.rutoken.ru/post/30747/#p30747</link>
			<description><![CDATA[<p><strong>zijili</strong>, я немного еще поотлаживался; после этого хотел бы заключить, что вы правы. Документация не совсем точна. Плагин из интерфейсных функций возвращает Promise-like объект с методом then.</p><p>Как проверял:</p><div class="codebox"><pre><code>plugin.login(0, &quot;1234567&quot;)
.then(function() {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + &quot;Token logged in&quot; + &quot;&lt;/pre&gt;&quot;;
})
.catch( msg =&gt; {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + msg + &quot;&lt;/pre&gt;&quot;;
})
.finally(
    function() {
        document.getElementById(&quot;pluginStatus&quot;).innerHTML = document.getElementById(&quot;pluginStatus&quot;).innerHTML + &quot;&lt;pre&gt;&quot; + &quot;Finally&quot; + &quot;&lt;/pre&gt;&quot;;
    }
);</code></pre></div><p>PIN-код неправильный, но catch и finally не зовется. Получить сообщение об ошибке можно, если указать в then вторым параметром функцию -- обработчик ошибки (как делается в <a href="https://aktivco.github.io/rutoken-plugin-demo/">https://aktivco.github.io/rutoken-plugin-demo/</a> )</p><p>Как получить Promises с catch/finally с тем же примером:</p><div class="codebox"><pre><code>Promise.resolve().then(function() {
    return plugin.login(0, &quot;1234567&quot;)
})
.then(function() {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + &quot;Token logged in&quot; + &quot;&lt;/pre&gt;&quot;;
})
.catch( msg =&gt; {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + msg + &quot;&lt;/pre&gt;&quot;;
})
.finally(
    function() {
        document.getElementById(&quot;pluginStatus&quot;).innerHTML = document.getElementById(&quot;pluginStatus&quot;).innerHTML + &quot;&lt;pre&gt;&quot; + &quot;Finally&quot; + &quot;&lt;/pre&gt;&quot;;
    }
);</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Евгений Мироненко)]]></author>
			<pubDate>Fri, 01 Aug 2025 12:39:21 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/30747/#p30747</guid>
		</item>
		<item>
			<title><![CDATA[Re: Новый асинхронный интерфейс]]></title>
			<link>https://forum.rutoken.ru/post/30744/#p30744</link>
			<description><![CDATA[<div class="quotebox"><cite>zijili пишет:</cite><blockquote><p>В документации указано, что реализация на promise, а по факту получаем объект в котором реализован только .then()</p></blockquote></div><p>Немного не понимаю. С моей стороны и такой код работает:</p><div class="codebox"><pre><code>rutoken.loadPlugin() // это promise
.then(p =&gt; {
    return p.login(0,&#039;1234&#039;); // это promise
})
.then(function() {
    document.write(&quot;Logged in&quot;);
}).catch( msg =&gt; {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + msg + &quot;&lt;/pre&gt;&quot;;
}).finally(function() {
    document.getElementById(&quot;pluginStatus&quot;).innerHTML = document.getElementById(&quot;pluginStatus&quot;).innerHTML + &quot;&lt;pre&gt;&quot; + &quot;Finally&quot; + &quot;&lt;/pre&gt;&quot;;
});</code></pre></div><p>В finally попадаю всегда под конец, в then/catch -- в зависимости от того, правильный ли PIN.</p><p>Как будто это соответствует документации на Promise: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">https://developer.mozilla.org/en-US/doc … ts/Promise</a></p>]]></description>
			<author><![CDATA[null@example.com (Евгений Мироненко)]]></author>
			<pubDate>Fri, 01 Aug 2025 11:49:52 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/30744/#p30744</guid>
		</item>
		<item>
			<title><![CDATA[Re: Новый асинхронный интерфейс]]></title>
			<link>https://forum.rutoken.ru/post/30743/#p30743</link>
			<description><![CDATA[<p>Код работает, вопрос заключается в другом.</p><p>В документации указано, что реализация на <strong>promise</strong>, а по факту получаем <strong>объект в котором реализован только .then()</strong></p><p>Я так понимаю это и есть финальная реализация, вопрос можно считать закрытым.<br />Спасибо за ответ!</p>]]></description>
			<author><![CDATA[null@example.com (zijili)]]></author>
			<pubDate>Fri, 01 Aug 2025 11:41:10 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/30743/#p30743</guid>
		</item>
		<item>
			<title><![CDATA[Re: Новый асинхронный интерфейс]]></title>
			<link>https://forum.rutoken.ru/post/30741/#p30741</link>
			<description><![CDATA[<p><strong>zijili</strong>, добрый день!</p><p>Такой код у вас не работает?</p><div class="codebox"><pre><code>rutoken.loadPlugin() // это promise
.then(p =&gt; {
    return p.login(0,&#039;1234&#039;); // это promise
})
.then(function() {
    document.write(&quot;Logged in&quot;);
});</code></pre></div><p>Советую посмотреть на простой пример <a href="https://dev.rutoken.ru/pages/viewpage.action?pageId=30113795">https://dev.rutoken.ru/pages/viewpage.a … d=30113795</a> и на демо-страницу Рутокен Плагин: <a href="https://aktivco.github.io/rutoken-plugin-demo/">https://aktivco.github.io/rutoken-plugin-demo/</a></p><p>С использованием rutoken-plugin.js из архива <a href="https://github.com/AktivCo/rutoken-plugin-js/archive/refs/tags/v1.0.10.zip">https://github.com/AktivCo/rutoken-plug … 1.0.10.zip</a> такой пример у меня успешно отработал:</p><div class="codebox"><pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
 &lt;head&gt;
 &lt;meta charset=&quot;UTF-8&quot;&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;rutoken-plugin.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    window.onload = function() {
        rutoken.ready
            // Проверка установки расширение &#039;Адаптера Рутокен Плагина&#039; в Google Chrome
            .then(function() {
                if (window.chrome || typeof InstallTrigger !== &#039;undefined&#039;) {
                    return rutoken.isExtensionInstalled();
                } else {
                    return Promise.resolve(true);
                }
            })
            // Проверка установки Рутокен Плагина
            .then(function(result) {
                if (result) {
                    return rutoken.isPluginInstalled();
                } else {
                    return Promise.reject(&quot;Не удаётся найти расширение &#039;Адаптер Рутокен Плагина&#039;&quot;);
                }
            })
            // Загрузка плагина
            .then(function(result) {
                if (result) {
                    return rutoken.loadPlugin();
                } else {
                    return Promise.reject(&quot;Не удаётся найти Плагин&quot;);
                }
            })
            //Можно начинать работать с плагином
            .then(function(result) {
                if (!result) {
                    return Promise.reject(&quot;Не удаётся загрузить Плагин&quot;);
                } else {
                    plugin = result;
                    return Promise.resolve();
                }
            })
            .then(function() {
                document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;Плагин загрузился&lt;/pre&gt;&quot;;
                return plugin.enumerateDevices();
            }, function(msg) {
                //document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + msg + &quot;&lt;/pre&gt;&quot;;
                return Promise.reject(&quot;Не удаётся загрузить Плагин&quot;);
            })
            .then(function(devices) {
                if (devices.length &gt; 0) {
                    return Promise.resolve(devices[0]);
                } else {
                    return Promise.reject(&quot;Рутокен не обнаружен&quot;);
                }
            })
            // Проверка залогиненности
            .then(function(firstDevice) {
                rutokenHandle = firstDevice;
                return plugin.getDeviceInfo(rutokenHandle, plugin.TOKEN_INFO_IS_LOGGED_IN);
            })
            // Логин на первый токен в списке устройств PIN-кодом по умолчанию
            .then(function(isLoggedIn) {
                if (isLoggedIn) {
                    return Promise.resolve();
                } else {
                    return plugin.login(rutokenHandle, &quot;12345678&quot;);
                }
            }).then(function() {
                document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + &quot;Token logged in&quot; + &quot;&lt;/pre&gt;&quot;;
            }).catch( msg =&gt; {
                document.getElementById(&quot;pluginStatus&quot;).innerHTML = &quot;&lt;pre&gt;&quot; + msg + &quot;&lt;/pre&gt;&quot;;
            });
    }
&lt;/script&gt;

&lt;title&gt;Rutoken Plugin Tutorial&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
 &lt;div id=&quot;pluginStatus&quot;&gt;&lt;pre&gt;Загрузка Плагина...&lt;/pre&gt;&lt;/div&gt;
 &lt;/body&gt; 
&lt;/html&gt;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Евгений Мироненко)]]></author>
			<pubDate>Fri, 01 Aug 2025 10:53:53 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/30741/#p30741</guid>
		</item>
		<item>
			<title><![CDATA[Новый асинхронный интерфейс]]></title>
			<link>https://forum.rutoken.ru/post/30739/#p30739</link>
			<description><![CDATA[<p>Chrome<br />Адаптер Рутокен Плагин 1.1.0.0<br />Плагин 4.11.0.0</p><p>Работаю с использованием <a href="https://github.com/AktivCo/rutoken-plugin-js">https://github.com/AktivCo/rutoken-plugin-js</a> </p><div class="codebox"><pre><code>rutoken.loadPlugin() // это promise
.then(p =&gt; {
 p.login(0,&#039;1234&#039;); // это не promise
});</code></pre></div><p>В описании - Все интерфейсные функции плагина возвращают promise<br />Как я могу добиться такого поведения плагина?</p>]]></description>
			<author><![CDATA[null@example.com (zijili)]]></author>
			<pubDate>Fri, 01 Aug 2025 09:46:49 +0000</pubDate>
			<guid>https://forum.rutoken.ru/post/30739/#p30739</guid>
		</item>
	</channel>
</rss>
