This file contains hidden or 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
| public abstract class AbstractModelAndViewBuilder<B extends AbstractModelAndViewBuilder<B>> { | |
| private static final String REDIRECT = "redirect:"; | |
| private B thisObj; | |
| protected abstract B self(); | |
| protected ModelAndView mav; | |
| protected AbstractModelAndViewBuilder() { | |
| thisObj = self(); | |
| } | |
| protected B setPage(Page page) { | |
| mav = new ModelAndView(page.getTemplateName()); |
This file contains hidden or 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
| def callDone = Action { | |
| implicit request => Logger.info(s"A call from a browser has ended, storing details") | |
| Logger.debug(s"Request: ${request.queryString.toList}") | |
| val status = request.queryString.get("DialCallStatus").getOrElse(mutable.Buffer()).mkString | |
| val sid = request.queryString.get("DialCallSid").getOrElse(mutable.Buffer()).mkString | |
| val duration = request.queryString.get("DialCallDuration").getOrElse(mutable.Buffer()).mkString | |
| val recording = request.queryString.get("RecordingUrl").getOrElse(mutable.Buffer()).mkString | |
| Logger.info(s"Call $sid terminated with status $status after $duration. Recording available at $recording") | |
| callsReceived = recording :: callsReceived Ok | |
| } |
This file contains hidden or 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
| def serveCallConfig = Action { | |
| implicit request => Logger.info(s"Establishing a call form a browser") | |
| Logger.debug(s"Request: ${request.queryString.toList}") | |
| val to = request.queryString.get("To").getOrElse(mutable.Buffer()).mkString | |
| Logger.info(s"Found target number $to") val action = routes.Application.callDone.absoluteURL() | |
| Logger.info(s"Action for recording is $action") | |
| val xml = s"<Response><Dial callerId='+441473379566' method='GET' action='$action' record='true'><Number>$to</Number></Dial></Response>" | |
| Ok(xml).as("text/xml") | |
| } |
This file contains hidden or 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
| object Application extends Controller with TwilioAccess { | |
| def index = Action { | |
| implicit request => Ok(views.html.index(credentialsForm)).withNewSession | |
| } | |
| def getCredentials = Action { | |
| implicit request => credentialsForm.bindFromRequest.fold( | |
| errors => BadRequest(views.html.index(errors) | |
| ), | |
| credentials => Redirect(routes.Application.testTwilio) .withSession(setSessionCredentials(credentials.sid, credentials.token, credentials.appSID)) ) | |
| } |
This file contains hidden or 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
| def sendSMS = hasCredentials { | |
| (sid, token, appSID) => implicit request => smsForm.bindFromRequest.fold( | |
| errors => BadRequest(views.html.twilio(sid, errors, "", callsReceived)), | |
| details => { val msg = TwilioAPI .sendSMS(sid, token, details.phone, details.msg) match { case Failure(ex) => Flash(Map("danger" -> s"Couldn't send sms, error: ${ex.getMessage}")) case Success(id) => Flash(Map("success" -> s"SMS sent with id $id")) } | |
| Redirect(routes.Application.testTwilio).flashing(msg) } | |
| ) | |
| } |
This file contains hidden or 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
| function splitLoop(items, process, context) { | |
| var todo = items.concat(); | |
| setTimeout(function () { | |
| do { | |
| process.call(context, todo.shift()); | |
| } while (todo.length > 0); | |
| setTimeout(arguments.callee, 25); | |
| }, 25); | |
| } |
This file contains hidden or 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
| var items = []; | |
| for (var i = 0; i < 1000; i++) | |
| items[i] = i; | |
| splitLoop(items, function (item) { | |
| console.log(item) | |
| }, this); |
This file contains hidden or 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
| function splitLoop(items, process, context, callback) { | |
| var todo = items.concat(); | |
| setTimeout(function () { | |
| var start = +new Date(); | |
| do { | |
| process.call(context, todo.shift()); | |
| } while (todo.length > 0 && (+new Date() - start < 50)); | |
This file contains hidden or 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
| function todo(item) { | |
| console.log(item); | |
| }; | |
| function done() { | |
| console.log('done'); | |
| } | |
| var items = []; | |
| for (var i = 0; i < 1000; i++) |
This file contains hidden or 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
| function splitLoop(items, process, context, callback) { | |
| var todo = items.concat(); | |
| setTimeout(function () { | |
| var start = +new Date(); | |
| do { | |
| process.call(context, todo.shift()); | |
| } while (todo.length > 0); | |
| if (todo.length > 0) { |