Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="vue-loading">
  <i class="fas fa-circle-notch fa-spin fa-3x fa-fw"></i>
</div>
<section id="app" v-cloak>
  <div class="steps">
    <div class="number-box">2</div>
    <div class="header">
      Establish connection
      <span v-show="connected">
        <i class="session-status fas fa-link is-warning"></i>
      </span>
      <span v-show="!connected">
        <i class="session-status fas fa-unlink is-primary"></i>
      </span>
    </div>
  </div>
  <div id="tab-session">
    <form>
      <div v-if="showAdvancedSettings">
        <div class="field">
          <label class="label">Broker URL</label>
          <div class="control">
            <input class="input" type="text" v-model="tabs.session.form.url" />
          </div>
        </div>

        <div class="field">
          <label class="label">Client Username</label>
          <div class="control">
            <input class="input" type="text" v-model="tabs.session.form.userName" />
          </div>
        </div>

        <div class="field">
          <label class="label">Client Password</label>
          <div class="control">
            <input class="input" type="password" v-model="tabs.session.form.password" />
          </div>
        </div>

        <div class="field">
          <label class="label">Message VPN</label>
          <div class="control">
            <input class="input" type="text" v-model="tabs.session.form.vpnName" />
          </div>
        </div>
      </div>

      <div class='buttons'>
        <input class="button is-primary" 
               type="submit" 
               v-model="tabs.session.form.button.connect" 
               :disabled="session"
               @click.prevent="connect" 
        />
        <input class="button" 
               type="submit" 
               v-model="tabs.session.form.button.disconnect" 
               :disabled="!session" 
               @click.prevent="disconnect"
        />
        <input class="button" 
               type="submit" 
               v-model="tabs.session.form.button.advanced" 
               :disabled="false" 
               @click.prevent="toggleAdvancedSettings()"
               />
        <i class="fa fa-spinner fa-fw fa-spin" aria-hidden="true" v-if="sessionRequestPending"></i>
      </div>
    </form>

      <div class="status message is-primary" v-show="tabs.session.status.show">
        <div class="message-header">
          <p>Connect Status</p>
        </div>
        <div class="message-body">
          {{tabs.session.status.message}}
        </div>
      </div>
  </div>

  <div class="steps">
    <div class="number-box">3</div>
    <div class="header">Subscribe</div>
  </div>
  <div id="tab-subscribe">
    <div class="columns">
      <div class="column">
        <form>
          <label class="label">Add Topic</label>
          <div class="field has-addons">
            <div class="control">
              <input class="input subscribe"
                     type="text" 
                     v-model="tabs.subscribe.form.topic" 
              />
            </div>
            <div class="control">
              <input class="button is-primary" type="submit" :disabled="!(session && tabs.subscribe.form.topic.length)" v-model="tabs.subscribe.form.buttons.subscribe"
                @click.prevent="subscribe" />
            </div>
          </div>
          <div class="field">
            <label class="label">Subscribed Topics</label>
            <div v-if="subscriptions.length">
              <div class="field is-grouped is-grouped-multiline">
                <template v-for="topic in subscriptions">
                  <div class="control">
                    <div class="tags has-addons">
                      <span class="tag is-primary">{{ topic }}</span>
                      <a class="tag is-delete" 
                         href='#' 
                         @click.prevent="unsubscribe(topic)"></a>
                    </div>
                  </div>
                </template>
              </div>
            </div>
            <div v-else>
              Add a topic subscription to begin receiving messages.
            </div>
          </div>
        </form>
        <transition name="fade" mode="out-in">
          <div class="status message is-primary" v-show="tabs.subscribe.status.show">
            <div class="message-header">
              <p>Subscribe Status</p>
            </div>
            <div class="message-body">
              {{tabs.subscribe.status.message}}
            </div>
          </div>
        </transition>
      </div>

      <div class="column">
        <h2 class="subtitle">
          Messages
        </h2>
        <div class="scroller messages">
          <div v-for="(message, index) in messages" 
               class="tags has-addons">
            <article class="message is-primary">
              <div class="message-header">
                {{ message.date.toLocaleTimeString() }} {{ message.message.getDestination().toString() }}
                <button class="delete" @click.prevent="messageRemove(index)"></button>
              </div>
              <div v-for="view in messageContent(message)"
                   class="message-body">
                {{ view }}
              </div>
              <div class="message-format">
                <div class="control">
                  <label class="radio">
                    <input type="radio" value="binaryAttachment" v-model="message.format"> binary
                  </label>
                  <label class="radio">
                    <input type="radio" value="sdtText" v-model="message.format"> text
                  </label>
                </div>
              </div>
            </article>
          </div>
        </div>
      </div>
    </div>

  </div>

</section>
            
          
!
            
              $background-color:    #FFFFFF;
$banner-color:        #474747;
$border-top-color:    #606060;
$delete-tag-color:    #e0e0e0;
$field-shadow-color:  rgba(0, 0, 0, 0.15);
$format-select-color: #c0c0c0;
$label-color:         #595959;
$radio-color:         #7b7c7d;
$title-color:         #FFFFFF;

$font-stack:          'Rubik', sans-serif;
$font-weight-normal:  normal;

html {
  background-color: $background-color;
  height: 100%;
}

.title, 
.control, 
.field, 
.tabs, 
.input,
.textarea,
.radio {
  font-family: $font-stack;
  font-weight: $font-weight-normal;
}

.banner {
  margin: -2em -2em 0em -2em;
  padding: 1em 1em 0em 1em;
  background-color: $banner-color;  
}

.title {
  height: 50px;
  font-size: 1.8em;
  color: $title-color;
}

body {
  padding: 2em;
}

.label {
  color: $label-color;
  font-size: 0.8rem;
  font-weight: 400;
}

.input,
.textarea {
  font-size: 20px;
  font-weight: 300;
  box-shadow: 0 1px 1px $field-shadow-color;
}

label.radio {
  font-size: 15px;
  line-height: 25px;
  color: $radio-color;
}

[v-cloak] {
  display: none;
}

#vue-loading {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 150px;
}

#tab-session, #tab-subscribe {
  margin-left: 50px;
}

.steps {
  display: flex;
  position: relative;
  margin: auto 0;
  height: 40px;
  margin-bottom: 5px;
  
  .number-box {
    width: 30px;
    height: 30px;
    color: white;
    background: #474747;
    text-align: center;
    margin: auto 20px auto 0;
    padding-top: 3px;
    border-radius: 5px;
  }
  .header {
    margin: auto 0;
    font-size: 18px;
    color: rgba(0, 0, 0, 0.65);
    font-weight: 500;
    flex: 1;
  }
}

form {
  .buttons {
    margin-top: 15px;
    margin-bottom: 5px !important;
    position: relative;
    .advanced {
      position: absolute;
      right: 0;
      color: #00ad93;
      bottom: 15px;
    }
    .fa-spinner {
      color: #00ad93;
    }
  }
  .is-primary {
    background: #00ad93 !important;
  }
  input.subscribe {
    font-size: 16px;
  }
}

.fade-enter, 
.fade-leave-active {
  opacity: 0;
}

.fade-enter-active, 
.fade-leave-active {
  transition: opacity .5s;
}

.status {
  margin-top: 2em;
}

.tag.is-delete {
  background-color: $delete-tag-color;
}

.status {
  margin-top: 2em;
}

.message-header {
  background: #00ad93 !important;
}

.message-body {
  border-color: #00ad93 !important;
}

.session-status {
  padding-left : 3px;
  font-size: 0.8em;
  &.fa-unlink {
    color: red;
  }
  &.fa-link {
    color: green;
  }
}

.messages {
  border-top: 1px solid $border-top-color;
  .message {
    margin-top: 1em;
    width: 100%;
  };
  .message-format {
    padding: 1em;
    background-color: $format-select-color;
  }
}

.tabs li.is-active a {
  border-bottom-color: #4a4a4a;
  color: #000;
}

            
          
!
            
              const { 
  SolclientFactory, 
  SDTField,
  SDTFieldType,
  Session, 
  StatType,
  SessionEventCode,
  TransportProtocol 
} = solace;
const { 
  createSession, 
  createTopicDestination, 
  createMessage,
} = SolclientFactory;
const {
  getCurrentService
} = (SolaceCloud || {});

const MAX_MESSAGES = 300;

const app = new Vue({
  
  el: '#app',
  
  data: {
    tabs: {
      session: {
        active: true,
        form: {
          url: "ws://localhost",
          userName: "default",
          vpnName: "default",
          password: "secret",
          transportProtocol: TransportProtocol.HTTP_BINARY_STREAMING,
          button: {
            connect: 'Connect',
            disconnect: 'Disconnect',
            advanced: 'Advanced ...'
          }
        },
        status: {
          show: false,
          message: ''
        }
      },
      subscribe: {
        form: {
          topic: 'topic/try/me',
          buttons: {
            subscribe: 'Subscribe'
          }
        },
        status: {
          show: false,
          message: ''
        }
      }
    },
    
    connected: false,
    session: null,
    subscriptions: new Set(),
    messages: [],
    pendingSession: null,
    showAdvancedSettings: false
  },
  
  methods: {
    
    // Initialize the Solace API factory.
    init() {
      SolclientFactory.init({
        profile: SolclientFactory.profiles.version7
      });
      // If embedded in Solace Cloud (as a demo), ask the console for service credentials.
      getCurrentService && getCurrentService((r) => app.setSessionCredentials(r.data.service));
    },
    
    // Reset the application state.
    reset() {
      this.session.dispose();
      this.session = null;
      this.subscriptions = [];
      this.connected = false;
    },
    
    // Connect a session and listen for events.
    connect() {
      if (this.session) this.reset();
      
      // Create a session with the given session properties
      try {
        this.session = createSession(this.tabs.session.form);
      } catch (ex) {
        this.setStatus('session', 'Error creating session: ' + ex.message);
        return;
      }
      
      // Listen for events
      this.session.on(SessionEventCode.UP_NOTICE, () => {
        this.connected = true;
        this.sessionRequestCompleted();
        this.setActiveTab('subscribe');
      });
      this.session.on(SessionEventCode.DISCONNECTED, () => {
        this.sessionRequestCompleted();
        this.reset();
      });
      this.session.on(SessionEventCode.DOWN_ERROR, (...args) => {
        this.setStatus('session', 'Session down with error ' + event);
        this.reset();
      });
      this.session.on(SessionEventCode.MESSAGE, message => {
        this.messageAdd(message);
      });

      // Connect the session
      this.showSessionRequestPending();
      try {
        this.session.connect();      
      } catch (ex) {
        this.setStatus('session', 'Error connecting session: ' + ex.message);
        this.reset();
      }      
    },
    
    // Disconnect the session.
    disconnect() {
      if (!this.session) return;
      this.showSessionRequestPending();
      this.session.disconnect();
    },
    
    // Subscribe to a topic.
    subscribe() {
      const { session } = this;
      const { form } = this.tabs.subscribe;
      try {
        session.subscribe(createTopicDestination(form.topic));
      } catch (ex) {
        this.setStatus('subscribe', 'Error subscribing: ' + ex.message);      
      }
      
      this.subscriptions = Array.from(new Set([...this.subscriptions, form.topic]));
      form.topic = '';
    },
    
    // Unsubscribe from a topic.
    unsubscribe(topic) {
      const { session } = this;
      try {
        session.unsubscribe(createTopicDestination(topic));
      } catch (ex) {
        this.setStatus('subscribe', 'Error unsubscribing: ' + ex.message);      
      }
      
      this.subscriptions = this.subscriptions.filter(x => x != topic);
    },
    
    // Wrap a received message and add it to the display.
    // Often you'll simply put your own payload, e.g. JSON, in the binaryAttachment,
    // so you won't need to inspect the message contents like this.
    messageAdd(message) {
      this.messages.unshift({
        date: new Date(),
        format: message.getSdtContainer() ? 'sdtText' : 'binaryAttachment', 
        message
      });
      if (this.messages.length > MAX_MESSAGES) this.messages.length = MAX_MESSAGES;
    },
    
    // Display the message content using the message's selected format.
    messageContent(messageWrapper) {
      const { format, message } = messageWrapper;
      if (format === 'sdtText') {
        const container = message.getSdtContainer();
        return [container && container.getValue() || '<empty>'];
      }
      const attachment = message.getBinaryAttachment() || '';
      return [
        attachment.split('').map(x => `0${x.codePointAt(0).toString(16)}`.slice(-2)).join(' '), 
        attachment
      ];
    },
    
    // Removes a message from the display.
    messageRemove(index) {
      this.messages.splice(index, 1);
    },
    
    // Sets a status popup message.
    setStatus(type, message) {
      const statusNode = this.tabs[type].status;
      Object.assign(statusNode, {
        show: true,
        message
      });
      this.sessionRequestCompleted();
    },
    
    showSessionRequestPending() {
      this.sessionRequestPending = true;
    },
    
    sessionRequestCompleted() {
      this.sessionRequestPending = false;
    },
    
    // Sets the active tab to the given tab name.
    setActiveTab(selection) {
      Object.keys(this.tabs).forEach(tabName => {
        const tab = this.tabs[tabName];
        tab.active = (tabName === selection);
      });
    },
    
    // toggle the advanced settings
    toggleAdvancedSettings() {
      this.showAdvancedSettings = !this.showAdvancedSettings;
      this.tabs.session.form.button.advanced = (!this.showAdvancedSettings) ? 'Advanced ...':'Less';
    },
        
    // Sets the session credentials using the enumerable properties provided.
    setSessionCredentials(properties) {
      Object.assign(this.tabs.session.form, properties);
    }
    
  },
  
  mounted() {
    document.getElementById('vue-loading').remove();
    this.init();
  }
  
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console