| 1 | package SockJS::Transport; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use SockJS::Transport::EventSource; | ||
| 7 | use SockJS::Transport::HtmlFile; | ||
| 8 | use SockJS::Transport::WebSocket; | ||
| 9 | use SockJS::Transport::XHRPolling; | ||
| 10 | use SockJS::Transport::XHRSend; | ||
| 11 | use SockJS::Transport::XHRStreaming; | ||
| 12 | use SockJS::Transport::JSONPPolling; | ||
| 13 | use SockJS::Transport::JSONPSend; | ||
| 14 | |||
| 15 | sub build { | ||
| 16 | my $self = shift; | ||
| 17 | my $path = shift; | ||
| 18 | |||
| 19 | my $class; | ||
| 20 | |||
| 21 | if ($path eq 'xhr') { | ||
| 22 | $class = 'XHRPolling'; | ||
| 23 | } | ||
| 24 | elsif ($path eq 'xhr_send') { | ||
| 25 | $class = 'XHRSend'; | ||
| 26 | } | ||
| 27 | elsif ($path eq 'xhr_streaming') { | ||
| 28 | $class = 'XHRStreaming'; | ||
| 29 | } | ||
| 30 | if ($path eq 'jsonp') { | ||
| 31 | $class = 'JSONPPolling'; | ||
| 32 | } | ||
| 33 | elsif ($path eq 'jsonp_send') { | ||
| 34 | $class = 'JSONPSend'; | ||
| 35 | } | ||
| 36 | elsif ($path eq 'websocket' || $path eq 'raw_websocket') { | ||
| 37 | $class = 'WebSocket'; | ||
| 38 | } | ||
| 39 | elsif ($path eq 'eventsource') { | ||
| 40 | $class = 'EventSource'; | ||
| 41 | } | ||
| 42 | elsif ($path eq 'htmlfile') { | ||
| 43 | $class = 'HtmlFile'; | ||
| 44 | } | ||
| 45 | |||
| 46 | return unless $class; | ||
| 47 | |||
| 48 | $class = "SockJS::Transport::$class"; | ||
| 49 | |||
| 50 | return $class->new(name => $path, @_); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; |