|
| 1 | +# Stream Deck SDK |
| 2 | + |
| 3 | +This project is a **not official** SDK for Elgato's Stream Deck. |
| 4 | + |
| 5 | +The idea behind was that there are few "files" or projects which want providing an layer for the Stream Deck. |
| 6 | +But I want to develop some plugins as easy as possible and as fast as possible. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- Automatic setting management (Loading & Saving values in Property Inspector with 2 lines of code) |
| 11 | +- Setting image easily via URL |
| 12 | +- Drawing management (Canvas) |
| 13 | +- HTTP Module (http.get/http.post/... easily instead of fetch) |
| 14 | + |
| 15 | +# Installation |
| 16 | + |
| 17 | + $ npm install streamdeck-sdk |
| 18 | + |
| 19 | +After that add the script to header of your html files. (i.e. `plugin.html`/`index.html` and `property-inspector.html`) |
| 20 | + |
| 21 | + <script src="node_modules/streamdeck-sdk/dist/StreamDeckSDK.js"></script> |
| 22 | + |
| 23 | +When you downloaded only the `StreamDeckSDK.js` you can easily add them, too. |
| 24 | + |
| 25 | + <script src="StreamDeckSDK.js"></script> |
| 26 | + |
| 27 | +# Registration Procedure |
| 28 | + |
| 29 | +Read the steps for the plugin and for the property inspector. |
| 30 | + |
| 31 | +## Plugin |
| 32 | + |
| 33 | +The plugin is easily load via: |
| 34 | + |
| 35 | + <script> |
| 36 | + var plugin = new StreamDeckPlugin(); |
| 37 | + </script> |
| 38 | + |
| 39 | +## Property Inspector |
| 40 | + |
| 41 | +The property inspector is easily load via: |
| 42 | + |
| 43 | + <script> |
| 44 | + var propertyInspector = new StreamDeckPropertyInspector(); |
| 45 | + </script> |
| 46 | + |
| 47 | +### Automatic setting management |
| 48 | + |
| 49 | +For enabling the property inspector setting management you must add this line to your `<script>`: |
| 50 | + |
| 51 | + propertyInspector.enableSettingManager(); |
| 52 | + |
| 53 | +Behind the scene it loops all your `input`, `textarea` and `select` elements. |
| 54 | +Then it checks for the `name` or `id` attribute and if it's already set in the `settings` of your Stream Deck. |
| 55 | + |
| 56 | +If yes, it automatically set's the `value` of your element to the stored value. |
| 57 | +On change event it will automatically store the value. |
| 58 | +And in case of closing the property inspector there is a listener for the `beforeunload` event. |
| 59 | +(which sends the settings to the plugin which stores it then automatically) |
| 60 | + |
| 61 | +You can disable the automatic loading and saving for single elements by adding the `sdk-ignore` class. |
| 62 | + |
| 63 | +This logic supports also `file` inputs. |
| 64 | +You can show the `file` then in the plugin via `instance.setImageURL(instance.settings.myname)`. |
| 65 | + |
| 66 | +### Example: Simple counter (with stored and changable value) |
| 67 | + |
| 68 | +This demonstrates how easy you can develop a plugin with property inspector view. |
| 69 | + |
| 70 | +_Do not forget to add the StreamDeckSDK.js in plugin and property inspector files as described in Installation!_ |
| 71 | + |
| 72 | +#### Plugin |
| 73 | + |
| 74 | +The plugin shows a number (counter) and on each key press (keyUp) it will count the number plus one. |
| 75 | +But when we got a new value from property inspector we also want to use this number. |
| 76 | + |
| 77 | + // First we initialize the Stream Deck Plugin |
| 78 | + var plugin = new StreamDeckPlugin(); |
| 79 | + // Then we listen to the initialization process |
| 80 | + plugin.on('init', function(event) { |
| 81 | + // Each init gives one instance (instance = 1 button on the Stream Deck) |
| 82 | + // Instances having an `action` which you can check when you have multiple actions! |
| 83 | + // i.e. if (instance.action === 'org.examle.firstaction') { } |
| 84 | + var instance = event.detail.instance; |
| 85 | + // Then we setting the title of the instance to the counter - else 1 |
| 86 | + instance.setTitle((+instance.settings.counter) || 1); |
| 87 | + // Now we're going to listen for keyUp, so whenever we press the button and release this is called |
| 88 | + instance.on('keyUp', function() { |
| 89 | + // Lets get the current value and count + 1 |
| 90 | + var count = ((+instance.settings.counter) || 1) + 1; |
| 91 | + // Now lets set the title of our instance to the number |
| 92 | + instance.setTitle(count); |
| 93 | + // And then lets save the new number |
| 94 | + instance.setSetting('counter', count); |
| 95 | + }); |
| 96 | + // We want also to listen for changed settings from the property inspector |
| 97 | + instance.on('didReceiveSettings', function() { |
| 98 | + // So when property inspector changes the counter value set the title to it |
| 99 | + instance.setTitle(instance.settings.counter || 1); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | +#### Property Inspector |
| 104 | + |
| 105 | +In the property inspector we add the element with the input to the `<body>`. |
| 106 | + |
| 107 | + <div class="sdpi-item"> |
| 108 | + <div class="sdpi-item-label">Counter Value</div> |
| 109 | + <input class="sdpi-item-value" name="counter" /> |
| 110 | + </div> |
| 111 | + |
| 112 | +And in the `<script>` (maybe before closing `</body>`) we add our logic. |
| 113 | + |
| 114 | + <script> |
| 115 | + var plugin = new StreamDeckPropertyInspector(); |
| 116 | + plugin.enableSettingManager(); |
| 117 | + </script> |
| 118 | + |
| 119 | +#### Done |
| 120 | + |
| 121 | +Et voilà - we created a simple logic which sends the counter value to the plugin which shows it. |
| 122 | +And the plugin count it up on each keypress. |
| 123 | +The property inspector will also be updated on each `keyUp` because it's listening to the setting change event. |
| 124 | + |
| 125 | +# Build |
| 126 | + |
| 127 | +Run `npm run build` to build the project. The build artifacts will be stored in the `dist/` directory. |
| 128 | + |
| 129 | +# Sample plugins |
| 130 | + |
| 131 | +* Coming May 2020: Toggl |
| 132 | +* Coming May 2020: INSTAR Camera Viewer |
| 133 | + |
| 134 | +# Contributing |
| 135 | + |
| 136 | +Feel free to open issues, pull requests or something else. |
| 137 | + |
| 138 | +When you need a plugin feel free to request it via the issues. |
0 commit comments