| 71 | } |
| 72 | |
| 73 | function getWorkerType(code: string, match: RegExpExecArray): AlphaTabWorkerTypes { |
| 74 | if (match[1].includes('.addModule')) { |
| 75 | return AlphaTabWorkerTypes.AudioWorklet; |
| 76 | } |
| 77 | |
| 78 | const endOfMatch = match.indices![0]![1]; |
| 79 | |
| 80 | const startOfOptions = code.indexOf('{', endOfMatch); |
| 81 | if (startOfOptions === -1) { |
| 82 | return AlphaTabWorkerTypes.WorkerClassic; |
| 83 | } |
| 84 | |
| 85 | const endOfOptions = code.indexOf('}', endOfMatch); |
| 86 | if (endOfOptions === -1) { |
| 87 | return AlphaTabWorkerTypes.WorkerClassic; |
| 88 | } |
| 89 | |
| 90 | const endOfWorkerCreate = code.indexOf(')', endOfMatch); |
| 91 | if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) { |
| 92 | return AlphaTabWorkerTypes.WorkerClassic; |
| 93 | } |
| 94 | |
| 95 | let workerOptions: string | null | { type: string } = code.slice(startOfOptions, endOfOptions + 1); |
| 96 | try { |
| 97 | workerOptions = evalValue(workerOptions); |
| 98 | } catch { |
| 99 | return AlphaTabWorkerTypes.WorkerClassic; |
| 100 | } |
| 101 | |
| 102 | if (typeof workerOptions === 'object' && workerOptions?.type === 'module') { |
| 103 | return AlphaTabWorkerTypes.WorkerModule; |
| 104 | } |
| 105 | |
| 106 | return AlphaTabWorkerTypes.WorkerClassic; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @public |