Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Latest commit

 

History

History
94 lines (51 loc) · 5.54 KB

API.md

File metadata and controls

94 lines (51 loc) · 5.54 KB

Snack SDK API

SnackSession

Creates a snack session on the web. Multiple mobile devices can connect to the same session and each one will be updated when new code is pushed.

Parameters

  • options object
    • options.files ExpoSnackFiles The initial React Native code.
    • options.name string? Name shown if this Snack is saved.
    • options.description string? Descriptions shown if this Snack is saved.
    • options.sessionId string? Can be specified if you want a consistent url. This is a global namespace so make sure to use a UUID or scope it somehow if you use this.
    • options.sdkVersion string? Determines what version of React Native is used on the mobile client. Defaults to 15.0.0 which maps to React Native 0.42.0. If you specify a different version, make sure to save that version along with the code. Code from one SDK version is not guaranteed to work on others.
    • options.verbose boolean? Enable verbose logging mode.

startAsync

Starts the session.

Returns Promise<void> A promise that resolves when the session is started.

stopAsync

Stops the session.

Returns Promise<void> A promise that resolves when the session is stopped.

getUrlAsync

Returns a url that will open the current Snack session in the Expo client when opened on a phone. You can create a QR code from this link or send it to the phone in another way. See https://github.com/expo/snack-sdk/tree/master/example for how to turn this into a QR code.

Returns Promise<void> A promise that contains the url when fulfilled.

uploadAssetAsync

Upload an asset file that will be available in each connected mobile client

Returns Promise<string> A promise that contains the url when fulfilled

sendCodeAsync

Push new code to each connected mobile client. Any clients that connect in the future will also get the new code.

Parameters

  • files ExpoSnackFiles The new React Native code.

Returns Promise<void> A promise that resolves when the code has been sent. Does not wait for the mobile clients to update before resolving.

addErrorListener

Add a listener to get notified of error events.

Parameters

  • callback function (array) The callback that handles new error events. If there are no errors this will be called with an empty array. Otherwise will be called with an array of objects that each contain a message field.

Returns object A subscription object. Call .remove() on this object so stop getting new events.

addLogListener

Add a listener to get notified of log events.

Parameters

  • callback function (object) The callback that handles new log events. Will be called with an object containing a message field.

Returns object A subscription object. Call .remove() on this object so stop getting new events.

addPresenceListener

Add a listener to get notified of presence events.

Parameters

  • callback function (object) The callback that handles new presence events. Will be called with an object containing a status field.

Returns object A subscription object. Call .remove() on this object so stop getting new events.

saveAsync

Uploads the current code to Expo's servers and return a url that points to that version of the code.

Returns Promise<object> A promise that contains an object with a url field when fulfilled.

addModuleAsync

Adds a given module, along with any required peer dependencies, to the current project Reports errors to any registered DependendencyErrorListeners

Returns Promise<any>