npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

streambim-widget-api

v2.0.1

Published

A JavaScript library for interacting with StreamBIM from within an embedded widget, and when using StreamBIM in embedded mode.

Downloads

56

Readme

streambim-widget-api

A JavaScript library for interacting with StreamBIM from within an embedded widget, as well as for using StreamBIM in embedded mode.

Integration

StreamBIM widgets have to be whitelisted and then enabled per StreamBIM project. Please contact [email protected] if you want to set up a custom widget for one or more projects.

Authentication

If your widget requires authentication you have two options:

  1. Handle the authentication in the widget itself
  2. Use OpenID Connect and provide us with your identity server etc. StreamBIM will then open your login screen in a popup and persist the token per user across sessions.

Installation

Using npm

npm install streambim-widget-api --save

And import the library into your code.

To run a widget inside StreamBIM, call something like this from your widget:

import StreamBIM from 'streambim-widget-api';

const methods = {
  pickedObject: function (result) {
    console.log('Clicked at ' + result.guid);
  }
}

StreamBIM.connect(methods).then(function() {
  console.log('Connected!');
});

To run StreamBIM in embedded mode, first create an iframe, open a StreamBIM project with embedded=true in the URL parameters, and then call the connectToChild method.

import StreamBIM from 'streambim-widget-api';

const iframe = document.getElementById('streambim_target');
const projectId = PROJECT_ID;

iframe.src = 'https://app.streambim.com/webapp/default/#/viewer?projectId=' + projectId + '&embedded=true';

const methods = {
  pickedObject: function (result) {
    console.log('Clicked at ' + result.guid);
  }
}

StreamBIM.connectToChild(iframe, methods).then(function() {
  console.log('Connected!');
});

For full list of supported methods, see Usage below.

CDN

We don't currently have a CDN solution, but you can download, bundle and load the minified script, in which case the library will be available on window.StreamBIM

<script src="streambim-widget-api.min.js"></script>
<script>
  window.StreamBIM.connect().then(function() {
    console.log('Connected!');
  });
</script>

Usage

// From within a widget

StreamBIM.connect({
  pickedObject: function (result) {
    console.log('Clicked at ' + result.guid);
  },
  spacesChanged: function (guids) {
    console.log('Entered space: ' + guids[0]);
  }
}).then( function () {
  console.log('Widget ready');

  StreamBIM.getCameraState().then( (result) => {
    console.log('Got camera state: ', result);
  });
});


// From a parent running StreamBIM in embedded mode
StreamBIM.connectToChild(iframe, {
  pickedObject: function (result) {
    console.log('Clicked at ' + result.guid);
  },
  spacesChanged: function (guids) {
    console.log('Entered space: ' + guids[0]);
  }
}).then( function () {
  console.log('Widget ready');

  StreamBIM.getCameraState().then( (result) => {
    console.log('Got camera state: ', result);
  });
});

API

The API is promise based, which means all functions below return promises.

connect(callbacks)

This establishes the connection from the widget to StreamBIM. The function returns a promise which has to be fulfilled before any other API calls can be made.

connectToChild(iframe, callbacks)

This establishes the connection from the parent to StreamBIM in embedded mode. The function returns a promise which has to be fulfilled before any other API calls can be made.

Callbacks
  • pickedObject (function, optional) Function to be called whenever the user picks an object in StreamBIM. The function has one argument, which is an object containing point - the picked 3D coordinate and guid - the GUID of the picked object.

  • spacesChanged (function, optional) Function to be called whenever the user enteres or leaves a space. The function has one argument which is an array of IFC space GUIDs, sorted from the smallest to the largest space.

  • cameraChanged (function, optional) Function to be called whenever the user moves or rotates the camera. The function has one argument which holds the camera position (vector) and orientation (quaternion). This complies to the IFC/BCF coordinate system where position (0,0,0) is the model origin and orientation (0,0,0,0) is north.

  • didExpand (function, optional) Function to be called whenever the widget is expanded into fullscreen mode, either using the widget API or by the user clicking the expand/contract button in the panel header.

  • didContract (function, optional) Function to be called whenever the widget is contracted into side panel mode, either using the widget API or by the user clicking the expand/contract button in the panel header.

getProjectId()

Returns a promise which is resolved with the project's ID.

getUserEmail()

Returns a promise which is resolved with the authenticated user's email.

getCameraState()

Returns a promise which is resolved with an object containing the camera's position and quaternion.

setCameraState(state)

Takes an object of the form

{
  position: [x, y, z],
  quaternion: [x, y, z, w]
}

and applies it to the user's camera.

setCameraPosition([x, y, z])

Moves the camera to position (x, y, z) without modifying the camera's rotation.

getSpaces()

Returns a promise which is resolved with an array of GUIDs of the spaces the user's camera is currently inside. The spaces are sorted form the smallers to the largest.

getObjectInfo(guid)

Returns a promise which is resolved with an object with various information about the object.

gotoSpace(guid)

Move the camera to the center of the space.

highlightObject(guid)

deHighlightObject(guid)

deHighlightAllObjects()

hideObject(guid)

showObject(guid)

findObjects(query)

Returns a promise which is resolved with an an array of GUIDs for objects matching the query.

Query options
  • filter.key The key for the property to search for
  • filter.value The value of the property to search for
  • page.limit and page.skip for pagination
  • sort.field and sort.descending for sorting (only applies to getObjectInfoForSearch)
  • fieldUnion used for getObjectInfoForSearch only. If true, it returns all properies for all objects. If false, it returns only basic properties.
{
  filter: {
    key: "Type Object Global Id",
    value: "1a7mCik3D1IgMeWf2ZMmvT"
  },
  page: {
    limit: 10,
    skip: 0
  },
  sort: {
    field: 'ID',
    descending: false

  }
}

getObjectInfoForSearch(query)

Filter the 3D scene to show only objects matching the filter. See findObjects(query) for filter options.

applyObjectSearch(filter)

Filter the 3D scene to show only objects matching the filter. See findObjects(query) for filter options.

resetObjectSearch()

showAllObjects()

getViewportState()

Returns a promise which is resolved with an object containing the entire viewport state, including camera position and rotation, hidden- and highlighted objects, hidden layers and clipping planes.

setViewportState(state)

Resets the viewport and applies the state, which should be on the same form as returned from getViewportState():

{
  cameraState: {
    position: [x, y, z],
    quaternion: [x, y, z, w]
  },
  hiddenObjects: [guid],
  highlightedObjects: [guid],
  hiddenLayers: [layerName],
  clippingPlanes: [{}]
}

takeScreenshot()

Returns a promise which is resolved with a dataUrl of the 3D screenshot.

setShowExpandButton(bool)

Show or hide the expand/contract button in the widget panel's header.

setExpanded(bool)

Set to TRUE to expand the widget into fullscreen mode or FALSE to contract the widget into side panel mode.

Errors

All API calls return promises which, if an error occurs, are rejected with an object which has a code and a detail field. Code is one of the following: invalid, notFound, unknown, unauthorized and notAllowed. Detail can contain anything and should only be used for debugging purposes.

Demo

Please take a look at the demo widget for a complete widget implementation example. To see an example of how to run StreamBIM in embedded mode, see the embedded demo. Notice the CSS rules to ensure that the content is scrollable on touch devices.

Dependencies

The library is using the excellent Penpal library for secure communication with iframes via postMessage

License

MIT