Announcement

Collapse
No announcement yet.

[CLOSED] Getting examples of Retyped library

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] Getting examples of Retyped library

    Hey guys,
    First off, to the amazing geniuses who created Retyped, way to go! Your work to "open a portal to the JavaScript universe" is totally amazing! I haven't messed with Electron (I use NW.js a lot at work, which is similar) but I'm definitely gonna check it out, and also try it with NW, now that Bridge can access Node APIs! And of course, since this is Saturday, I'm not building anything work-related, so of course I'm messing with libraries for building games!

    But unfortunately, there's one kinda nasty gotcha with this amazing new tool: There is no documentation. There's IntelliSense, cuz Bridge rocks, but I think I discovered a difference between the library I want to use (Howler.js) and how it's represented in C#. I found the original .d.ts file on GitHub, but sadly there was no README, so I'm kinda stuck guessing my way through IntelliSense and trying to figure out what could potentially work.

    In case anyone's interested, let me explain the problem. In Howler (an awesome audio library btw) the main sound object is called a Howl. You instantiate it with the "new" keyword like in any other C# class. But the .d.ts file lists it as an interface, which apparently means your only option is to re-implement everything yourself by creating a class that implements the interface (which kinda defeats the purpose IMO). I suppose I could slap the [External] at the top or use the "extern" keyword (I forget which one does what lol) to use a class like this as a starting point for a declaration file of my own, but again, that kinda defeats the purpose. There's also a "HowlStatic" class (again, there is no such thing in the JS version) but it has been no help so far either.

    Is there a place where I can get some documentation, or examples, or _anything_ that could lend a clue? Thanks.

    #2
    Hi DojoMike,

    I'm having a difficult time making sense of the Retyped.Howler implementation as well. The Howl class and all of its members are marked as abstract, which forces a sub-class to re-implement the entire logic. Not good.

    We're going to have to do some work to clean this up.

    Comment


      #3
      Hi DojoMike,

      You were right when saying that there is no sense of implementing the interfaces. Howler library does that for us, and we're supposed to use static properties returning those HowlerGlobal (Retyped.howler.Howler) and HowlStatic (Retyped.howler.Howl2) interfaces.

      Indeed, as geoffrey.mcgill mentioned Retyped has logic converting interfaces to abstract classes. That helps to reduce size of inheritors (they will have to implement abstract methods only, and properties often are not abstract). Another advantage of this approach - interfaces having no methods will be emitted as non-abstract object literal classes, making possible instantiation of those classes (that happened with IHowlProperties interface).

      Below is a rough sample for playing a live stream from a radio station:

      Demo.html :
      <!DOCTYPE html>
      
      <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
      <head>
          <meta charset="utf-8" />
          <title>Howler Demo</title>
      
          <script src="./bin/Debug/bridge/bridge.js"></script>
          <script src="./bin/Debug/bridge/bridge.console.js"></script>
          <script src="./bin/Debug/bridge/Demo.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.0.0/howler.js"></script>
      </head>
      <body>
      </body>
      </html>
      Demo.cs :
      namespace Demo
      {
          using static Retyped.dom;
          using static Retyped.howler;
      
          public class App
          {
              private static Howl _howl;
      
              public static void Main()
              {
                  var playBtn = new HTMLButtonElement
                  {
                      innerText = "Play"
                  };
      
                  var stopBtn = new HTMLButtonElement
                  {
                      innerText = "Stop"
                  };
      
                  playBtn.addEventListener("click", Play);
                  stopBtn.addEventListener("click", Stop);
      
                  document.body.appendChild(playBtn);
                  document.body.appendChild(stopBtn);
              }
      
              private static void Play()
              {
                  Stop();
      
                  var howlProps = new IHowlProperties
                  {
                      src = new[]
                      {
                          "http://ice1.somafm.com/groovesalad-128-mp3",
                          "http://ice1.somafm.com/groovesalad-128-aac"
                      },
                      html5 = true,
                      format = new[] { "mp3", "aac" }
                  };
      
                  _howl = Howl2.New(howlProps);
                  _howl.play();
      
                  System.Console.WriteLine("Playing..");
              }
      
              private static void Stop()
              {
                  if (_howl != null)
                  {
                      _howl.stop();
                      _howl = null;
      
                      System.Console.WriteLine("Stopped.");
                  }
              }
          }
      }
      Hope that helps.

      Comment


        #4
        Hi DojoMike,

        We had a team meeting today and discussed Retyped.Howler. We'll be making some changes to Retyped that will clean up the syntax and make it much more natural. The changes will be available in the next release of Retyped. At the moment we do not have a release date for Retyped, but it's getting close and we're working hard to finish.

        We'll also be adding some Howler demos to https://demos.retyped.com.

        We'll update this thread once complete.

        Comment


          #5
          Hi DojoMike,

          The Retyped.howler package was updated with the howler.js v2.0.5 API. It also includes syntax refinements that we discussed some time ago. So the sample from my previous post needs to be updated:
          // Before:
          _howl = Howl2.New(howlProps);
          
          // After:
          _howl = new Howl(howlProps);

          Comment

          Working...
          X