-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { noopLogger} = require('../utils'); | ||
const debug = require('debug')('jambonz:realtimedb-helpers'); | ||
|
||
const scan = async(client, logger, cursor, pattern) => { | ||
try { | ||
const res = await client.scan(cursor, 'MATCH', pattern); | ||
debug(`scanned pattern ${pattern} cursor ${cursor} result: ${JSON.stringify(res)}`); | ||
return {next: res[0], matches: res[1]}; // return updated cursor | ||
} catch (err) { | ||
logger.error(err, `Error scanning ${pattern}`); | ||
return {next: '0'}; | ||
} | ||
}; | ||
|
||
async function listHashes(client, logger, createPaternForScan, hashPrefix, accountSid, glob) { | ||
logger = logger || noopLogger; | ||
let cursor = '0'; | ||
const pattern = createPaternForScan(accountSid, glob); | ||
const hashes = []; | ||
try { | ||
debug(`listHashes: scanning with match ${pattern}`); | ||
do { | ||
const {next, matches} = await scan(client, logger, cursor, pattern); | ||
if (matches.length > 0) hashes.push.apply(hashes, matches); | ||
cursor = next; | ||
} while ('0' !== cursor); | ||
|
||
logger.debug(`listHashes retrieved ${hashes.length} ${hashPrefix}`); | ||
|
||
return hashes; | ||
} catch (err) { | ||
debug(err, `listHashes: Error retrieving ${hashPrefix} for account sid ${accountSid}`); | ||
logger.error(err, `listHashes: Error retrieving ${hashPrefix} for account sid ${accountSid}`); | ||
} | ||
} | ||
|
||
module.exports = listHashes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const test = require('tape').test ; | ||
const config = require('config'); | ||
const opts = config.get('redis'); | ||
|
||
|
||
process.on('unhandledRejection', (reason, p) => { | ||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); | ||
}); | ||
|
||
test('Conference tests', async(t) => { | ||
const fn = require('..'); | ||
const {listConferences, createHash, client} = fn(opts); | ||
|
||
//wait 1 sec for connection | ||
//await sleep(1); | ||
|
||
try { | ||
|
||
await createHash('conf:account-sid:conf1', 'url1'); | ||
await createHash('conf:account-sid:conf2', 'url2'); | ||
await createHash('conf:account-sid:conf3', 'url3'); | ||
await createHash('conf:account-sid:conf4', 'url4'); | ||
await createHash('conf:account-sid:ss-conf5', 'a value'); | ||
await createHash('conf:account-sid:ss-conf6', 'another value'); | ||
|
||
let confs = await listConferences('account-sid'); | ||
t.ok(confs.length === 6, 'retrieved 6 total queues'); | ||
|
||
confs = await listConferences('account-sid', 'ss-*'); | ||
t.ok(confs.length === 2, 'retrieved 2 total queues by pattern'); | ||
|
||
t.end(); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
t.end(err); | ||
} | ||
client.quit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters