5 examples of 'how to create session in javascript' in JavaScript

Every line of 'how to create session in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
102function generateSession(): string {
103 return Array(3).fill(0).map(generateRandomHexString).join('');
104}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1export default function createSession({
2 apiKey, sessionId, token, onStreamsUpdated
3}) {
4 let streams = [];
5
6 let onStreamCreated = event => {
7 let index = streams.findIndex(stream => stream.id === event.stream.id);
8 if (index < 0) {
9 streams.push(event.stream);
10 onStreamsUpdated(streams);
11 }
12 };
13
14 let onStreamDestroyed = event => {
15 let index = streams.findIndex(stream => stream.id === event.stream.id);
16 if (index >= 0) {
17 streams.splice(index, 1);
18 onStreamsUpdated(streams);
19 }
20 };
21
22 let eventHandlers = {
23 streamCreated: onStreamCreated,
24 streamDestroyed: onStreamDestroyed
25 };
26
27 let session = OT.initSession(apiKey, sessionId);
28 session.on(eventHandlers);
29 session.connect(token);
30
31 return {
32 session,
33 streams,
34 disconnect() {
35 if (session) {
36 session.off(eventHandlers);
37 session.disconnect();
38 }
39
40 streams = null;
41 onStreamCreated = null;
42 onStreamDestroyed = null;
43 eventHandlers = null;
44 session = null;
45
46 this.session = null;
47 this.streams = null;
48 }
49 };
50}
30function createSession(app, bsid){
31 try {
32 return sessionStore[app][bsid] = new Session();
33 } catch (e) {
34 sessionStore[app] = {};
35 return sessionStore[app][bsid] = new Session();
36 }
37}
396public async executeScript<T>(script: string, args: any[] = []): Promise<T> {
397 return POST<T>(`${this.host}/session/${this.sessionId}/execute/sync`, {
398 script,
399 args
400 });
401}
16createSession(sessionId, object) {
17 this.sessions[sessionId] = object;
18}

Related snippets