Skip to main content

DeepLinkModule

Class

The DeepLinkModule brings the concept of deep linking, familiar from mobile platforms like Android and iOS, to Spectacles.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

The DeepLinkModule brings the concept of deep linking, familiar from mobile platforms like Android and iOS, to Spectacles. This module allows Lenses to send and receive deep link URIs between Spectacles and the Spectacles App.

Index

Example

const deepLink = require("LensStudio:DeepLinkModule");

// Configuration for Google OAuth2
const clientId = "YOUR_GOOGLE_CLIENT_ID";
const redirectUri = "YOUR_APP_REDIRECT_URI"; // Make sure this is registered in Google developer console
const scope = "https://www.googleapis.com/auth/userinfo.profile"; // Adjust scope as needed

// Register an event handler to handle when a deep link URI is received
deepLink.onUriReceived.add((event) => {
console.log(`Deep link received: ${event.uri}`);

// Extract the authorization code using string manipulation
const queryString = event.uri.split('?')[1];
const params = queryString.split('&');
let authorizationCode = null;

for (const param of params) {
const [key, value] = param.split('=');
if (key === 'code') {
authorizationCode = decodeURIComponent(value);
break;
}
}

if (authorizationCode) {
console.log(`Authorization code received: ${authorizationCode}`);

// Exchange authorization code for access token
exchangeAuthorizationCodeForAccessToken(authorizationCode);
} else {
console.error("Authorization code not found in URI");
}
});

// Function to start the OAuth2 flow by opening a deep link to Google's OAuth2 page
function authenticateWithGoogle() {
const oauthUri = `https://accounts.google.com/o/oauth2/v2/auth` +
`?response_type=code` +
`&client_id=${encodeURIComponent(clientId)}` +
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
`&scope=${encodeURIComponent(scope)}`;

deepLink.openUri(oauthUri)
.then(() => {
console.log('Deep link opened successfully');
})
.catch((error) => {
console.error('Failed to open deep link:', error);
});
}

// Placeholder function for exchanging authorization code for access token
function exchangeAuthorizationCodeForAccessToken(code: string) {
console.log(`Exchanging authorization code for access token: ${code}`);

// Implement server-side logic to exchange code for access token
// Send a POST request to Google's token endpoint with `code`, `clientId`, `redirectUri`, and `clientSecret`
}

// Call this function to begin OAuth2 authentication with Google
authenticateWithGoogle();

Extends

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


onUriReceived

readonly onUriReceived: event1<DeepLinkUriReceivedArgs, void>

SPECS

An event triggered when a deep link request is received by the Lens from SnapOS, enabling the lens to process and respond to the incoming action or content linked by the URI.


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getTypeName()

static getTypeName(): TypeName<DeepLinkModule>

SPECS

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<DeepLinkModule>

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame


openUri()

openUri(uri): Promise<void>

SPECS

Initiates a deep link request by sending a specified URI from the Lens to SnapOS, allowing dynamic interaction based on the URI’s target action or content.

Parameters

ParameterType
uristring

Returns

Promise<void>