1

I'm creating a web based chat app using react and decided to implement end to end encryption. So I'm using signal encryption protocol. Now the main library I need to import in order to do end to end encryption is in a file called libsignal-protocol.js (it is available in signals github repo). All functions and variables I need to use is inside a variable called libsignal (example - libsignal.KeyHelper.generateIdentityKeyPair().

Library libsignal-protocol.js doesn't provide javascript modules so I'm importing whole library with a global script declaration.

<!DOCTYPE html>
<html lang="en">
  <head>
   <script src="libsignal-protocol.js"></script>
    ...........
   </head>
<body>
......
</body>
</html>

Since my chat app is a react app, I tried to call libsignal's functions inside react components.

Webpack gives an error

Line 33:13: 'libsignal' is not defined no-undef

I googled and tried to solve this issue and found a very similar question but that question is related with typescript and I'm using javascript so this is not a duplicate.

Javascript doesn't have a declare keyword. How do I tell webpack that I have already imported libsignal using a global script tag?

2
  • 1
    is your bundle being loaded before or after the libsignal library? if libsignal is putting something on global variable and your webpack bundle is being loaded afterwards you should be able to access it via window.whateverLibSignalAddsToGlobal . alternatively you can load the script asynchronously, and render your react tree / component afterwards github.com/eldargab/load-script Commented Oct 9, 2020 at 19:26
  • Thankyou! it really helped. bundle is loaded after the libsignal library. Thanks a lot. @azium Commented Oct 9, 2020 at 19:34

1 Answer 1

1

Please try this

window.libsignal
Sign up to request clarification or add additional context in comments.

3 Comments

same as azium's answer in the comments.
sorry didn't notice
@IgorDoroshenko you da real mvp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.